Skip to content

[Server] Migration steps that can't break an upgrade: data steps, bad-row checks, steps already applied - #2051

Closed
shba24 wants to merge 57 commits into
unitycatalog:mainfrom
shba24:stack/uc-flyway-safe-repeat
Closed

shba24 wants to merge 57 commits into
unitycatalog:mainfrom
shba24:stack/uc-flyway-safe-repeat

Conversation

@shba24

@shba24 shba24 commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator

🥞 Stacked PR

Use this link to review incremental changes.


PR Checklist

  • A description of the changes is added to the description of this PR.
  • If there is a related issue, make sure it is linked to this PR.
  • If you've fixed a bug or added code that should be tested, add tests!
  • If you've added or modified a feature, documentation in docs is updated

Description of changes

Reviewing: this PR's own changes are shba24/unitycatalog@stack/uc-flyway-merge-checks...stack/uc-flyway-safe-repeat. GitHub's Files changed tab also shows #2009, #2044, #2045, #2046, which this PR builds on, until they merge.

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 SchemaMigrator and the test-only steps under server/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's BaseJavaMigration):
    • 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 mode (batched() returns true): the step runs outside Flyway's transaction and updateInBatches(connection, sql, batchSize) commits after each batch. If a run stops, the rerun continues with the rows not yet done.
    • It logs rows per batch and the running total. Its checksum comes from the step's version and description.
  • Location: real data steps go in io.unitycatalog.server.migrate.steps, which SchemaMigrator now 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.
  • No entities in data steps: DataStepsUseNoEntitiesTest fails when a step imports io.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.
  • Test-only steps in one place: SQL in server/src/test/resources/db/test-steps/<purpose>/, Java in io.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.md describes both.

Testing

DataStepTest runs 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.

  • Each mode fills all 5 rows.
  • A rerun changes nothing.
  • When alreadyDone() is true, the step is recorded and changes nothing.
  • A batched run that stops after its first batch has kept that batch: 2 of 5 rows are filled. After Flyway's repair, the rerun fills the rest, and the history has the step once.
    • Making the step transactional, or removing the per-batch commit, fails only this test, on all three databases.
  • DataStepsUseNoEntitiesTest failed on a scratch step that imported an entity (since removed).
  • The script's Java-step rules in a scratch clone: base postgresql/V5 + new Java V4__Fill.java fails ("…is version 4, not above 5, the highest step of any database on base"); Java V5 fails, V6 passes; base Java V7 + new h2/V6 fails; an edited merged Java step fails; a change to package-info.java alone 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. updateInBatches commits 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)), and updateInBatches stays database-neutral. The test step uses WHERE id IN (SELECT id … LIMIT ?) on H2 and PostgreSQL and UPDATE … 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 steps location from the packaged jar (the Python client CI job runs the packaged server and covers it).

Why the empty steps package needs -Xpkginfo:always. Flyway refuses a location that doesn't exist, and a package-info.java with 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-schema

An 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:

  • Checks: a step that adds such a rule ships db/migration/checks/<db>/C<version>__<description>.sql, one SELECT that returns the rows breaking it. Flyway only scans db/migration/<db>/, so it never runs a check. No real check ships yet.
  • At server start: under the run lock, after the existing refusals and before the first step, the checks of the pending steps run, each in a read-only transaction that is rolled back. If one returns rows, the server doesn't start and nothing changes:
    The upgrade is stopped before any change: 1 check found rows that break a rule of this release.
    Check 3001 (unique test named item names) found 2 rows:
      id=1, name=a
      id=2, name=a
    Fix them as docs/server/upgrades.md shows (section "Rows that block an upgrade"), then start the server again.
    
    At most 20 rows per check are listed, then ... 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 exits 0 if the upgrade would go through or 1 if 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.
  • Rules: SqlStepsAreSingleDdlTest requires each check to be one SELECT/WITH statement with a step of the same version in the same database. dev/check-migration-steps.sh skips checks in its numbering rule; its no-edit rule covers them.
  • Docs: docs/server/upgrades.md "Rows that block an upgrade"; AGENTS.md says how to add a check.

Testing

BadRowCheckTest runs on H2, PostgreSQL 18 and MySQL 8.4 with test-only steps on their own table: V3000 creates test_named_items, V3001 adds a unique constraint on name, and C3001 lists duplicate names.

  • Two rows named a: the upgrade is refused with exactly those rows listed; the schema and the history are unchanged and V3001 is not applied. Before the change, V3001 ran and failed with a unique-key violation.
  • 25 duplicate rows: 20 listed, then ... and 5 more.
  • After deleting one row, the upgrade applies V3001.
  • An empty database runs no check.
  • --check-schema (through the method main calls): with the duplicates it returns 1 and lists them, and nothing changes; after the fix it returns 0 and V3001 is still not applied.
  • SqlStepsAreSingleDdlTest failed on a scratch check holding an UPDATE and 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. OptionParserTest 12 passed.
  • By hand: bin/start-uc-server --check-schema on a copy of the sample database prints Database: 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 C file 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-schema is 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-SELECT rule 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:

    Step Already there when
    CREATE TABLE t table t exists
    ALTER TABLE t ADD [COLUMN] c column t.c exists
    CREATE [UNIQUE] INDEX i ON t index i exists on t
    ALTER TABLE t ADD CONSTRAINT k constraint k exists on t
    ALTER COLUMN c [SET DATA] TYPE … / MODIFY c … t.c already has that type and size

    If it's there, the step is recorded (Flyway's skipExecutingMigrations) and the server logs Step 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 (varchar over varchar(64)), and types with extra parameters (enum(…), decimal(10,2)) all run as before.

  • Docs: one paragraph in docs/server/upgrades.md.

Testing

StepAlreadyInDatabaseTest runs on H2, PostgreSQL 18 and MySQL 8.4, with test-only steps on their own table (test_repeat_items):

  • One step per probe kind, its statement applied by hand first: the step is recorded as SUCCESS and 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.
  • Without the hand change, every step runs.
  • A 0.7.0 database with step 2's widening applied by hand: on adoption, step 2 is recorded without running and the database is current.
  • Two changes in one statement with only the first there: the step runs and fails on the second (before the fix it was recorded silently on PostgreSQL and MySQL). A size-less varchar over varchar(64): the step runs (H2 and PostgreSQL; MySQL's varchar needs a size).
  • With the probe forced off, 6 of the 7 original tests fail on every database.
  • 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. MySQL MODIFY and H2's bare ALTER COLUMN also 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 with target set 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.

shba24 and others added 30 commits October 25, 2026 01:53
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]>
…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]>
shba24 and others added 15 commits October 25, 2026 05:09
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]>
…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]>
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]>
@shba24

shba24 commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator Author

Closing this draft. Its code is kept as a reference on ref/pr3-safe-repeat; the schema upgrade work continues in smaller pull requests built from it, starting with #2045 and #2046.

@shba24 shba24 closed this Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant