Repository navigation
IBX-11939: Added Doctrine Migrations for the user-invitation schema - #128
Conversation
…0.0 rename) Adds InstallSchemaMigration (4.6.0 baseline) and, on 5.0+, RenameSchemaTo5_0Migration renaming ibexa_user_invitations(_assignments) to singular. ibexa/installer's shipped upgrade SQL was missing the rename of the assignment table's Doctrine-hashed FK-backing index (its hash changes with the table name: IDX_DA5A7872A35D7AF0 -> IDX_9E1E6F70A35D7AF0) - added that. SQLite equivalent derived and verified end-to-end - resulting schema matches a fresh dump-sql of the current schema.yaml exactly. Existing schema.yaml + BuildSchemaSubscriber left untouched.
…lines composer.json was missing ibexa/doctrine-migrations (require + matching VCS repository entry for its unreleased dev branch), causing "Class Doctrine\Migrations\AbstractMigration not found" across static analysis, unit tests, and browser tests - mirrors ibexa/core's own composer.json pattern exactly (same dev-branch constraint per major version). Also removes extra blank lines the generator scripts introduced (before each } elseif and the up() method's closing brace) that php-cs-fixer's no_extra_blank_lines rule flagged.
InstallSchemaMigration was generated with the same template used for all three branches, hardcoding DBAL 3.x class names (AbstractMySQLPlatform/ PostgreSQLPlatform). This branch pins doctrine/dbal 2.13.9, where the correct names are MySqlPlatform/PostgreSqlPlatform (matching ibexa/core's own 4.6 baseline) - the 3.x names don't exist in that version, causing "Class ... not found" in static analysis and tests. Verified against a real DBAL 2.x connection.
Extends AbstractSqlMigration (added in ibexa/doctrine-migrations) instead of the plain Doctrine AbstractMigration, replacing `$this->platform instanceof ...` checks with isMySQL()/isPostgreSQL()/isSqlite(), and moving each platform Statement block out of the PHP file into its own sql/*.sql file loaded via addSqlFile(). Mechanical, content-preserving change: every migration was run before and after against all three platforms and the resulting SQL statement lists are byte-for-byte identical.
Call abortIfUnsupportedPlatform() as the first statement of up(), so installs on a database this migration doesn't build SQL for fail loudly instead of silently queuing zero statements.
Each statement now ends with `;`, matching ibexa:doctrine:schema:dump-sql's own convention, so the files are directly executable via mysql/psql/sqlite3 CLI clients. addSqlFile() still splits on the delimiter and passes one statement per addSql() call, unaffected by the trailing terminator.
…tions Checks $schema (already the live, introspected database) before running, and skipIf()s when the tables/columns/FK targets this migration would create already exist -- so installs that built their schema the old way (SchemaBuilderEvent) can adopt Doctrine Migrations without every migration aborting or duplicating existing schema objects.
Doctrine Migrations only calls MetadataStorage::complete() (the write to
doctrine_migration_versions) when a migration's up() returns normally --
never when it throws SkipMigration. So every migration using skipIf() was
being silently re-evaluated on every future doctrine:migrations:migrate
run instead of being permanently recorded as applied, even though its
guard condition (the schema already being in place) never changes back.
Replaces every `$this->skipIf($condition, $message);` with
`if ($condition) { return; }`: up() now returns normally with zero queued
SQL when the guard fires, so the migration is correctly recorded as
executed (with a "did not result in any SQL statements" warning logged,
which is expected and harmless) and never re-evaluated again.
Verified end-to-end: fresh ibexa:install (schema_builder_event enabled)
followed by doctrine:migrations:migrate now records all 44 tagged
migrations in doctrine_migration_versions in one pass, and a second
migrate run does zero work at all ("Already at the latest version").
…name Live end-to-end testing (fresh legacy install -> doctrine:migrations:migrate on 4.6) surfaced that these baseline guards checked the FINAL, post-5.0- rename table name (e.g. "ibexa_content") -- correct on 5.0/6.0, but wrong on 4.6, which has no rename at all: there, the table this migration creates already IS the branch's permanent, current name (e.g. "ezcontentobject"), so the guard never fired and the baseline collided with an already-installed legacy 4.6 schema. Checks the branch's own table name instead, exactly like every other baseline guard that has no later rename to worry about. For core's ImportDataMigration specifically, this required a proper data check rather than a schema-shape check: "ezcontentobject" is 4.6's real, permanent name, so it always exists once the baseline has run there, regardless of whether this migration's own bootstrap INSERTs ran yet. Checks for the actual seed row (root content, id = 1) instead, combined with the table's outright absence (the 5.0/6.0 legacy signal) via OR.
ibexa/doctrine-migrations is now published on Packagist (which mirrors all of its branches, not just tags), so the explicit VCS repository pointing composer directly at GitHub is no longer needed to resolve the dev-branch require constraint.
33f698e to
0a641b0
Compare
The MySQL install SQL hardcoded "DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci". On MySQL 8 "utf8" is an alias for utf8mb3, so a Doctrine Migrations install produced 3-byte columns while a SchemaBuilderEvent install produced utf8mb4 - the latter reads the configured database_charset/database_collation, which default to utf8mb4 and utf8mb4_unicode_520_ci. The practical effect was that a migrations-based install could not store 4-byte characters (emoji, CJK extensions) at all, and sorted/compared text differently. Verified against a real MySQL 8.0 server: the schema a migrations install produces now matches a SchemaBuilderEvent one.
The requirement pinned dev-feat/doctrine-migrations, a branch that does not exist on the remote - only feat/doctrine-migrations-5.0 does. Composer could not resolve it, so every CI job that installs dependencies failed, including all three SQLite integration test runs and the code style check. Uses the tier constraint the other 4.6 packages use.
| @@ -0,0 +1,5 @@ | |||
| CREATE TABLE ibexa_user_invitations (id INT AUTO_INCREMENT NOT NULL, email VARCHAR(255) NOT NULL, site_access_name VARCHAR(255) NOT NULL, hash VARCHAR(255) NOT NULL, creation_date INT NOT NULL, used TINYINT(1) DEFAULT '0' NOT NULL, INDEX ibexa_user_invitations_email_idx (email), INDEX ibexa_user_invitations_hash_idx (hash), UNIQUE INDEX ibexa_user_invitations_email_uindex (email(191)), UNIQUE INDEX ibexa_user_invitations_hash_uindex (hash(191)), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_520_ci` ENGINE = InnoDB; | |||
There was a problem hiding this comment.
noticing it now, but is there a way we make that coding utf8mb4_unicode_520_ci configurable / leave it to doctrine/dbal? we had different codings in the past accross tables and I wonder if forcing it like that here is not gonna mess anything (like foreign keys) for someone who is on different one
There was a problem hiding this comment.
Technically, we can read it from the DBAL configuration - or at least try to.
The issue with this is that configuration can change over time (in one's project), so while it is possible, we should be very careful about documenting it properly, at least.
I would assume that the developer wants the same collation across all tables.
As for the potential migration of collation, it's doable - at least according to Claude. The potential snag is that there is a chance of uniqueness collision.
@konradoboza @alongosz thoughts?
There was a problem hiding this comment.
I would personally make that configurable to avoid any assumptions. Would the migration be done via some SQL script changing the collation in batch or how do you see it?
There was a problem hiding this comment.
Couple options.
- Provide a specialized key/literal string that we would react to, and replace it before the migrations executes the SQL - downside = SQL no longer is simply executable.
- Detect that we are dealing with a collation string, and replace it when detected. Downside is that we are not able to use that collation literal anywhere else in the SQL, or it will break.
- ☝️ do as above, but instead of literal targeting just collation, let's look for a pattern - dependent on database - that we would usually use collation with. If detected, we would replace that.
I'd go with option 3, and additionally we could make it so this is done using a trait, so we don't duplicate the code across the all packages or put it into the AbstractSqlMigration class.
I think this is one of the cases where we are "attaching a behavior to a class" that constitutes valid use for trait. @alongosz ?
konradoboza
left a comment
There was a problem hiding this comment.
Apart from remark from Dawid.
Each CREATE TABLE now lists one column, index or constraint per line, and ALTER TABLE and CREATE INDEX statements longer than 120 characters are wrapped. Only whitespace changes, apart from the comma moving in front of SQLite's --(DC2Type:...) comments, which keeps each comment with its column.
ibexa/doctrine-migrations#19 makes MariaDB a platform of its own, so each migration now lists SqlPlatform::MARIADB and runs its MySQL SQL there too.
bee5087 to
4123879
Compare
|



Note
Test-side companion —
ibexa/test-core#57.Moves the baseline fixture import into its own
BaseFixtureHook(priority 950, between theschema hooks and
FixtureHook), switchable with aload_base_fixtureoption.It matters here because under the Doctrine Migrations path the baseline repository content
arrives as core's
ImportDataMigrationrather than as a loaded fixture, andFixtureImportertruncates every table a fixture touches before inserting — so a package's own fixture writing
into those tables would take the baseline's rows with it unless it implements
AppendOnlyFixture.Packages whose integration tests load their own fixtures depend on it; the rest are unaffected.
Note
Shared library —
ibexa/doctrine-migrations.Every migration in the table below extends the
AbstractSqlMigration/SqlPlatformbase it provides.It is already merged on all three branches, so nothing in this effort is blocked on it:
#1 (4.6 baseline) · #3 (6.0 baseline) · #4 (
enable_service_migrationsfix) · #6 (DBAL 4).The fix reached 5.0 and 6.0 via merge-ups #9 and #10 — which is why
#5was closed rather than merged.Related PRs:
#168⏭️#174⏭️#116⏭️#199⏭️#371⏭️#342🩹 ⏭️#51⏭️#210🩹 ⏭️#242🩹 ⏭️#135⏭️#440⏭️#50⏭️#206⏭️#1545⏭️#54⏭️#18⏭️#170⏭️#191⏭️#156⏭️#67⏭️#174🩹 ⏭️#175⏭️#130⏭️#193🩹 ⏭️🔄 = this branch adds an upgrade migration (renames/FK-retargets existing schema), not just a fresh baseline.
⚠️ = fixes a different, related problem (missing
🩹 = this branch also received a backported delta migration, converted from a legacy
ibexa/installerupgrade/db/*.sqlscript (4.6.0 or later) that the original baseline-only migration didn't cover. See IBX-11939 upgrade-scripts backport report or that package's own PR description for details.SchemaBuilderEventsupport for a plain Doctrine ORM entity/table) — not a Doctrine Migrations baseline/upgrade migration like the rest of this table. See that package's own PR description for details.⏭️ =
struck throughand closed as unnecessary — that tier needs no changes of its own. Everything it requires arrives through the normal merge-up from the tier below; the branch is kept, so the PR can be reopened if genuinely tier-specific work turns up.Description:
Adds
InstallSchemaMigration(tagged4.6.0), mirroring ibexa/core's Doctrine Migrations installer path (#785): a plainDoctrine\Migrations\AbstractMigrationimplementingIbexaMigrationInterface, taggedIbexaMigrationTag::TAG, with SQL for MySQL/PostgreSQL/SQLite generated viaibexa:doctrine:schema:dump-sqlfrom this package's ownschema.yaml(byte-identical to whatSchemaBuilderEvent's existing install path produces).The existing
schema.yaml+BuildSchema(Event)Subscriberare untouched — both mechanisms coexist whileibexa.installer.schema_builder_event.enabledstill defaults totrue.For QA:
Ran the migration end-to-end against a real SQLite connection; the resulting tables/indexes match a fresh
ibexa:doctrine:schema:dump-sql --force-platform=sqliteof this package'sschema.yamlexactly.Documentation:
N/A — internal installer implementation detail.