Repository navigation
Conversation
This was referenced Oct 24, 2026
shba24
force-pushed
the
stack/uc-flyway-data-steps
branch
5 times, most recently
from
October 24, 2026 23:42
a03f9f4 to
0db8d08
Compare
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]>
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]>
Closed
3 of 4 tasks
…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]>
3 of 4 tasks
No changes yet. This pull request will hold the lock-wait cap, failed-step recovery and the safe stop on SIGTERM; the real commits replace this one. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
Every connection of a migration run except the run lock's (Flyway's, through initSql, and those of the probes and checks) waits at most 60 seconds for a lock another session holds: PostgreSQL lock_timeout, MySQL lock_wait_timeout and innodb_lock_wait_timeout, H2 LOCK_TIMEOUT. A step that waits longer fails with a message naming the step, the table when the step's statement names one, and what to do. Closing the migrator soft-evicts the connections of a pool it doesn't own, so the server's own sessions don't keep the cap. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
A step that failed in an earlier run (H2 and MySQL DDL can't roll back, and a batched data step commits each batch on every database) no longer refuses every start. Under the run lock, before the checks, the run looks at each failed step: a SQL step whose probe can tell whether its change is there, or a DataStep, which changes only the rows not changed yet. Then Flyway's repair removes the failed rows and the run records or runs the steps like pending ones. Any other failed step (several changes, a statement the probe doesn't recognise, a step not in this build) is refused with a message that says what to do. --check-schema lists a failed step that runs again among the pending steps and runs its check: the current version no longer counts a failed step. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
Flyway 13 logs "initSql is deprecated" each time the migrator loads a Flyway configuration, several times on every server start. Flyway now takes its connections through the migrator, which sets the lock wait on each one, as it already does for the probes and checks. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
While a server start migrates the schema, a shutdown hook asks the run to stop and waits for it, at most the lock wait (60 seconds). The run stops before its next step, or after the batch a batched data step is in; a statement that is running is not interrupted. The server logs "Stopped the schema migration at <boundary> on SIGTERM; start the server again to finish it.", also on standard error since Log4j's own shutdown hook has usually stopped the logger by then, and the process exits non-zero. The next start runs the step again, and a batched step goes on from the rows it has not changed yet. The test starts a server in a child process on PostgreSQL or MySQL (H2 has no sleep function for the slow step, and closes its database in a shutdown hook of its own), sends SIGTERM during a batch and checks that the batch committed before the process exited, then finishes the step in a second run. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
…rver bin/start-uc-server ran java as a child of bash. In the Docker image (CMD ["./bin/start-uc-server"]) and so in the Helm chart, bash is PID 1 and ignores SIGTERM, so the JVM never got the signal and was killed after the grace period; outside a container, SIGTERM killed bash and left java running. The script now execs java, which then receives the signal itself and runs its shutdown hooks, such as the safe stop of the startup migration. The script's exit status is java's, as before. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
docs/server/upgrades.md gets three sections: the 60-second lock wait, what the next start does after a failed step, and the safe stop on SIGTERM. The entry for a failed step no longer says to always restore the backup. The refusal for a failed step the server can't check now names the ways out that work: restore the backup, or undo the step's change and remove its failed record as the new section shows. Making such a step's change complete by hand would not help: the server still can't check it. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
MySQL's step 3 converts every table to a case-sensitive collation in many statements, each safe to repeat; it failed in practice on latin1 databases. A start no longer refuses it after a failure: the run removes its failed record and runs it again. SchemaMigrator.SAFE_TO_REPEAT declares such steps, and SqlStepsAreSingleDdlTest reads it instead of listing them itself. 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
…branch Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
This was referenced Oct 25, 2026
Closed
…r's pool
The server's pool doesn't autocommit (Hibernate manages transactions), and
the migration took its connections from it. On PostgreSQL the lock-wait SET
then opened a transaction, so a bad-row check's setReadOnly(true) failed
("Cannot change transaction read-only property in the middle of a
transaction") and every check refused the start. A statement run on such a
connection outside Flyway would also never be committed.
connection() now sets autocommit before the SET, as the backup's connections
do; a check still runs in its own read-only transaction. Flyway gets the same
autocommit connections the tests always gave it. The new test runs the checks
and the upgrade on a pool built like the server's.
Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
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]>
…e probe The add-column probe also matched ALTER TABLE t ADD UNIQUE (c), ADD PRIMARY KEY, ADD INDEX and the like, taking the keyword for a column name. It then reported the change as absent instead of "can't tell", so a failed step of that form whose change was there was run again: an unnamed unique key was added twice, and a named index failed again on every start. These forms now get no probe: a failed one is refused with the "can't tell" message, a pending one runs. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
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]>
shba24
added a commit
to shba24/unitycatalog
that referenced
this pull request
Oct 25, 2026
Conflict: BadRowCheckTest imports. SchemaSnapshot is in the migrate package on this branch, so the kit import goes; the HikariDataSource and HibernateConfigurator imports of the new pool test stay. 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
An interrupted or failed upgrade can now be started again: steps don't wait forever for a lock, a failed step is recovered when the server can tell how much of it ran, and SIGTERM stops the migration at a safe point.
lock_timeout, MySQLlock_wait_timeoutandinnodb_lock_wait_timeout, H2LOCK_TIMEOUT). A step that hits it is refused with "Step () waited more than 60 seconds for a lock on ; another session holds it. Stop the other sessions on the database, then start the server again." Closing the migrator replaces the pool's connections, so the server's own sessions don't keep the cap.repair()) and the step is recorded or run;bin/start-uc-serverrunsexec java. Before, java ran as a child of the script, so in a container (script as PID 1) SIGTERM never reached the JVM and Kubernetes killed it after the grace period.docs/server/upgrades.mdcovers lock waits, "A step that failed" (with theDELETEfor a failed record) and SIGTERM.Testing
On H2, PostgreSQL 18 and MySQL 8.4 (
migrate.*: H2 49 passed, PostgreSQL 50, MySQL 51; skipped tests are the ones for other databases):LockWaitTest: another session holds a lock on the step's table; the step fails within the cap (2 s in the test) with the message; after the other transaction ends, a restart applies the step.DataStepTest.serverStopsAtABatchOnSigterm(PostgreSQL, MySQL): a child server JVM gets SIGTERM during a 1-second batch; it exits non-zero, keeps the rows of the batch that was running (more than were filled when the signal was sent, fewer than all), records no success; the next start completes the step. With the hook removed, the running batch was lost on PostgreSQL (the test failed). H2 is skipped: it closes its database in its own shutdown hook, so the running step fails, and the next start recovers it as a failed step.kill -TERMwaits for step 2 to finish, logs the stop line and exits 143;docker stop -t 40takes 17.6 s and exits 143. The old script as PID 1: 40.4 s, exit 137 (SIGKILL), both steps applied anyway.From the final review (each finding reproduced first): migration connections now turn autocommit on before the lock-wait
SET; on the server's own pool (autocommit off) theSETopened a transaction on PostgreSQL, so bad-row checks failed ("Cannot change transaction read-only property in the middle of a transaction") and statements outside Flyway weren't committed (BadRowCheckTest.checksAndUpgradesOnTheServersPool).ADD UNIQUE (…)/PRIMARY KEY/FOREIGN KEYare no longer taken for a column add, so a failed unnamed-key step is refused instead of adding a second key.📐 Design notes & details
Why a constant, not a setting, for the cap. The fix for a held lock is to stop the other sessions; a setting would be one more released name to keep.
Why not Flyway's
initSql. Flyway 13 logs a deprecation warning for it on every configuration load, and its connection callback fires on one connection only. Flyway gets a data source whose connections are set up by the same helper the probes use.Why the stop line also goes to stderr. Log4j's own shutdown hook usually stops the logger before the migration reaches a boundary.
What
repair()also does. It realigns stored checksums of applied steps and marks applied steps missing from the build as deleted. #2046's merge checks keep merged steps from changing, so this only matters together with a failed row.Why PostgreSQL rarely has a failed row. DDL is transactional there, and Flyway's transactional lock rolls the failure record back too; the recovery matters for MySQL, H2 and batched data steps.
This pull request and its description were written by Isaac.