Skip to content

IBX-11939: Added a test case checking that both schema install paths align - #68

Merged
Steveb-p merged 15 commits into
4.6from
feature/schema-parity-4.6
Oct 19, 2026
Merged

Steveb-p merged 15 commits into
4.6from
feature/schema-parity-4.6

Conversation

@Steveb-p

@Steveb-p Steveb-p commented Oct 3, 2026 •

Copy link
Copy Markdown
Collaborator
🎫 Issue IBX-11939

Related PRs:

Description:

Integration suites that run on both install paths (the schema_builder_event CI matrix, e.g. ibexa/taxonomy#431 or ibexa/core-persistence#52) each build their database one way: DatabaseSchemaHook executes the schema SchemaBuilderEvent declares, core's DoctrineMigrationsSchemaHook runs the Doctrine migrations instead. Nothing compared the two so far.

AbstractSchemaAlignmentTestCase compares the database the suite runs on with what SchemaBuilderInterface::buildSchema() returns, through DBAL's Comparator. On the migrations run, a failure means a migration is missing or incomplete, and the message says what it should do:

The database doesn't match the schema SchemaBuilderEvent declares. If Doctrine Migrations installed it, a migration is missing or incomplete. These statements would make it match:
CREATE INDEX ibexa_taxonomy_entries_scratch_name_idx ON ibexa_taxonomy_entries (name)

On the SchemaBuilderEvent run it passes by construction. Established migrations never change and every schema change comes with a new one, so a fresh install runs all of them, which is also what a site upgrading through migrations ends up running.

A package only needs an empty subclass in its integration suite:

final class SchemaAlignmentTest extends AbstractSchemaAlignmentTestCase
{
}

It has two override points, both protected:

  • getDatabaseConnection(), for a suite that reaches its database through another connection. It defaults to IbexaTestCore::getDoctrineConnection().
  • getSchemaBuilder(), for a suite that builds the schema it declares another way. It defaults to IbexaTestCore::getServiceByClassName(SchemaBuilderInterface::class), which is why IbexaTestKernel now exposes SchemaBuilderInterface.

It compares everything in the test kernel, not just the package's own tables, so until the IBX-11939 PRs land, the packages in the kernel that own tables need their branches pinned.

DBAL can't read everything back the way schema.yaml declares it, so both sides leave out a few things before comparing:

  • index prefix lengths outside MySQL/MariaDB; there they're compared as integers, as schema.yaml gives them as strings,
  • sequences: no schema declares any, so the only ones are PostgreSQL's SERIAL ones, which DBAL ties to their column only on a single-column primary key,
  • autoincrement on SQLite, which can't express it on a composite key and reports every single-column INTEGER PRIMARY KEY as autoincrement,
  • strings longer than the platform's VARCHAR limit (4000 on SQLite), which are created and read back as text.

With that, the SchemaBuilderEvent run comes out clean on SQLite, MySQL 8.0, MariaDB 10.11 and PostgreSQL 14.

test-core now has an integration suite of its own (phpunit.integration.xml, composer test-integration), run in CI on all four. Its kernel adds tests/integration/Schema/_fixtures/schema.yaml - one table per case above, declared the way a package's schema.yaml is - through core's BuildSchemaSubscriber. SchemaAlignmentTest covers those tables end to end, and SchemaAlignmentNormalizationTest shows on which engines each one reads back differently without the normalization. The unit test runs the test case through its override points, with the same declarations imported by doctrine-schema's SchemaImporter.

Steveb-p added a commit to ibexa/core that referenced this pull request Oct 5, 2026
…ches

Points CI at ibexa/test-core#68, which has the test case. Must be removed before merging.
Steveb-p added a commit to ibexa/user that referenced this pull request Oct 5, 2026
…ches

Points CI at ibexa/test-core#68 (the test case), ibexa/core#785 with ibexa/installer#213 (the
Doctrine Migrations path). Must be removed before merging.
Steveb-p added a commit to ibexa/core that referenced this pull request Oct 5, 2026
Points CI at ibexa/test-core#68, which has the test case. Must be removed before merging.
Steveb-p added a commit to ibexa/user that referenced this pull request Oct 5, 2026
Points CI at ibexa/test-core#68, which has the test case. Must be removed before merging.
private static function normalize(Schema $schema, AbstractPlatform $platform): void
{
foreach ($schema->getSequences() as $sequence) {
self::ignoreSerialColumnSequence($schema, $sequence);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just dropping given sequence (not only those for serial columns), and if we're iterating over all sequences - we drop of them in fact.

Is there a way to narrow this down into serial columns only? If not, can we simply rename this method to reflect it's just dropping given sequence?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't declare sequences, so only SERIAL ones exist - and matching by name breaks on PostgreSQL's 63-char truncation. Renamed to ignoreSequences().

}

/**
* SQLite can't express autoincrement on a composite primary key, and reports every INTEGER

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any way to narrow this down to composite PRs only?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No - DBAL also flags every single-column INTEGER PRIMARY KEY as autoincrement (e.g. ezuser.contentobject_id). Added to the docblock.

/**
* @covers \Ibexa\Contracts\Test\Core\Schema\AbstractSchemaAlignmentTestCase
*/
final class AbstractSchemaAlignmentTestCaseTest extends TestCase

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All tests here are calling AbstractSchemaAlignmentTestCase::compareSchemas as entrypoint. Can we prepare some test stub implementation of AbstractSchemaAlignmentTestCase to run testDatabaseMatchesTheSchemaBuilderEventSchema on it as well? Only happy-path would be enough IMO.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done - SchemaAlignmentTestCaseStub, plus an integration suite running on all four databases.


public function testComparesPrefixLengthsWhereTheDatabaseStoresThem(): void
{
self::assertNotSame(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a way to compare actuall diff and not if just they are different?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

* Returns the statements that would turn the database schema into the declared one, leaving out
* what DBAL can't read back from a database the way it was declared.
*
* @internal public for this package's own tests

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will this be moved to internal-contracts at 6.0?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made it private instead, tests go through the override points.

* PostgreSQL creates a sequence for each SERIAL column, and DBAL doesn't recognize it as implicit
* on a table with a composite primary key. The column's autoincrement flag still says the same.
*/
private static function ignoreSerialColumnSequence(Schema $schema, Sequence $sequence): void

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems to drop every sequence, not only serial as the name and the doc says.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to ignoreSequences().

…align

Integration suites already run once on each install path: DatabaseSchemaHook executes the
SchemaBuilderEvent schema, ibexa/core's DoctrineMigrationsSchemaHook runs the Doctrine
migrations. AbstractSchemaAlignmentTestCase compares the database the suite runs on with the
schema SchemaBuilderEvent declares, so on the migrations run it fails when a migration is
missing or incomplete, listing the SQL that would make the database match.

DBAL can't read everything back the way schema.yaml declares it, so both sides leave out index
prefix lengths outside MySQL/MariaDB (and compare them as integers there), sequences, and
autoincrement on SQLite.
A suite may reach its database through another connection than the kernel's default one, so the
test case gets it from an overridable method, which defaults to
IbexaTestCore::getDoctrineConnection().
Each thing DBAL can't read back the way schema.yaml declares it now has a private method whose
name and docblock say why it's left out of the comparison: ignoreSerialColumnSequence(),
normalizeIndexPrefixLengths() and ignoreAutoincrementOnSqlite(). replaceIndexOptions() re-adds
an index with other options, since an index's options can't be changed.
…as text

DBAL creates a string column longer than the platform allows as a text one (a CLOB on SQLite,
where the limit is 4000), so it reads back as text. product-catalog's description columns
(string, length 10000) showed up as different on SQLite because of that.
IbexaTestKernel always registers DoctrineSchemaBundle, so the schema builder is always there.
Exposing it lets AbstractSchemaAlignmentTestCase get it through
IbexaTestCore::getServiceByClassName(), like every other service a test needs, instead of
reaching into the container itself.
Like getDatabaseConnection(), it's protected so a suite can override where the schema it compares
with comes from. It defaults to the SchemaBuilderInterface the kernel exposes.
ignoreAutoincrementOnSqlite() and treatOverlongStringAsText() now return as soon as the column or
platform isn't one they handle, instead of wrapping their whole body in a condition.
… casting them

By the time they're read, hasOption() has ruled out null, and wherever they come from - DBAL's
schema managers or doctrine-schema's importer - they're a list with one entry per column.
- Renamed ignoreSerialColumnSequence() to ignoreSequences(): it drops every sequence, and its
  docblock now says why they aren't matched to their SERIAL columns.
- Explained on ignoreAutoincrementOnSqlite() why leaving out composite keys alone isn't enough.
- Added an integration suite (phpunit.integration.xml, composer test-integration) whose bootstrap
  installs the kernel's SchemaBuilderEvent schema:
  - SchemaAlignmentTest, an empty subclass, runs the test case itself; it passes by construction.
  - SchemaAlignmentNormalizationTest creates each case the comparison normalizes, and checks that
    it compares as declared, and on which platforms the plain comparison differs.
- CI runs it on SQLite, PostgreSQL 14, MySQL 8.0 and MariaDB 10.11.
The prefix length and VARCHAR limit cases only checked that something was reported; they now
check that it's the index or column change.
… points

compareSchemas() was public only for this package's own tests. They now run
testDatabaseMatchesTheSchemaBuilderEventSchema() on a stub subclass that overrides
getDatabaseConnection() and getSchemaBuilder(), so it's private again.
Each case the comparison normalizes is now declared in tests/integration/Schema/_fixtures/schema.yaml,
the way packages declare their schema:
- The integration kernel adds it with core's BuildSchemaSubscriber, so the bootstrap installs it
  through SchemaBuilderEvent, and SchemaAlignmentTest compares it on every database.
- SchemaAlignmentNormalizationTest reads those tables back, instead of creating its own, and only
  checks where the plain comparison differs.
- The unit test imports the same file with doctrine-schema's SchemaImporter, instead of building
  the declared schema by hand.
…t case

4.6 now requires ibexa/code-style ~2.3.1 (#70), whose PHP CS Fixer wraps signatures with several
parameters, calls createStub() statically, writes empty class bodies on one line and imports the
classes docblocks refer to.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants