Repository navigation
Conversation
Signed-off-by: Shubham Bansal <[email protected]>
Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
Adds MySQL 8.4 to the test database harness (testMySQL8) and a CI job. Test databases use the case-sensitive utf8mb4_0900_bin collation. The isolation test now reads the database's default level instead of assuming READ_COMMITTED. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
Without an ORDER BY, MySQL returned columns (and function parameters) in its own order. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
Storage paths and names are case-sensitive, but MySQL's default collation is not. Log a warning at startup and document the utf8mb4_0900_bin collation. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
MySQL and PostgreSQL now share one harness: Hibernate builds the schema once per JVM into a template and each test clones it. Both containers keep their data in memory with durability off. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
Fix harness comments and docs, assign the cached database only after it started, drop duplicate test dependencies, request a different isolation level in the restore test, check the MySQL template has every mapped table, and cover parameter order in the function CRUD test. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
The MYSQL_8 CI row runs SdkDeltaCommitsCRUDTest on MySQL, so the class that started its own MySQL container is no longer needed. Its lock-reading test moves into SdkDeltaCommitsCRUDTest and runs on every database. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
A @TempDatabase field gets a fresh TestDatabase, per test for an instance field and per class for a static one. The extension stores it in the JUnit store, which closes it after every @AfterEach, so a test's server always closes before its database is dropped, and a failing setUp still drops it. TestDatabase no longer takes a ServerProperties (it overwrote everything the properties set) and offers hibernateProperties(), hibernateConfigurator() and sessionFactory(). All tests that made their own database now use the annotation. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
…eSQL containers Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
…lt_on_error The isolation test asks for a level other than the default, because asking for the default would pass even if nothing were restored. The MySQL template keeps halt_on_error off only for the one index InnoDB rejects; a TODO removes it once the schema migration steps build the template. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
Adds Flyway 13.10.3, the V1 baseline of the 0.7 schema and V2 (type_json widening) for H2, PostgreSQL and MySQL; empty test databases, @TempDatabase and TestDatabase.dataSource()/kind() in the harness; and a schema snapshot check that the steps build the schema the entities expect. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
Adds Migrator, which classifies a database (empty, current, pending, newer than this release, an unversioned 0.7 database, not a Unity Catalog database, failed step) and, under a run lock, sets up an empty database, adopts a 0.7 one (version 1 recorded as the baseline) and applies the pending steps. The run lock is pg_advisory_lock on PostgreSQL, GET_LOCK on MySQL and an in-process lock per database file on H2. bin/uc-migrate runs `migrate` and `info` against the database in etc/conf/hibernate.properties. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
…ases with Flyway The server sets up an empty database itself (a second server starting at the same time waits on the run lock) and refuses any other schema version with a message that names the fix. Hibernate never alters the schema: hbm2ddl.auto is forced to none, even if an old hibernate.properties says update. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
…ases Adds V3. On MySQL it converts the database and every Unity Catalog table (and casbin_rule, when it exists) to utf8mb4_0900_bin, so a database created with MySQL's case-insensitive default compares names and storage paths like PostgreSQL and H2. Converting is safe to repeat, so the step holds several statements. On PostgreSQL and H2, V3 does nothing. The startup collation warning skips Flyway's history table, which keeps the database's original collation. Test-only steps move to version 1000 and tests read the latest version instead of hard-coding it. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
Every test database now gets its schema from Migrator, never from Hibernate DDL: the PostgreSQL and MySQL templates are migrated once, and each H2 test database is migrated when it is created. Hibernate runs with hbm2ddl.auto=none in every test. MySQL clones now also copy the template's rows (Flyway's history), as PostgreSQL's TEMPLATE does, so a clone is at the current version. The MySQL template no longer needs halt_on_error=false or the check that every mapped table exists: Flyway stops on any failed statement. PopulateTestDatabase migrates its database before opening it. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
Describe how Flyway manages the schema, how to upgrade without Helm with bin/uc-migrate, the first start on an empty database, the MySQL case-sensitivity change, going back to 0.7, and each error message with what to do. Replace the outdated Hibernate auto-update paragraph in the deployment guide with a link to the guide. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
- The server and bin/uc-migrate print the same refusal for a foreign, newer or failed schema (Migrator.refusal); "Stop the servers and run bin/uc-migrate migrate" is kept for a 0.7 or pending database. - bin/uc-migrate runs from the repository or tarball root, so it reads etc/conf/hibernate.properties from any directory; it exits 1 when it finds neither, and builds a missing classpath file. - The MySQL run lock is per database, not per MySQL server. - Flyway fails on missing step locations; a jar without steps says so. - uc-migrate reuses the server's Hikari settings. - The shaded server jar keeps META-INF/services (merged), so Flyway finds its database support in connector tests. - The Helm chart no longer sets hibernate.hbm2ddl.auto=update. - Tests: release-to-release upgrade, casbin_rule conversion on MySQL, server properties always turn Hibernate schema updates off. - Docs: messages say who prints them; going back to 0.7 needs no restore; waiting applies to PostgreSQL and MySQL. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
…6 via 0.7 RealUpgradeTest runs real server images on each UpgradePath and test database: the first image writes a data set through the API with authorization on, later images just start, then the current server refuses the database until Migrator.migrate() upgrades it to the fresh install schema, and the data reads back. The test kit gains AcrossUpgradePaths, UpgradePath (BASE built from UC_TEST_BASE_REF by dev/build-image.sh, LATEST, V0_6_VIA_0_7), OldImage, OldServer and DataSet. The tests are tagged "upgrades": the default test and coverage runs leave them out, and testUpgrades, testUpgradesPostgres18 and testUpgradesMySQL8 run them, also in a new CI job. Real 0.7 databases showed that Hibernate's auto-update names the unique constraints of uc_columns, uc_delta_commits and uc_properties, so the H2 and PostgreSQL baselines now name them the same way, and the baseline check builds its reference schema with "update", as 0.7 installs did. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
The classpath file used by bin/start-uc-server and bin/uc-migrate listed both
server/target/classes and the server jar, so Flyway found every migration step
twice ("Found more than one migration with version 1") when running from a
source checkout or the Docker image. The jar holds the same classes.
Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
etc/db/h2db (the quickstart database) was created before 0.7 and had 10 of the 0.7 schema's 18 tables; older servers added the rest at startup with Hibernate auto-update, which this release turns off, so the server refused it. Upgraded the way a user upgrades: started v0.7.0 on it once (its auto-update added the missing tables), then ran bin/uc-migrate migrate (0.7 baseline, then steps 2 and 3). The sample data is unchanged. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
MigrationOutcome, SchemaState and DatabaseKind become nested types of SchemaMigrator, and RunLock a private nested class. No behaviour change. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
Every server start now sets up an empty database, adopts a database without schema history and applies the pending steps, under the run lock; it still refuses a newer, foreign or failed schema. Every start path (bin/start-uc-server, the Docker image, a Helm pod) goes through it, so bin/uc-migrate and UcMigrate are removed. The upgrade guide describes the new procedure: stop the servers, back up the database, start the new release. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
…ore it SchemaMigrator.BASELINE_RELEASE (0.7.0) is the one place the baseline release is named; messages use it and comments say "the baseline release". Before adopting a database without schema history, the migrator checks that it has every table the baseline step creates, and otherwise refuses it, naming the missing tables: such a database is from an earlier release, which has to be started on 0.7.0 once first. The upgrade guide says so. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
… built image UpgradePath.BASE now runs the base commit's shaded server jar as a child process on the test database, so the upgrade tests build no Docker image (dev/build-image.sh is removed). The jar comes from UC_TEST_BASE_JAR, the local cache ~/.cache/uc-upgrade-base/<sha>.jar, or is built once there from git archive. CI saves the jar of every main commit in the Actions cache and the upgrade job restores the one of the merge commit's first parent; the job runs only when schema-related paths change. Published releases keep their Docker Hub images, now pinned by digest; the moving "latest" path becomes a pinned V0_7. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
Move the upgrade tests out of unit-tests.yml into upgrade-tests.yml, which runs only when a change touches the schema, its migration code or the upgrade test kit. A base-jar job builds the server jar of the commit the PR starts from and shares it as an artifact. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
The upgrade tests now have two paths, and every old server is a server jar run as a child process (no release images, no Docker container mode): - BASE: the jar of the code this change starts from (UC_TEST_BASE_REF). - RELEASE_CHAIN: one jar per release, oldest first, from the release tags: strict vX.Y.Z, from SchemaMigrator.BASELINE_RELEASE up to, not including, this build's version, latest patch per minor. UC_TEST_RELEASE_CHAIN sets the tags (CI computes them once); unset, the kit computes them from git. Each jar is found by its commit: UC_TEST_JAR_DIR/<sha>.jar, else ~/.cache/uc-upgrade-base/<sha>.jar, else built once from that commit and cached. This replaces UC_TEST_BASE_JAR. The first jar writes the data set; every later jar reads it back, then the current server upgrades the database and reads it back; failures name the server that read it. The data set now has one column (and one function parameter) per column type, with every field set, and is compared as whole objects, ignoring only the fields a server fills in itself. The managed table is Delta, whose columns can't have the types Delta lacks (interval, void, user-defined, table), so it has the other 18; the external table is Parquet and has all 22. Dropped: V0_7, V0_6_VIA_0_7 and the pinned release images. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
A refs job picks the base commit (the merge commit's first parent) and the release chain from the tags; a build-jars matrix builds each one's server jar and uploads it as jar-<sha>; the upgrade tests download them all and find each by its commit through UC_TEST_JAR_DIR. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
…iting its own data The upgrade test now takes one path: every release tag from the baseline release up to this build's version, in version order (not only the latest patch of each minor), then the current server. Each release writes its own copy of the data set, named for the release (catalog, user email, sibling storage directories); the current server checks the schema against a fresh install and reads every copy back. The path from the PR's base commit is gone, with its jar in CI: unreleased code never writes a user's database. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
Test-only steps add uc_catalogs.name_copy (version 2000, one SQL step per database) and fill it from name (version 2001, a DataStep), either in one transaction or in batches of 2. DataStepTest checks on any database that each mode fills every row, a rerun changes nothing, a step whose change is already in place is recorded without running, and a batched step stopped after its first batch keeps that batch and completes on the rerun, recorded once. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
DataStepsUseNoEntitiesTest fails when a source file under server/src/main/java/io/unitycatalog/server/migrate/steps imports anything from io.unitycatalog.server.persist (entities, DAOs, repositories): those change with each release, while a step must keep working on the schema of its own release. AGENTS.md says where data steps go and that they use plain JDBC. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
Test-only steps mirror the release layout: SQL under server/src/test/resources/db/test-steps/<purpose>/ and Java under io.unitycatalog.server.migrate.teststeps.<purpose>. The slow step moves from kit/slowstep to teststeps/slow, leaving kit/ for the test toolkit. AGENTS.md says where test-only steps go and how they are loaded. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
The data-step test's own Flyway now includes the release Java steps, so its repair keeps working once a real step ships. A stopped batched step leaves a failed row on every database, PostgreSQL included (it runs outside a transaction); the comment and Javadoc now say so, and the batch contract warns about a value that can stay NULL. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
…chema_history Java steps share their versions with every database's SQL folder, so dev/check-migration-steps.sh now counts them in the step-order rule: a new SQL step must be above its folder's and the Java steps' highest version on the base, and a new Java step above every folder's. The release-branch rule covers Java steps too. DataStepTest read and repaired flyway_schema_history, the table's name before the rename, so two of its tests failed; it now uses uc_schema_history. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
A check is checks/<db>/C<version>__<description>.sql next to the step folders: one SELECT (or WITH ... SELECT) listing the rows that break the rule its step V<version> in <db>/ adds. Flyway scans only <db>/, so it never sees them. The step-order check skips them; its no-edit rule keeps merged checks from changing. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
Under the run lock, after the existing refusals and before any step runs, the migrator runs the check of every pending step (above the current version; above version 1 when it adopts a baseline-release database; none on an empty one). Each runs on its own connection in a read-only transaction. When any returns rows, the start fails and lists them (at most 20 per check). Checks are found next to the SQL step locations: <base>/<db> has its checks in <base>/checks/<db>. Test-only steps create test_named_items (3000) and make its names unique (3001, with a check), on every database. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
With --check-schema the server does not start: under the run lock, it prints the database's state and pending steps, runs the checks of the pending steps, and prints whether an upgrade would go through, with the same text as a refused start. It exits 0 when an upgrade would go through and 1 when it would be refused, and changes nothing. Operators run it with a new release before they stop the old servers. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
docs/server/upgrades.md: how to run bin/start-uc-server --check-schema with a new release before stopping the old servers, what its exit codes mean, and the refusal's message. AGENTS.md: how to add a check to a step. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
…ng it
A SQL step's change can be in the database while its history row is
missing: a run stopped between the step and Flyway's history insert, a
MySQL step (its DDL cannot roll back), or an operator applied it by
hand. The next start then fails ("already exists") and stays stuck.
The migrator now applies the pending steps one at a time under the run
lock. Before each SQL step of one statement, it checks whether the
step's change is already there; if so, it records the step without
running it (Flyway's skipExecutingMigrations with target set to that
step) and logs one line. This commit recognises CREATE TABLE; the other
kinds follow.
Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
…the database A SQL step that adds a column (ALTER TABLE t ADD [COLUMN] c), creates an index (CREATE [UNIQUE] INDEX i ON t) or adds a constraint (ALTER TABLE t ADD CONSTRAINT k) is recorded without running when the column, the index on t or the constraint on t is already there. Columns and indexes are read through DatabaseMetaData, constraints from information_schema.table_constraints, which all three databases have; names compare case-insensitively. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
A SQL step that changes a column's type (ALTER TABLE t ALTER COLUMN c [SET DATA TYPE | TYPE] type[(n)] on H2 and PostgreSQL, ALTER TABLE t MODIFY [COLUMN] c type[(n)] on MySQL) is recorded without running when the column already has that type and size. Type names compare case-insensitively, with H2's metadata names for CLOB and VARCHAR; a type with other parameters (MySQL's enum (...)) is not recognised and the step runs. A 0.7.0 database adopted with V2's widening already applied now records V2 without running it. Its baseline is recorded before the steps: a Flyway run that only records steps would record V1 as one of them instead of as the baseline. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
Two kinds of step were recorded without running although only part of their change, or a different one, was in the database: - A statement with several changes, such as ALTER TABLE t ADD COLUMN a INT, ADD COLUMN b INT with only a there: the probe saw a and recorded the step, leaving b missing. A statement with a comma outside parentheses and quotes now gets no probe and runs. - A type change without a size, such as ALTER COLUMN c TYPE varchar over varchar(64): the type names matched, so the step was recorded and the column kept its size. Without a size, only types that take none (text, clob, mediumtext, longtext) are probed; any other type runs. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
This was referenced Oct 25, 2026
Closed
This was referenced Oct 25, 2026
Closed
The type-change probe compared only the type and size, so a step that restates them and changes something else was recorded without running: a MySQL MODIFY c varchar(64) NOT NULL over a nullable varchar(64), or a PostgreSQL ALTER COLUMN c TYPE varchar(64) COLLATE "C". The probe now recognises a type change only when nothing but NULL or NOT NULL follows the type; any other clause (DEFAULT, COLLATE, CHARACTER SET, USING, ...) gets no probe, so the step runs. A NULL or NOT NULL must match the column's nullability. MySQL's MODIFY and H2's ALTER COLUMN c <type> restate the column: they drop its default, and MySQL's makes it nullable unless it says NOT NULL, so for them the column must also have no default, and on MySQL be nullable when the statement says nothing. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
shba24
added a commit
to shba24/unitycatalog
that referenced
this pull request
Oct 25, 2026
Conflicts: SchemaMigrator type-change probe keeps the Optional return with the new end-anchored regex and the nullable/restates hasType arguments; StepAlreadyInDatabaseTest keeps both test-step directories. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
Collaborator
Author
|
Closing this draft. Its code is kept as a reference on |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🥞 Stacked PR
Use this link to review incremental changes.
PR Checklist
docsis updatedDescription of changes
Migration steps that can't break an upgrade: data changes as Java steps that are safe to repeat, checks that stop an upgrade before any change when rows would break a new rule, and SQL steps whose change is already there recorded instead of failing.
All three parts decide, before or around each step, whether it can run safely. They live in
SchemaMigratorand the test-only steps underserver/src/test/resources/db/test-steps/. The commits are in this order: part 1, part 2, part 3.Part 1: Java data steps
A migration step that changes rows is now a Java class that is safe to repeat and can commit in batches on large tables.
#2046 keeps SQL steps to one DDL statement each. Data changes (filling a new column, fixing rows before a unique constraint) need code. This PR adds the base class for them; no real data step ships yet.
DataStep(extends Flyway'sBaseJavaMigration):alreadyDone(connection): a probe. When it returns true, the step is recorded without running.apply(connection): the change. By default it runs in one transaction.batched()returns true): the step runs outside Flyway's transaction andupdateInBatches(connection, sql, batchSize)commits after each batch. If a run stops, the rerun continues with the rows not yet done.io.unitycatalog.server.migrate.steps, whichSchemaMigratornow loads on every database. Version numbers are shared with the SQL steps.dev/check-migration-steps.sh(from [Server] Check schema migration steps on every pull request #2046) now also covers Java steps: it refuses edits to merged ones, a new Java step must be numbered above every database's steps on the base, a new SQL step above its folder and the Java steps, and release branches take no new Java steps either.DataStepsUseNoEntitiesTestfails when a step importsio.unitycatalog.server.persist. Entities change with each release, and a step must keep working on the schema of its own release, so steps use plain JDBC.server/src/test/resources/db/test-steps/<purpose>/, Java inio.unitycatalog.server.migrate.teststeps.<purpose>. The slow step from [Server] Add the schema steps and a manual --upgrade-schema command #2045 moved there from the test kit.AGENTS.mddescribes both.Testing
DataStepTestruns on H2, PostgreSQL 18 and MySQL 8.4. A test-only SQL step creates its own table (test_data_step_items), and two test-only data steps fill a column in it, one in a single transaction and one in batches of 2.alreadyDone()is true, the step is recorded and changes nothing.DataStepsUseNoEntitiesTestfailed on a scratch step that imported an entity (since removed).postgresql/V5+ new JavaV4__Fill.javafails ("…is version 4, not above 5, the highest step of any database on base"); JavaV5fails,V6passes; base JavaV7+ newh2/V6fails; an edited merged Java step fails; a change topackage-info.javaalone passes.📐 Design notes & details
Why batched steps run outside Flyway's transaction. Inside it, a failure rolls back every batch, so a step on a large table could only ever finish in one go. Outside it, each batch commits, and the step's batch statement only selects rows not yet done, so a rerun continues where it stopped. Flyway runs non-transactional Java steps on a connection with autocommit on.
updateInBatchescommits only when autocommit is off.Batch SQL per database. PostgreSQL has no
UPDATE … LIMIT. Each step supplies its batch statement for the database it runs on (databaseKind(connection)), andupdateInBatchesstays database-neutral. The test step usesWHERE id IN (SELECT id … LIMIT ?)on H2 and PostgreSQL andUPDATE … LIMIT ?on MySQL.A stopped batched step. It runs outside a transaction, so on every database (PostgreSQL included) Flyway records a failed row in its history. Its committed batches stay. The server refuses a failed database until the row is repaired; after the repair, the rerun continues with the rows not yet done. Clearing that row safely is the failed-step recovery PR later in this stack.
Not covered here (reviewers' notes): no test makes a one-transaction data step fail midway to show the rollback (Flyway's own transaction handling), and no test loads the empty
stepslocation from the packaged jar (the Python client CI job runs the packaged server and covers it).Why the empty
stepspackage needs-Xpkginfo:always. Flyway refuses a location that doesn't exist, and apackage-info.javawith only documentation compiles to no class by default. With the flag, the package is in the jar, and Flyway finds it with no steps.Part 2: bad-row checks and
--check-schemaAn upgrade now stops before any change when existing rows would break a rule of the new release, and lists those rows. Operators can run the same check against the live database before they stop the old servers.
A future step may add a rule that existing rows can break, for example unique catalog names. Without a check, that step fails halfway through the upgrade. This PR adds:
db/migration/checks/<db>/C<version>__<description>.sql, oneSELECTthat returns the rows breaking it. Flyway only scansdb/migration/<db>/, so it never runs a check. No real check ships yet.... and N more. An empty database runs no checks.bin/start-uc-server --check-schema: prints the database's state and pending steps, runs their checks, and exits0if the upgrade would go through or1if it would be refused (bad rows, or a newer, foreign, failed or pre-0.7.0 database). It never migrates and never serves, so it can run with the new release against the live database while the old servers keep serving.SqlStepsAreSingleDdlTestrequires each check to be oneSELECT/WITHstatement with a step of the same version in the same database.dev/check-migration-steps.shskips checks in its numbering rule; its no-edit rule covers them.docs/server/upgrades.md"Rows that block an upgrade";AGENTS.mdsays how to add a check.Testing
BadRowCheckTestruns on H2, PostgreSQL 18 and MySQL 8.4 with test-only steps on their own table:V3000createstest_named_items,V3001adds a unique constraint onname, andC3001lists duplicate names.a: the upgrade is refused with exactly those rows listed; the schema and the history are unchanged andV3001is not applied. Before the change,V3001ran and failed with a unique-key violation.... and 5 more.V3001.--check-schema(through the methodmaincalls): with the duplicates it returns 1 and lists them, and nothing changes; after the fix it returns 0 andV3001is still not applied.SqlStepsAreSingleDdlTestfailed on a scratch check holding anUPDATEand on a check without a step (since removed).migrate.*tests: H2 36 passed (1 MySQL-only test skipped), PostgreSQL 36 passed (1 skipped), MySQL 37 passed.OptionParserTest12 passed.bin/start-uc-server --check-schemaon a copy of the sample database printsDatabase: CURRENT, schema version 3; this release ends at 3.,Pending steps: none.,The upgrade would go through.and exits 0. From the packaged jars, with a temporary check and one history row removed, it listed the check's rows and exited 1 (the temporary check was removed).📐 Design notes & details
Why checks live in their own folder. The server runs Flyway with strict file-name validation, so a
Cfile next to the steps makes every migrate fail with "Unrecognised migration name format". Turning that validation off would let a misnamed step be skipped silently. The checks of a step folder<base>/<db>are in<base>/checks/<db>, so the test-only step folders get their checks the same way, with no extra configuration.Why the checks run inside the run lock. The state, the pending steps and the rows are read together with the migration that follows, so a second server starting at the same time can't change the answer in between.
Why a check reads only columns no step of the same release writes. Then it gives the same answer before, during and after a partially applied upgrade (
AGENTS.md).Why
--check-schemais safe on a live database. It takes UC's run lock (0.7.x servers never take it), reads, and rolls back. On PostgreSQL and MySQL the read-only transaction is enforced by the database; on H2 the one-SELECTrule covers it.Not in this PR: real checks (they come with the steps that need them) and the Helm pre-upgrade hook that will run
--check-schema(later in the stack).Part 3: steps whose change is already in the database
A SQL step whose change is already in the database is now recorded as done without running, so an upgrade no longer gets stuck on "already exists".
A step's DDL can be in the database while the history says it isn't applied: the server crashed between the DDL and Flyway's history row, MySQL can't roll DDL back, or someone applied the step by hand. Today the next start fails ("column already exists") and keeps failing. This PR:
Probes each pending SQL step before it runs. The pending steps run one at a time under the run lock, after the checks in part 2. For each one, the server recognises the step's statement and checks the database through JDBC metadata:
CREATE TABLE ttexistsALTER TABLE t ADD [COLUMN] ct.cexistsCREATE [UNIQUE] INDEX i ON tiexists ontALTER TABLE t ADD CONSTRAINT kkexists ontALTER COLUMN c [SET DATA] TYPE …/MODIFY c …t.calready has that type and sizeIf it's there, the step is recorded (Flyway's
skipExecutingMigrations) and the server logsStep 2 (widen function param type json) is already in the database; recorded it without running it.Runs the step whenever the probe can't tell. Other statements (the baseline, MySQL's multi-statement step 3, Java steps, which already check themselves), statements with more than one change (
ADD COLUMN a, ADD COLUMN b), a type change without a size over a sized type (varcharovervarchar(64)), and types with extra parameters (enum(…),decimal(10,2)) all run as before.Docs: one paragraph in
docs/server/upgrades.md.Testing
StepAlreadyInDatabaseTestruns on H2, PostgreSQL 18 and MySQL 8.4, with test-only steps on their own table (test_repeat_items):SUCCESSand its statement is never sent to the database (a data-source wrapper records every statement). Before the probe, each failed: "Table … already exists",Duplicate column name,Duplicate key name,relation … already exists; for the widening, the statement was re-sent.varcharovervarchar(64): the step runs (H2 and PostgreSQL; MySQL'svarcharneeds a size).migrate.*tests: 45 passed on each of H2, PostgreSQL and MySQL (1 skipped each: a MySQL-only and a non-MySQL test).From the final review (Codex + Claude reviewers, each finding reproduced by a failing test first): a type-change step is probed only when it restates the type, size and (optionally)
NULL/NOT NULL; any other clause (DEFAULT,COLLATE,CHARACTER SET,USING) means the step runs. MySQLMODIFYand H2's bareALTER COLUMNalso drop a column's default, so they're probed only on a column without one.📐 Design notes & details
Why one Flyway run per step. Flyway can't skip one step in the middle of a run, but it can record steps without running them (
skipExecutingMigrations, in the open-source edition). Running each pending step withtargetset to its version lets the server decide step by step. The run lock is held across all of them.Why a 0.7.0 database is now baselined before its steps. Flyway's baseline-on-migrate doesn't write the baseline row when the run only records steps; it recorded V1 as a skipped step instead. Calling
baseline()first keeps the history the same as before: a baseline row at 1, then the steps.Why "can't tell" means "run". A wrong "already there" leaves the schema wrong without any error. Running a step whose change is there fails loudly with "already exists", which is what happens today, so every case the probe can't decide falls back to that.
Not in this PR: rebuilding a PostgreSQL index left invalid, drift repair (later in the stack), recovery from a failed step (later in the stack).
This pull request and its description were written by Isaac.