Repository navigation
IBX-11939: Added a test case checking that both schema install paths align - #68
Conversation
b59d15d to
674dedd
Compare
…ches Points CI at ibexa/test-core#68, which has the test case. Must be removed before merging.
…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.
Points CI at ibexa/test-core#68, which has the test case. Must be removed before merging.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
any way to narrow this down to composite PRs only?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Done - SchemaAlignmentTestCaseStub, plus an integration suite running on all four databases.
|
|
||
| public function testComparesPrefixLengthsWhereTheDatabaseStoresThem(): void | ||
| { | ||
| self::assertNotSame( |
There was a problem hiding this comment.
is there a way to compare actuall diff and not if just they are different?
| * 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 |
There was a problem hiding this comment.
will this be moved to internal-contracts at 6.0?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
this seems to drop every sequence, not only serial as the name and the doc says.
There was a problem hiding this comment.
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.
077ee29 to
fae3632
Compare
Related PRs:
SchemaInstallPath), stacked on thisdependencies.json: ibexa/activity-log#190, ibexa/cart#200, ibexa/connector-payum#53, IBX-11939: Added the schema alignment test core#861, ibexa/corporate-account#404, ibexa/fieldtype-page#248, ibexa/form-builder#271, ibexa/measurement#165, ibexa/migrations#477, ibexa/oauth2-server#67, ibexa/order-management#218, ibexa/payment#230, ibexa/product-catalog#1627, ibexa/scheduler#199, ibexa/segmentation#262, ibexa/shipping#182, ibexa/site-factory#213, ibexa/taxonomy#465, IBX-11939: Added the schema alignment test user#158, ibexa/workflow#218Description:
Integration suites that run on both install paths (the
schema_builder_eventCI matrix, e.g. ibexa/taxonomy#431 or ibexa/core-persistence#52) each build their database one way:DatabaseSchemaHookexecutes the schemaSchemaBuilderEventdeclares, core'sDoctrineMigrationsSchemaHookruns the Doctrine migrations instead. Nothing compared the two so far.AbstractSchemaAlignmentTestCasecompares the database the suite runs on with whatSchemaBuilderInterface::buildSchema()returns, through DBAL'sComparator. On the migrations run, a failure means a migration is missing or incomplete, and the message says what it should do:On the
SchemaBuilderEventrun 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:
It has two override points, both
protected:getDatabaseConnection(), for a suite that reaches its database through another connection. It defaults toIbexaTestCore::getDoctrineConnection().getSchemaBuilder(), for a suite that builds the schema it declares another way. It defaults toIbexaTestCore::getServiceByClassName(SchemaBuilderInterface::class), which is whyIbexaTestKernelnow exposesSchemaBuilderInterface.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.yamldeclares it, so both sides leave out a few things before comparing:schema.yamlgives them as strings,INTEGER PRIMARY KEYas autoincrement,With that, the
SchemaBuilderEventrun 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 addstests/integration/Schema/_fixtures/schema.yaml- one table per case above, declared the way a package'sschema.yamlis - through core'sBuildSchemaSubscriber.SchemaAlignmentTestcovers those tables end to end, andSchemaAlignmentNormalizationTestshows 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'sSchemaImporter.