Skip to content

[Build] Check the schema steps on every pull request - #2113

Merged
yili-db merged 17 commits into
unitycatalog:mainfrom
shba24:stack/uc-upgrade-merge-checks
Nov 13, 2026
Merged

yili-db merged 17 commits into
unitycatalog:mainfrom
shba24:stack/uc-upgrade-merge-checks

Conversation

@shba24

@shba24 shba24 commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

🥞 Stacked PR

Use this link to review incremental changes.


This PR adds the checks that every new schema step must pass before it merges, so that --upgrade-schema can tell from the schema whether a step ran, and a step avoids the changes that rows already in a database can make fail: a unique index, an index whose PostgreSQL entry (key and INCLUDE columns) can be over 2,704 bytes, a partial index (its predicate runs on every row), NOT NULL without a default, a narrowing type change (including an unconstrained PostgreSQL numeric to one with a precision), dropping an enum or set member, and a MySQL MODIFY that drops a column's default or collation.

What a contributor sees

  • A step after the first holds one SQL statement as Flyway sends it to each database, or none when the step changes nothing on that database. The statement creates a table, creates an index that is not unique, adds a column (NOT NULL only with a default, and without a key or CHECK rule), changes a column's type, or drops a NOT NULL. A type change must widen the column, and no change may make a column NOT NULL.
  • Every step exists for H2, PostgreSQL and MySQL as a versioned V<n>__<description>.sql file, and has an effect file for each database.
  • A new CI job fails a pull request that edits, deletes or renames a merged step or effect file, adds a step whose number is not above every merged one, or adds any step on a release branch (branch-*).
  • The "All tests" rows of Unit Tests (H2, PostgreSQL 18, MySQL 8) run the step checks on every pull request, and fail if either check class ran no tests or skipped them.
  • --upgrade-schema refuses a build that holds a repeatable (R__) step, before it changes the database.
  • AGENTS.md and CODE_REVIEW.md now say that a schema change ships as a new Flyway step with its effect files, instead of relying on Hibernate's update. The same line for the AI reviewer's rules is in [Build] Leave the schema-change rule to CODE_REVIEW.md in the domain reviewer #2221.

For example, a step V3__add_index.sql with CREATE UNIQUE INDEX ... fails the checks: a unique index can fail on rows that are already in the database.

What doesn't change yet

Tests

Ran locally with UC_TEST_MIGRATION_CHECKS=true, every test in io.unitycatalog.server.migrate (MigrationStepRulesTest, BaselineMatchesEntitiesTest, SchemaMigratorTest and the rest): on H2, PostgreSQL 18 and MySQL 8 at 431a23e (the later commit only moves the AI reviewer's line to #2221). CI runs the full suite with the step checks on all three.

📐 Design notes & details

Design

  • MigrationStepRulesTest reads what Flyway sends to each database with JSqlParser (a test-only dependency, Apache-2.0 or LGPL-2.1), not the raw file, so the check sees the same statements as the database. SQL that JSqlParser can't read fails the check, because what it can't read, it can't check.
  • Step 1, the 0.7.0 baseline, may create any table and index, but not from a query or CONCURRENTLY.
  • Why these limits: with one statement per step, the schema shows whether the step ran, which [Server] Retry a schema upgrade that stopped part way #2114 needs to retry a run that stopped. A unique index, a NOT NULL without a default, or a narrowing type change can fail on rows already in a database, so they're out.
  • The step checks and BaselineMatchesEntitiesTest now run only with UC_TEST_MIGRATION_CHECKS=true, which the "All tests" rows set; a plain build/sbt test skips them.
  • dev/check-migration-steps.sh (job "Merged migration steps unchanged" in unit-tests.yml) compares the pull request with its base: merged steps and effect files stay as they are, because databases already ran those steps and the effect files tell --upgrade-schema what they did. A new step must be numbered above every merged step for that database, because Flyway refuses a step below the recorded version. Release branches take no new steps, because the number could clash with a different step on main.
  • The step order is checked against the pull request's base, so two open pull requests can each pass with the same step number. AGENTS.md asks the author to merge main into a pull request that adds a step just before it merges (or to rely on a merge queue or "require branches to be up to date").

Test coverage

Stack

Part 3 of 8 of the schema-upgrade stack:

  1. [Server] Add the schema steps and a manual --upgrade-schema command #2045 [Server] Add the schema steps and a manual --upgrade-schema command
  2. [Server] Adopt existing databases in --upgrade-schema #2112 [Server] Adopt existing databases in --upgrade-schema
  3. [Build] Check the schema steps on every pull request #2113 [Build] Check the schema steps on every pull request (this PR)
  4. [Server] Retry a schema upgrade that stopped part way #2114 [Server] Retry a schema upgrade that stopped part way
  5. [Server] Add a read-only --check-schema command #2115 [Server] Add a read-only --check-schema command
  6. [Build] Build the sample database instead of checking it in #2116 [Build] Build the sample database instead of checking it in
  7. [Server] Let only the schema steps change the schema #2117 [Server] Let only the schema steps change the schema
  8. [Server] Add a temporary fallback to Hibernate schema updates #2118 [Server] Add a temporary fallback to Hibernate schema updates

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

This pull request and its description were written by Isaac.

@shba24

shba24 commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator Author

/review

@shba24 shba24 changed the title [Server] Check what each schema step may change [Build] Check the schema steps on every pull request Nov 4, 2026
@shba24

shba24 commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator Author

/review

yili-db pushed a commit that referenced this pull request Nov 7, 2026
…2045)

## 🥞 Stacked PR
Use this
[link](https://github.com/unitycatalog/unitycatalog/pull/2045/files) to
review incremental changes.
-
[**stack/uc-flyway-schema**](#2045)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2045/files)]
← _this PR_
-
[stack/uc-upgrade-adopt](#2112)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2112/files/dfe03066ca3f748f42b916b6908d7ad23e50b7af..187be0b86367b2fe7cb3db852b33039bb534bbfe)]
-
[stack/uc-upgrade-merge-checks](#2113)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2113/files/b2982d514290d5a7cbb70010c31686d681f732d0..837c49999da9d021a385b5878dd5724f902b8ac0)]
-
[stack/uc-upgrade-retry](#2114)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2114/files/86b2b75709c1378fb7d199dabf453033849885c1..6aed4147e2b76bc45b076c5d1769a85461d9aaaf)]
-
[stack/uc-upgrade-check-schema](#2115)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2115/files/8ba3b07ae080f5d07518392679ddba696074afab..b7a8d07fbeae61d80e3518336ad7290b20cd6770)]
-
[stack/uc-sample-database-built](#2116)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2116/files/6a59493c75da317dfde80776cd29f6ae030eeabf..4221ea5224ceaf8b1122c0b00ba41eeaa6003840)]
-
[stack/uc-flyway-owns-schema](#2117)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2117/files/ccb5e69e8b53596d6f2925797970c9828505edba..b1e7a896aa2e48163e9a750265d99abf69c52371)]
-
[stack/uc-hibernate-fallback](#2118)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2118/files/861ca93eabac0bee2f40ebd4d0976dfd964929cf..0ed55964bab3e0d505fc330f41cdf00c48ff40b9)]

---------
This PR adds Unity Catalog's database schema as Flyway steps, and a
command that you run by hand to apply them: `bin/start-uc-server
--upgrade-schema`. The command is optional for now. The server still
sets up and updates its schema with Hibernate when it starts.

This PR now only adds the steps and the manual command. The rest of what
this PR held at the last review moved to the next PRs of the stack:
adopting existing databases to #2112, the merge checks and contributor
rules to #2113, the built sample database to #2116, and the start-time
schema check, the Hibernate refusals, the Helm init container and the
step-built test schemas to #2117. "What moved out of this PR" in the
details lists each piece.

### What you see

- The schema is a list of steps for each supported database: H2,
PostgreSQL and MySQL. Step 1 is the schema of release 0.7.0. Step 2
widens the function parameter type column (#2013).
- `bin/start-uc-server --upgrade-schema` applies the steps that are not
applied yet, records each one in the `uc_schema_history` table, and
exits without starting the server. It exits with 0 and prints `The
database schema is at version 2.` on success, and exits with 1 and
prints the reason otherwise.
- It sets up an empty database, also one that holds only other
applications' tables, which it leaves alone. It upgrades a database that
it set up earlier.
- It refuses, and changes nothing, in these cases:
- The database has Unity Catalog's tables but no schema history, for
example one that a server set up at start. The message says that
adopting such a database is not supported yet; #2112 adds it.
  - The database's schema is newer than this release.
- Flyway's check of the schema history fails, for example after a failed
step.
- The configuration uses H2 in server mode, `hibernate.default_schema`
or `hibernate.default_catalog`, an in-memory database, or a database
other than H2, PostgreSQL and MySQL, or a configuration file is missing.
- On PostgreSQL and MySQL, a run lock lets only one command apply steps
at a time. A second command waits for the first.
- The new page `docs/server/upgrades.md` describes the command, backups,
the lock, and the messages.

### What doesn't change yet

- Server start still runs Hibernate's `update`
(`hibernate.hbm2ddl.auto=update` in `etc/conf/hibernate.properties`),
and the Helm chart still sets it. The steps build the same schema that
Hibernate builds from the entities, so on a database that the steps set
up, Hibernate changes nothing.
- The test suite still builds its schemas with Hibernate, and the sample
database `etc/db/h2db.mv.db` is the same as on `main`.
- #2117 makes the steps the only way the schema changes.

### Tests

Ran locally on H2: compiled all modules and their tests with checkstyle,
and ran the schema migration tests, the option parser, Hibernate
configurator and key mapper tests, and the catalog SDK tests (46
passed). The four run-lock tests skip on H2, which takes no run lock;
they ran locally on PostgreSQL 18 and MySQL 8 only at the top of the
stack (#2118). CI runs the full suite on H2, PostgreSQL 18 and MySQL 8.

<details><summary><b>📐 Design notes &amp; details</b></summary>

### Design

- `SchemaMigrator` classifies the database from its `uc_*` tables only:
`EMPTY` (no `uc_*` table), `CURRENT`, `PENDING`, `AHEAD`, or
`UNVERSIONED_UC` (Unity Catalog's tables without history). Other
applications' tables, such as Casbin's, don't count, so the steps run
next to them. On a database with only other tables, Flyway records a
baseline at version 0, below step 1, so that step 1 runs.
- `upgradeSchema()` is a plain Flyway run under the run lock: refuse
`AHEAD` and `UNVERSIONED_UC`, validate the history, migrate, then check
that the database ends `CURRENT` with a valid history. Retrying a run
that stopped part way comes in #2114.
- Every statement of step 1 skips what is already there (for example
`create table if not exists`), so that a later run can run it again
after a run that stopped in the middle. #2114 relies on this.
- The run lock covers the whole run, from classifying the database to
the last step; Flyway's own lock is taken per step. PostgreSQL uses
`pg_advisory_lock` on a fixed key, and MySQL uses `GET_LOCK` on a name
derived from the database name. H2 takes no lock, because one process
opens an H2 file; for the same reason H2 in server mode (`AUTO_SERVER`,
`jdbc:h2:tcp:`, `jdbc:h2:ssl:`) is refused. The lock lives on one
database session, so a pooler in transaction mode (PgBouncer `pool_mode
= transaction`) is not supported for the command. A failed lock release
closes the connection underneath the pooled one, which ends the session
and so releases the lock.
- The migrator opens its own pool of 4 connections (the lock's
connection, Flyway's two on PostgreSQL, and one for reading the schema)
and closes it at the end, so the server's pool size doesn't limit it.
- The database kind comes from the name that its JDBC driver reports,
not from the URL, so wrapping drivers (`jdbc:aws-wrapper:`,
`jdbc:p6spy:`) and pools set up with
`hibernate.hikari.dataSourceClassName` work.
- Metadata lookups pass the configured schema as an exact pattern
(`exactPattern`), since `_` and `%` are wildcards there and `uc_a` would
also match `ucxa`.
- `hibernate.default_schema` and `hibernate.default_catalog` are
refused, also from JVM system properties, because Flyway uses the
connection's schema. Set the schema in the JDBC URL instead. In this PR
only the command refuses them; #2117 adds the same refusal at server
start.
- `HibernateConfigurator` gains only helpers here: `hikariConfig()` (the
pool settings without opening a pool), `requireSchemaFromConnection()`,
and a `setupHibernateProperties()` overload that takes the file path.
- Build: the shaded jar merges Flyway's ServiceLoader file; other
service files are still dropped. The launcher classpath leaves out the
project's class directory, because the jar holds the same steps and
Flyway would find each one twice.
- `BaselineMatchesEntitiesTest` checks that the steps build the schema
that Hibernate builds from the entities. It runs in the normal suite
here; #2113 moves it behind `UC_TEST_MIGRATION_CHECKS=true` with the
other step checks.
- Test plumbing for the migrator tests: `@TempDatabase(empty = true)`,
`TestDatabase.dataSource()`, `newEmptyDatabase`, and H2 file databases.
The normal suite still builds its schema with Hibernate's `update`.
- `deployment.md`: the MySQL collation advice now changes the database
default together with every table, so that tables that later steps
create also get the binary collation.

### Test coverage

- `SchemaMigratorTest`: an empty database, one with only the
authorization rules table, one next to another application's tables, a
wrapping driver, a pool set up by data source class, a versioned
database with a pending step, reading only the configured schema, and
the refusals of a database without history, a newer schema, a failed
step, and H2 server mode. Run-lock tests on PostgreSQL and MySQL: two
runs on an empty database take turns, a refused lock, and a lock that is
not released.
- `SchemaGateTest`: the command sets up the configured database, and
refuses a missing `server.properties` or `hibernate.properties`, an
in-memory database and `hibernate.default_schema`.
- `OptionParserTest`: `--upgrade-schema`.
- Local runs: the runs listed above were on this branch before its last
merge of `main`, which brought in #1902, #2063, #2084, #2085, #2086 and
#2111. CI runs on the merged head.

### What moved out of this PR

Compared with the head at the last review (ae832c1):

- To #2117:
- Running the steps at server start. It is now a start-time check
(`requireCurrentSchema()`) that refuses a database not at this release's
schema; the command applies the steps.
- The Hibernate schema-action refusals in `HibernateConfigurator`
(`requireNoSchemaChanges`, `isSchemaAction`, `isNone`,
`withSchemaUpdatesOff`, the constructor checks, and
`setupHibernateProperties` turning `update` into `none`).
  - `etc/conf/hibernate.properties` without `update`.
- The removal of `hibernate.hbm2ddl.auto=update` from the Helm chart's
`_config.tpl`. This PR reverts ae832c1's last commit, so the chart is as
on `main`.
- Building every test database's schema with the steps:
`TemplateDatabases`, `TestDatabases.h2`/`runSteps`, `MySqlDatabases`,
`TestDatabase` with `hbm2ddl` set to `none`, `KeyMapperTest` with
`@TempDatabase`, and the `BaseAccessControlCRUDTest` comment.
- `HibernateConfiguratorTest.neverLetsHibernateChangeTheSchema` and
`refusesHibernatesOwnDefaultSchema`, and the start-time tests in
`SchemaGateTest`.
- To #2112:
- Adopting a 0.7.0 database as version 1 (`BASELINE_VERSION`,
`baselineFor`). It now adopts only on an exact schema match.
  - `ADOPTED_RELEASE` and `adoptsABaselineDatabase`.
- The real-release tests: `RealUpgradeTest`, `OldServer`, `DataSet`,
`TestServer`, `upgrade-tests.yml`, and the Vert.x test dependency.
  - `SchemaSnapshot`, which moves to the main code.
- To #2116: the migrated `etc/db/h2db.mv.db` and the
`PopulateTestDatabase` call that ran the steps. The sample database is
now built (`SampleDatabase`); this PR keeps `main`'s file.
- To #2113: the schema-change rules in `AGENTS.md`, `CODE_REVIEW.md` and
the AI reviewer's `REVIEW.md`.
- Removed, not moved:
- `BEFORE_BASELINE`, `BASELINE_TABLES`, `missingBaselineTables` and
`refusesADatabaseFromBeforeTheBaselineRelease`. #2112's schema
comparison replaces them; its refusal says that a database from before
0.7.0 must be started on a 0.7.0 server first.
- `NOT_UC` and `refusesADatabaseOfAnotherApplication`.
`setsUpADatabaseNextToAnotherApplicationsTables` replaces them: other
applications' tables are left alone.
- The H2 lock inside the JVM, `acceptsHibernatesNoneActionObject`, and
the schema-versions table in `upgrades.md`.
- Kept in this PR: `exactPattern` and the fix that reads only the
configured schema's tables (a80afaa), the H2 server-mode refusal, the
lock tests, `refusesADatabaseWithAFailedStep`, `migrate()` (now named
`upgradeSchema()`), the pool size (now 4 instead of 3), and step 1
written so that it can run again.

### Stack

Part 1 of 8 of the schema-upgrade stack:

1. #2045 [Server] Add the schema steps and a manual --upgrade-schema
command (this PR)
2. #2112 [Server] Adopt existing databases in --upgrade-schema
3. #2113 [Build] Check the schema steps on every pull request
4. #2114 [Server] Retry a schema upgrade that stopped part way
5. #2115 [Server] Add a read-only --check-schema command
6. #2116 [Build] Build the sample database instead of checking it in
7. #2117 [Server] Let only the schema steps change the schema
8. #2118 [Server] Add a temporary fallback to Hibernate schema updates

</details>

**PR Checklist**

- [x] 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.
- [x] If you've fixed a bug or added code that should be tested, add
tests!
- [x] If you've added or modified a feature, documentation in `docs` is
updated

This pull request and its description were written by Isaac.

---------

Signed-off-by: Shubham Bansal <[email protected]>
Co-authored-by: Isaac <[email protected]>
yili-db pushed a commit that referenced this pull request Nov 10, 2026
## 🥞 Stacked PR
Use this
[link](https://github.com/unitycatalog/unitycatalog/pull/2112/files/dfe03066ca3f748f42b916b6908d7ad23e50b7af..187be0b86367b2fe7cb3db852b33039bb534bbfe)
to review incremental changes.
-
[stack/uc-flyway-schema](#2045)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2045/files)]
-
[**stack/uc-upgrade-adopt**](#2112)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2112/files/dfe03066ca3f748f42b916b6908d7ad23e50b7af..187be0b86367b2fe7cb3db852b33039bb534bbfe)]
← _this PR_
-
[stack/uc-upgrade-merge-checks](#2113)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2113/files/b2982d514290d5a7cbb70010c31686d681f732d0..837c49999da9d021a385b5878dd5724f902b8ac0)]
-
[stack/uc-upgrade-retry](#2114)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2114/files/86b2b75709c1378fb7d199dabf453033849885c1..6aed4147e2b76bc45b076c5d1769a85461d9aaaf)]
-
[stack/uc-upgrade-check-schema](#2115)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2115/files/8ba3b07ae080f5d07518392679ddba696074afab..b7a8d07fbeae61d80e3518336ad7290b20cd6770)]
-
[stack/uc-sample-database-built](#2116)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2116/files/6a59493c75da317dfde80776cd29f6ae030eeabf..4221ea5224ceaf8b1122c0b00ba41eeaa6003840)]
-
[stack/uc-flyway-owns-schema](#2117)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2117/files/ccb5e69e8b53596d6f2925797970c9828505edba..b1e7a896aa2e48163e9a750265d99abf69c52371)]
-
[stack/uc-hibernate-fallback](#2118)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2118/files/861ca93eabac0bee2f40ebd4d0976dfd964929cf..0ed55964bab3e0d505fc330f41cdf00c48ff40b9)]

---------
`bin/start-uc-server --upgrade-schema` now adopts an existing database:
one that has Unity Catalog's tables but no schema history, such as a
0.7.0 database or one that a server of this release set up at start with
Hibernate. Before this PR, the command refused such a database.

### What you see

- A database whose schema is exactly the schema of version 1 (release
0.7.0) gets step 1 recorded without running it, and the later steps run.
- A database whose schema is exactly this release's schema gets every
step recorded without running it. A server of this release that set up a
new database at start leaves such a schema.
- Any other schema is refused, with one line for each difference from
version 1, and the hint that a database from before 0.7.0 must be
started on a 0.7.0 server first. For example, after someone added a
column by hand:

    ```console
The database has no schema history, and its schema is neither the schema
of version 1 nor that of version 2. It differs from version 1 in:
    unexpected column uc_catalogs.extra ...
    ```

- At the end of every run, the command compares the whole schema with
the schema that the steps build, and fails with the differences if they
don't match.
- `docs/server/upgrades.md` describes the baseline release, how to
repair a database from before 0.7.0 (two CHECK constraints differ; the
page gives the SQL for each database), and why not to start 0.7.0 again
on an upgraded database.

### What doesn't change yet

- Server start still runs Hibernate's `update`, and the command is still
optional and run by hand. #2117 switches that.

### Tests

Ran locally on H2: compiled all modules and their tests with checkstyle,
and ran the schema migration tests and the catalog SDK tests. The
real-release upgrade tests need `UC_TEST_UPGRADES=true` and did not run
locally; the new path-filtered workflow runs them in CI on H2,
PostgreSQL 18 and MySQL 8. CI also runs the full suite on all three
databases.

<details><summary><b>📐 Design notes &amp; details</b></summary>

### Design

- Adoption needs an exact match. A database that matches neither version
1 nor the latest version can't be told apart from one that someone
changed by hand, so the command refuses it and lists the differences
instead of guessing.
- To compare schemas, `SchemaSnapshot` moves from the tests to the
server, and renders what a one-statement step can change: CHECK
constraints by clause, MySQL enum values, column collations, numeric
scale, foreign key rules, descending index columns, and PostgreSQL's
partial indexes. It reads only Unity Catalog's `uc_*` tables, so the
test-only step's table is now `uc_test_only_step`.
- Each step has an effect file per database,
`schema-effects/<database>/V<n>.txt`, that lists what the step changes.
The schema of a version is the sum of the effect files up to it
(`SchemaMigrator.expected()`). The effect files ship in the server jar,
so the installed command compares without building a reference database.
- `MigrationStepRulesTest.eachStepHasItsEffectFile` checks each effect
file against what the step does on a new database. `build/sbt
updateSchemaDumps` rewrites the files on all three databases (PostgreSQL
and MySQL need Docker). This test lands here, not in #2113, because the
effect files and the rendering must exist before #2113 freezes merged
effect files.
- The record-without-running uses Flyway's `target` with
`skipExecutingMigrations`, so Flyway writes the history records itself.
- `adoptsADatabaseWithThisReleasesSchemaWithoutHistory` is a temporary
test: it drops the history table to stand in for a database that
Hibernate set up. #2118 removes it, because its hibernate-mode tests
cover the same case with a real Hibernate setup.
- `docs/server/upgrades.md` also says why not to start 0.7.0 on an
upgraded database: its Hibernate `update` narrows the column that step 2
widened, while the history still records step 2.

### Test coverage

- `SchemaMigratorTest`: adopts a version 1 database, adopts a database
with this release's schema, and refuses a version 1 database with an
extra column.
- `SchemaSnapshotTest`: tells apart schemas that differ only in each
rendered detail (some rows run only on PostgreSQL or MySQL), applies an
effect file with no changes, and counts duplicate checks once.
- `RealUpgradeTest` (`UC_TEST_UPGRADES=true`, workflow
`upgrade-tests.yml`): each release tag from 0.7.0 up to, but not
including, this build's version writes a data set, then this build
upgrades the database and reads every copy back. A database that 0.4.0
set up and 0.7.0 upgraded is refused, then repaired with the documented
SQL (`db/repair-0.7.0/*.sql`) and upgraded. This build's shaded jar sets
up an empty database with `--upgrade-schema` and serves it. `OldServer`,
`DataSet` and `TestServer` support it; the Vert.x test dependency is
there because older releases read Vert.x's version file at start.
- Local runs: the runs listed above were on this branch before its last
merge of `main`, which brought in #1902, #2063, #2084, #2085, #2086 and
#2111, and before #2045 added `refusesADatabaseWithAFailedStep`. CI runs
on the merged head.

### Stack

Part 2 of 8 of the schema-upgrade stack:

1. #2045 [Server] Add the schema steps and a manual --upgrade-schema
command
2. #2112 [Server] Adopt existing databases in --upgrade-schema (this PR)
3. #2113 [Build] Check the schema steps on every pull request
4. #2114 [Server] Retry a schema upgrade that stopped part way
5. #2115 [Server] Add a read-only --check-schema command
6. #2116 [Build] Build the sample database instead of checking it in
7. #2117 [Server] Let only the schema steps change the schema
8. #2118 [Server] Add a temporary fallback to Hibernate schema updates

</details>

**PR Checklist**

- [x] 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.
- [x] If you've fixed a bug or added code that should be tested, add
tests!
- [x] If you've added or modified a feature, documentation in `docs` is
updated

This pull request and its description were written by Isaac.

---------

Signed-off-by: Shubham Bansal <[email protected]>
Co-authored-by: Isaac <[email protected]>
Squashes unitycatalog#2113's own commits on top of main and the PRs below it in the
stack, so the PR stays under the DCO app's 250-commit limit. The tree is
the same as the merge of main into the branch (backup/uc-upgrade-merge-checks-merged-20261110).

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
@shba24
shba24 force-pushed the stack/uc-upgrade-merge-checks branch from fd734bf to c70c490 Compare November 10, 2026 23:12
@yili-db

yili-db commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

/review

@yili-db yili-db left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[AI Assisted] Thanks for this. The CI wiring looks safe and fails closed for missing or changed steps. Before merge, the rule checks need three fixes: the MySQL enum case in narrowing, a failing-input test for narrowing, and the isResolved() filter in the repeatable check with a test. The rest are follow-ups or nits.

Notes:

  • Description: "The server refuses a build that holds a repeatable step" applies only to --upgrade-schema. "rows already in a database can't make a step fail" overclaims given the MySQL enum case. The test notes say local runs predate the head's merge of main, so say which runs cover the head.
  • Test helpers: UpgradeTestUtils.migrateTo and sentStatements build Flyway without failOnMissingLocations(true) and validateMigrationNaming(true), which SchemaMigrator.flyway() sets. Test and production configs can drift.
  • AGENTS.md: "holds one SQL statement per step" applies to steps after the first. It also omits the branch-* rule and dev/check-migration-steps.sh.

Comment thread .github/workflows/migration-checks.yml Resolved
Comment thread dev/check-migration-steps.sh Resolved
Comment thread .github/workflows/migration-checks.yml Resolved
Comment thread dev/check-migration-steps.sh Resolved
- typeChangesWiden fails a MySQL step that drops an enum or set member
  (rows holding it would fail the change or lose the value), and a
  column line in an effect file that it can't read, instead of skipping
  it. A fixed-input table shows each column check failing and passing.
- The later-step refusal table covers each refusal, per database, and
  the index refusal names the index type (fulltext, spatial, unique).
- --upgrade-schema refuses only a repeatable step that this build has: a
  repeatable step that only the schema history records is refused by
  Flyway's history check, which names it correctly. Tests cover both.
- check-migration-steps.sh refuses a new step on a release branch before
  checking its number, so it gives the right advice.
- The migration checks job fails when either test class ran no tests or
  skipped them (testOnly passes when no class matches).
- AGENTS.md names the step-order script and the release-branch rule.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
@shba24

shba24 commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator Author

On the notes in your review body:

  • Description: fixed. The repeatable-step refusal is described as --upgrade-schema's, the "rows can't make a step fail" sentence now lists what the rules keep out (including the MySQL enum case), and the test notes say which runs cover 76ea533.
  • Test helpers: I left migrateTo and sentStatements as they are. The two options guard against a missing folder and a misnamed file. everyStepExistsForEveryDatabase checks the naming with STEP_FILE, and the helpers read fixed classpath folders that the tests already need, so I didn't find a defect the drift would let through.
  • AGENTS.md: it now names dev/check-migration-steps.sh and the branch-* rule. I kept "one SQL statement per step" as is: the first step is the merged 0.7.0 baseline, so every step a contributor adds holds one statement.

shba24 and others added 2 commits November 11, 2026 23:30
typeChangesWiden and its input table now call the same narrowedColumns,
so the table also covers the check that fails a column line the test
can't read.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
- droppedValues reads each line's members through one helper.
- The class Javadoc says a later step may create a plain index: a
  fulltext or spatial index is refused like a unique one.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
@shba24

shba24 commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator Author

/review

@shba24 shba24 reopened this Nov 12, 2026
@yili-db

yili-db commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

/review

@yili-db yili-db left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[AI Assisted] Thanks. The negative-scale fix (numeric(4,-2) to numeric(6,0) now passes, with the narrowing case still refused) and the effect-file change for several new steps are both right.

One blocker remains (inline): the NOT NULL ADD rule accepts a default that evaluates to NULL when it is spelled as an expression, such as DEFAULT (NULL) NOT NULL or DEFAULT NULL::integer NOT NULL. PostgreSQL rejects those on a table with rows, so the step can fail on a populated database.

Normal, still open:

  • The dev script has no tests of its refusal paths. The stale-base case was one wrong accept a test would have caught.
  • The PostgreSQL default comparison refuses an allowed widening of a column with a default, because a type change re-casts the default. Compare defaults for MySQL only.
  • The check passes when a non-empty step records no statements. Fail in that case too.
  • A type change on an indexed varchar widens what future inserts can hold. Please refuse it on indexed columns, or document the limit in the class Javadoc and AGENTS.md.
  • refusal() does not read the index method, so a non-btree USING is sized as a B-tree. Refuse non-btree methods in later steps.

Non-blocking: the workflow check's failure messages, the pure rule tests behind the gate, and the Flyway config in UpgradeTestUtils.

shba24 and others added 2 commits November 12, 2026 07:33
…n changes type

A NOT NULL column's default written as an expression, such as (NULL),
NULL::int or abs(NULL), passed the rule and failed on a table with rows.
A type change on an indexed column could outgrow the index: PostgreSQL
rebuilds it for int4 to int8, and later rows can hold the longer values.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
…he server's Flyway config

The CI step that checks the schema step tests ran now names the class
and the reason when it fails, and matches tests= in any attribute order.
UpgradeTestUtils.sentStatements runs the steps with SchemaMigrator's own
Flyway configuration, so the two can't drift apart.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
@shba24

shba24 commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks for the re-check. On the items in your 06:41 review and the AI review that we're leaving as they are:

  • The PostgreSQL default comparison on a widening: I couldn't reproduce a refusal. On PostgreSQL 18, I ran 10 type changes on columns with a default: smallint to int, int to bigint and to numeric, real to double precision, timestamp to timestamptz, numeric(5,2) to numeric(8,2), varchar to a longer varchar and to text, and char(3) to char(10). column_default in information_schema.columns stayed the same text after every one. pgjdbc reads COLUMN_DEF from pg_get_expr, the same source, so the effect file's default= doesn't change, and the widening passes. If you have a type pair where it does change, I'll add it.
  • Non-btree USING: on PostgreSQL 18, hash and SP-GiST indexes took a 9,600-character varchar value. BRIN failed only above 8,152 bytes, which the 2,704-byte B-tree estimate already refuses. A method with no default operator class for the type (GIN or GiST on varchar) fails on an empty database too, so CI catches it. Sizing every method as a B-tree only refuses some safe ones.
  • A step that records no statements: every step today is captured, and a step file Flyway skips is caught elsewhere. For example, a misnamed V3_drop.sql fails everyStepExistsForEveryDatabase, and Flyway's own filename check fails it too. So I'd add the extra check only if the way Flyway sends a step ever changes.
  • The pure rule tests behind UC_TEST_MIGRATION_CHECKS: the "All tests" rows on all three databases set it, and the check step fails if either class ran no tests or skipped any, so CI always runs them. Running them in a plain build/sbt test would mean a new test class, or a change to how @TempDatabase sets up the database, which I'd keep out of this PR.
  • Tests of dev/check-migration-steps.sh, and its message for a file that isn't a versioned step: as before, in a follow-up PR if they're required.
  • AI review notes:
    • A step file JSqlParser can't read: eachStepHasItsEffectFile still fails, so the only cost is the list of problems.
    • AGENTS.md wording: "one SQL statement per step" is the rule a contributor follows for a new step, and the class Javadoc covers the baseline and empty steps. "Check it in" refers to the effect file.
    • The HEAD^1 comments: they're accurate as written, since HEAD^1 is the base tip the merge starts from, and the script diffs from the merge base, as its header says.
    • CODE_REVIEW.md: it already has the checklist item for schema steps (new steps per database, no edits of merged ones), so naming the rules test there would add detail without correcting anything.
    • refuseIfUnsupported's second info() call: a refactor with no change in behavior.
    • Required status checks: AGENTS.md already names the "Require branches to be up to date before merging" setting.

The NULL-valued default and the indexed type change are fixed locally, together with the workflow messages and the shared Flyway configuration. I'll reply on those once they're pushed.

@shba24

shba24 commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator Author

Pushed the rest of your 06:41 review:

  • A type change on an indexed varchar (e1f8cac): confirmed on PostgreSQL 18. Widening an indexed varchar(100) to varchar(5000) ran, and a later insert of a 3,200-character value failed with "index row size 3216 exceeds btree version 4 maximum 2704". After each step, eachStepIsOneAllowedStatement now sizes every index on a column whose type the step changed, again with the new type, using the snapshot after the step. This also covers a case in the same class that I found while checking it. Widening int4 to int8 makes PostgreSQL rebuild the index, so a composite (varchar(673), int4) index whose rows already fit failed the step on a populated table with "index row size 2712 exceeds ... 2704". typeChangesKeepIndexEntriesShort has rows for both, plus a widening that still fits.
  • The workflow check's failure messages (8de2526): each failure now names the class and why (no report, no tests ran, or tests skipped), and the pattern matches tests= in any attribute position.
  • The Flyway config in UpgradeTestUtils (8de2526): sentStatements now runs the steps through SchemaMigrator.flyway(), so the recorder uses the server's own configuration.

The NULL-valued default is answered in its thread.

@shba24

shba24 commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator Author

One more note on how I checked these fixes. Beyond your examples, I swept the whole set of statements the rules allow: 165 probe statements, each run through the rule and on an empty and a populated table in PostgreSQL 18, MySQL 8.4 and H2. A probe the rule accepts that works on the empty table but fails on the populated one is a step CI couldn't catch.

  • Found, now fixed in e1f8cac: the NULL-valued defaults (16 probes over the three databases), and the int4 to int8 widening of a column in a near-limit index, which PostgreSQL rebuilds. Both are in the earlier replies.
  • Clean: CREATE TABLE (including IF NOT EXISTS and a foreign key to an existing table); CREATE INDEX with hash, BRIN, INCLUDE, MySQL prefixes and IF NOT EXISTS; and the other ALTER forms the rule refuses: foreign and primary keys, UNIQUE, CHECK, rename, drop, AUTO_INCREMENT, ENGINE and CONVERT TO. Defaults that error, such as (1/0) or a failing cast, either fail on an empty table too, so CI catches them, or were already refused.
  • Refused but safe: with literal-only defaults, the rule now also refuses some defaults that are safe, such as (0), now(), gen_random_uuid() and MySQL's (now()). No step uses a default yet. If one needs, say, a timestamp default, we'd allow that form explicitly. The sweep also shows some index options read as expressions and refused: DESC NULLS FIRST, an operator class and COLLATE.

The sweep checked one shape of populated rows per database, and H2 has no index size limit to hit, so the H2 part checks less.

@yili-db

yili-db commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

/review

…nges

Dropping NOT NULL on staging_location re-sized idx_staging_location,
which the 4-bytes-per-character estimate already puts over 2,704 bytes,
and refused a step that can't grow any index entry.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
@shba24

shba24 commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks for running the review again. On its findings:

  • A DROP NOT NULL on an indexed column is refused: good finding, and it's real. The re-size check I added in e1f8cac counted any change to a column's line, nullable= included. So ALTER TABLE uc_staging_tables ALTER COLUMN staging_location DROP NOT NULL re-sized idx_staging_location, which the 4-bytes-per-character estimate already puts at 8,208 bytes, and the step was refused on H2 and PostgreSQL. Fixed in 431a23e: an index is re-sized only when one of its columns changes type, size or scale, since NOT NULL, the default and the collation can't make a value longer. I ran both cases as a temporary step on H2 and PostgreSQL. The DROP NOT NULL now passes. Widening staging_location to varchar(4096) is still refused ("up to 16400 bytes"). Both are rows in typeChangesKeepIndexEntriesShort. The suggestion to compare the index's size before and after the step would miss the int4 to int8 rebuild, because both types round to 8 bytes in the estimate, so I kept the type check.
  • The PostgreSQL default changing after a widening: this doesn't reproduce. On PostgreSQL 18, I widened columns with a default 12 ways (varchar to text and to a longer varchar, int2 to int4 and int8, int4 to int8, numeric(5,2) to numeric(8,2) and numeric(8,3)), with string, empty, quoted, integer, negative, numeric, boolean and NULL defaults. pg_get_expr(adbin, adrelid), which pgjdbc reads for COLUMN_DEF, was the same text after every change; 'x'::character varying stays 'x'::character varying after TYPE text. I'd also keep the check on every database rather than MySQL only. On H2, the short form ALTER COLUMN c <type> drops the column's default (SET DATA TYPE keeps it), and this check is what catches that.
  • An effect file with no step: it can't change the server's expected schema, because SchemaMigrator.expected reads the effect files of resolved steps only. One describing a narrowing would fail typeChangesWiden, which reads every file. A copy of V2.txt saved as h2/V9.txt left the migrate tests passing (124/124), so I'm leaving it as is. AGENTS.md already names the "Require branches to be up to date before merging" setting for the step-order check.
  • The script tests, the empty statement list and the gated tests are the points from the earlier rounds that I replied to above.

Tests: the migrate package with the step checks on, at 431a23e: H2 126, PostgreSQL 18 134, MySQL 8 128, all passing.

@yili-db

yili-db commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

/review

@yili-db yili-db left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[AI Assisted] Approving. The DROP NOT NULL fix, the type check for int4 to int8, and the literal-default rules all check out.

Please take these in a follow-up PR:

  • Script tests for dev/check-migration-steps.sh: a throwaway-repo test covering edit, delete, rename, out-of-order number, V08, and the branch-* rule.
  • The empty statement capture in eachStepIsOneAllowedStatement: fail when a non-empty step file records no statements.

Non-blocking, as well:

  • @TempDatabase runs for each database-free parameterized case. Moving those cases to a class without the database would be faster and runnable locally.
  • The LITERAL pattern refuses quoted strings with spaces or quotes. A line in its Javadoc would say that is deliberate.
  • AGENTS.md and CODE_REVIEW.md: say how to enforce a uniqueness invariant on an existing table, and that entity changes must stay additive until #2117 lands.

Yi asked for the AI reviewer's rule change to be a separate PR: unitycatalog#2221.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
@shba24 shba24 closed this Nov 12, 2026
@shba24 shba24 reopened this Nov 12, 2026
@yili-db

yili-db commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

/review

@yili-db yili-db left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[AI Assisted] Follow-up to the approval: these join the follow-up list from the approval, not merge blockers.

Follow-ups: the serial-type gap and the empty statement capture, as inline comments.

@yili-db
yili-db merged commit fea3f18 into unitycatalog:main Nov 13, 2026
52 of 54 checks passed
yili-db pushed a commit that referenced this pull request Nov 13, 2026
…reviewer (#2221)

**Description**

Since #2045, a schema change ships as a new Flyway step for each
database. The `uc-domain-reviewer` agent still tells reviewers to check
that schema changes are additive under Hibernate's
`hbm2ddl.auto=update`. This removes that clause, so the agent only
points at `CODE_REVIEW.md` T11, the one place that states the
schema-change rule.

This was part of #2113, which updates T11 in `CODE_REVIEW.md` to
describe the Flyway steps. It is split out so the AI reviewer's own
rules change in a PR of their own.

<details>
<summary>📐 Design notes & details</summary>

- One line in
`.github/omnigent/reviewer/agents/uc-domain-reviewer/REVIEW.md`, item 3
("Persistence and schema portability"): the "additive-only (Hibernate
`hbm2ddl.auto=update`)" clause is removed; the rest of the item stays.
- The agent reads T11 for the rule, so it follows `CODE_REVIEW.md`
before and after #2113 merges.
- No code or test changes.

</details>

This pull request and its description were written by Isaac.

---------

Signed-off-by: Shubham Bansal <[email protected]>
Co-authored-by: Isaac <[email protected]>
yili-db added a commit that referenced this pull request Nov 16, 2026
## 🥞 Stacked PR
Use this
[link](https://github.com/unitycatalog/unitycatalog/pull/2171/files) to
review incremental changes.
-
[stack/s3compat_spec](#2170)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2170/files)]
[MERGED]
-
[**stack/s3compat_credentials**](#2171)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2171/files)]
← _this PR_
-
[stack/s3compat_vending](#2172)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2172/files/1c90863a0a328f0bec36232d3518c4fd65b9b6b6..7578d349b6dfd243ba229f147bf2046ece7ffc54)]
-
[stack/s3compat_hadoop_cli](#2173)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2173/files/7578d349b6dfd243ba229f147bf2046ece7ffc54..df3d6a134500556e4368352bffde8d4099c20478)]
-
[stack/s3compat_test_storage](#2174)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2174/files/df3d6a134500556e4368352bffde8d4099c20478..c43d8b01648e305615c27110fd892fd631924830)]
-
[stack/s3compat_helm_key](#2175)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2175/files/c43d8b01648e305615c27110fd892fd631924830..1262f181a18b28b9c856e1367cc6301b57bd4fbf)]
-
[stack/s3compat_credentials_text](#2169)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2169/files/1262f181a18b28b9c856e1367cc6301b57bd4fbf..b7b769051dd8fccbc7578458ad68f1bd642adf93)]

---------
Part of a stack adding experimental S3-compatible storage (MinIO, Ceph,
SeaweedFS, RustFS, Garage): #2170 (merged) to #2175, then #2169. Each PR
builds on the one before it; the files changed since the previous PR are
under the link above.

**Description of changes**

Experimental `s3_compatible` storage credentials, off by default.

- `server.s3-compatible-storage.enabled` (default `false`): with it off,
`s3_compatible` credentials cannot be created, an update cannot set
`s3_compatible` fields, and none is used to vend credentials; other
updates, reads and deletes still work
- `CredentialDAO` stores the credential; `secret_access_key` is
write-only, and `sts_endpoint` is stored only when set
- The secret is encrypted in the database with AES-256-GCM
(`CredentialSecretStore`, `EncryptedCredentialSecretStore`)
- key in `server.credential-encryption-key`, set through
`UC_SERVER_CREDENTIAL_ENCRYPTION_KEY`; without it, such credentials
cannot be created
  - each value is bound to its credential id and field
- at startup the server warns about credentials whose stored value it
cannot read, with the reason
- `CredentialRepository` checks type changes against the credential's
external locations
- The key is read only with `server.s3-compatible-storage.enabled=true`;
a malformed key then stops the server at startup
- `s3_endpoint` and `sts_endpoint` must be exactly
`http[s]://host[:port]` (port 1 to 65535; no path, not even a lone `/`,
no empty port, user info, query or fragment; `localhost` and private
hosts are fine), since they are returned to everyone who can read the
credential; error messages leave a rejected value out; no spec change
(the `api/` files match `main`)
- `updateCredential` refuses a request with both `aws_iam_role` and
`s3_compatible` before its transaction
- The v1 encryption binding (`storage credential <id> <field>`) is fixed
apart from error messages; a fixture checks an earlier value still reads
- The locked lookup by name returns the row the database matched, as
MySQL's case-insensitive default collation does for other lookups
- A stored value that does not decrypt keeps the failure as the cause,
for the logs; one too short to hold a nonce and a tag is refused before
decrypting; a stored credential that is not a JSON object is refused as
`INTERNAL`, naming the credential, as is one that does not bind to its
schema
- `ExternalLocationRepository` requires `s3://` URLs with a bucket (no
user info or port) for `s3_compatible` credentials, on create and
update; `NormalizedURL.isS3Path` is the one rule, which
`validateLocationsAreS3Paths` applies to each of a credential's location
URLs; a stored URL that no longer parses, as an earlier release may have
stored, is not an `s3://` path, so such a location can still be renamed,
commented or moved to another credential, and the parser's error, which
names the URL, never reaches the caller
- A non-forced `deleteCredential` locks the credential too, so a
location added meanwhile blocks the delete
- The race tests wait until the competing change waits for the row lock
(`awaitLockWait`: `pg_stat_activity`, `performance_schema.data_locks` or
H2's `INFORMATION_SCHEMA.SESSIONS`, showing what the database reports
when no session waits), so each fails without the lock it checks
- `assume_role.sts_region` must be letters, digits, '.', '_' and '-'; a
create with neither credential type returns `INVALID_ARGUMENT`
- credential updates and location changes lock the credential row on its
first read in the transaction (`getCredentialDAOForUpdate`; a location
update locks the location first), so a type change and a location change
on one credential cannot race, and the lock never lands on a copy read
earlier without it
- rows are locked by id and name with main's `RepositoryUtils.lockByKey`
helpers (`getForUpdateByName` reads the id first), so a rename that
commits meanwhile finds nothing: names have no index on MySQL, where a
locking read by name locked a range and could deadlock with a concurrent
create; these transactions run at READ COMMITTED, so reads after the
lock see what was committed while it waited; a lock failure returns
`UNAVAILABLE`, to retry
- a location update checks its URL against the credential's committed
type whether or not the URL changes
- Schema step `V3__s3_compatible_credential_type`, with its effect files
- PostgreSQL replaces the `credential_type` CHECK in one statement:
`DROP CONSTRAINT k, ADD CONSTRAINT k CHECK (credential_type IN (...))`,
where `k` is the column's CHECK, `uc_credentials_credential_type_check`
- `MigrationStepRulesTest` (from #2113) allows that change: on
PostgreSQL a step may replace a column's CHECK of its values with one
that keeps every value, so rows already there pass it. Until now its
rules said adding a Java enum constant on PostgreSQL was not supported
yet. `AGENTS.md` says so too.
- CLI (the key options keep their names): `--s3_access_key_id`,
`--s3_secret_access_key`, `--s3_endpoint`, `--s3_sts_endpoint`,
`--s3_role_arn` and `--s3_sts_region` on credential create and update

Known: on MySQL, a stored credential must fit `tinytext` (255 bytes)
until #2169 widens the column; an `s3_compatible` credential with
`assume_role` and real endpoints usually does not (`TODO(#2169)` on
`CredentialDAO.setS3Compatible`).

The spec text from #2170 also describes vending, which #2172 adds; the
stack is meant to land together.

Compatibility: additive and behind the flag; `aws_iam_role` credentials
are unchanged.

Tests: credential, external location, repository, DAO and secret store
tests (SDK and CLI), and the schema tests, with
`UC_TEST_MIGRATION_CHECKS=true`, on H2, PostgreSQL 18 and MySQL 8.

**PR Checklist**

- [x] 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.
- [x] 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

This pull request and its description were written by Isaac.

Signed-off-by: Yi Li <[email protected]>
Co-authored-by: Isaac <[email protected]>
yili-db pushed a commit that referenced this pull request Nov 17, 2026
## 🥞 Stacked PR
Use this
[link](https://github.com/unitycatalog/unitycatalog/pull/2114/files) to
review incremental changes.
-
[stack/uc-flyway-schema](#2045)
(merged)
-
[stack/uc-upgrade-adopt](#2112)
(merged)
-
[stack/uc-upgrade-merge-checks](#2113)
(merged)
-
[**stack/uc-upgrade-retry**](#2114)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2114/files)]
← _this PR_
-
[stack/uc-upgrade-check-schema](#2115)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2115/files/d4c1b003a0e576debded4b91a28b256d02507f67..0028bc22bb2e6ebd02e11048a2d7560ad023be19)]
-
[stack/uc-sample-database-built](#2116)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2116/files/0028bc22bb2e6ebd02e11048a2d7560ad023be19..727e167d1206b36e7bbb1e30fb18bd5ee0d4be7f)]
-
[stack/uc-flyway-owns-schema](#2117)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2117/files/727e167d1206b36e7bbb1e30fb18bd5ee0d4be7f..0a120a3c682986c926845a85ad249df1720e5d4c)]
-
[stack/uc-hibernate-fallback](#2118)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2118/files/0a120a3c682986c926845a85ad249df1720e5d4c..97bc44b5dfb75eb27fdddc33db6ea208680234ac)]

---------
`bin/start-uc-server --upgrade-schema` can now be run again after a run
that stopped part way, for example after a crash, a lost connection, or
a step that failed. Before this PR, it refused a database with a failed
step, and you had to restore the backup.

### What you see

- The command applies the pending steps one at a time. Before each step,
it compares the whole schema with the schema before and after that step:
  - If the schema is the one before the step, the step runs.
- If the schema already has the step's change, the step is recorded
without running. That is the schema after the step (a run that stopped
before Flyway recorded it) or after a later step (a database without
schema history at a later step, such as one that Hibernate updated).
- Otherwise the command stops, changes nothing more, and lists the
differences from the nearer of the two versions.
- Step 1 also runs again after an earlier run of it stopped part way,
because its statements skip what is already there.
- If the schema history is otherwise valid, the record of a step that
failed (H2 and MySQL keep one) is deleted once the schema check accepts
the step, so that the step is tried again. A run that the schema check
or Flyway's history check refuses keeps the record, and the command
stops.
- `docs/server/upgrades.md` says to fix the cause that the command names
and run the same command again.

For example, on MySQL, if the database connection drops after step 2
changed the column but before Flyway recorded step 2, the next run logs
`Recorded schema step 2 without running it: the database already has its
change`.

### What doesn't change yet

- Server start still runs Hibernate's `update`, and the command is still
optional and run by hand. #2117 switches that.

### Tests

Ran locally on H2 with `UC_TEST_MIGRATION_CHECKS=true`: compiled all
modules and their tests with checkstyle, and ran the schema migration
tests, including the sweep that stops a run at every statement of every
step, and the catalog SDK tests. The same sweep ran locally on
PostgreSQL 18 and MySQL 8 at the top of the stack (#2118). CI runs it in
the "All tests" rows, which set `UC_TEST_MIGRATION_CHECKS`.

<details><summary><b>📐 Design notes &amp; details</b></summary>

### Design

- The retry decision (`runs()`) uses the effect files from #2112: the
schema of version `n-1` means run step `n`, the schema of version `n`
means record it. This works because #2113 keeps each later step to one
statement, so a step is either fully there or not there at all. Step 1
is the exception: it has many statements, so a partial step 1 under an
existing history table runs again.
- Recording uses Flyway's `target(step)` with `skipExecutingMigrations`,
one step per Flyway call. After each call, the command checks that
exactly that one step was recorded, and stops otherwise.
- During an upgrade, the history check ignores Flyway's failed-step
error, and only that one, so that the record can be deleted. Any other
error, such as an edited step, still stops the run and keeps the record.
- Failed records are deleted with plain SQL on a connection that commits
by itself, after the history is validated. The caller's pool may not
commit by itself, and a rollback would keep the record. The connection's
previous auto-commit setting is put back afterwards, as it is for the
run lock's connection. Flyway's `repair` would also rewrite the other
records' checksums, which would hide an edited step.
- The refusal message names the nearer version (by the size of the
difference list), so the operator sees the shorter, more useful list. It
adds the pre-0.7.0 hint only when the database has no history.
- `refusesADatabaseWithAFailedStep` (from #2045) is removed: a failed
step is now tried again. `runsAgainAFailedStepOnTheConfiguredPool` and
`keepsTheRecordOfAFailedStepWhenTheHistoryIsRefused` cover both sides.

### Test coverage

- `SchemaMigratorTest`: runs a failed step again, keeps a failed record
when the history is refused, runs again after a run that stopped in a
step (before and after its record), runs step 1 again after it stopped
part way, and refuses a step when the schema is neither before nor after
it.
- `everyStepRunsAgainAfterARunThatStoppedInIt`
(`UC_TEST_MIGRATION_CHECKS=true`): for every step of this build, stops a
run at each of its statements and between its last statement and its
history record, then checks that the next run ends with a new install's
schema. `failingAt` and the watcher helpers in `UpgradeTestUtils` make
the chosen statement or history record fail.
- The sweep in `SchemaMigratorTest` runs with
`UC_TEST_MIGRATION_CHECKS=true`, which the "All tests" rows of Unit
Tests set.
- Local runs: the runs listed above were on this branch before its last
merge of `main`, which brought in #1902, #2063, #2084, #2085, #2086 and
#2111. CI runs on the merged head.

### Stack

Part 4 of 8 of the schema-upgrade stack:

1. #2045 [Server] Add the schema steps and a manual --upgrade-schema
command
2. #2112 [Server] Adopt existing databases in --upgrade-schema
3. #2113 [Build] Check the schema steps on every pull request
4. #2114 [Server] Retry a schema upgrade that stopped part way (this PR)
5. #2115 [Server] Add a read-only --check-schema command
6. #2116 [Build] Build the sample database instead of checking it in
7. #2117 [Server] Let only the schema steps change the schema
8. #2118 [Server] Add a temporary fallback to Hibernate schema updates

</details>

**PR Checklist**

- [x] 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.
- [x] If you've fixed a bug or added code that should be tested, add
tests!
- [x] If you've added or modified a feature, documentation in `docs` is
updated

This pull request and its description were written by Isaac.

---------

Signed-off-by: Shubham Bansal <[email protected]>
Co-authored-by: Isaac <[email protected]>
yili-db pushed a commit that referenced this pull request Nov 18, 2026
## 🥞 Stacked PR
Use this
[link](https://github.com/unitycatalog/unitycatalog/pull/2115/files/d4c1b003a0e576debded4b91a28b256d02507f67..0028bc22bb2e6ebd02e11048a2d7560ad023be19)
to review incremental changes.
-
[stack/uc-flyway-schema](#2045)
(merged)
-
[stack/uc-upgrade-adopt](#2112)
(merged)
-
[stack/uc-upgrade-merge-checks](#2113)
(merged)
-
[stack/uc-upgrade-retry](#2114)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2114/files)]
-
[**stack/uc-upgrade-check-schema**](#2115)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2115/files/d4c1b003a0e576debded4b91a28b256d02507f67..0028bc22bb2e6ebd02e11048a2d7560ad023be19)]
← _this PR_
-
[stack/uc-sample-database-built](#2116)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2116/files/0028bc22bb2e6ebd02e11048a2d7560ad023be19..727e167d1206b36e7bbb1e30fb18bd5ee0d4be7f)]
-
[stack/uc-flyway-owns-schema](#2117)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2117/files/727e167d1206b36e7bbb1e30fb18bd5ee0d4be7f..0a120a3c682986c926845a85ad249df1720e5d4c)]
-
[stack/uc-hibernate-fallback](#2118)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2118/files/0a120a3c682986c926845a85ad249df1720e5d4c..97bc44b5dfb75eb27fdddc33db6ea208680234ac)]

---------
This PR adds `bin/start-uc-server --check-schema`, which tells you
whether `--upgrade-schema` would go through, without changing the
database. Run it before an upgrade to find problems early; on PostgreSQL
and MySQL, the old servers can keep serving while it runs.

### What you see

- `--check-schema` prints the database's schema version, what
`--upgrade-schema` would do with each pending step (run it, or record it
without running because its change is already there), and whether the
upgrade would go through. It runs the same checks on the schema as the
upgrade.
- It exits with 0 when the upgrade would go through, and with 1 and the
reasons otherwise.
- It changes nothing and takes no run lock, so on PostgreSQL and MySQL
you can run it with the new release while the old servers still run. H2
lets only one process open the database file, so on H2 stop the server
first.
- It refuses the same configurations as `--upgrade-schema`, such as a
missing configuration file or an in-memory database.
- You can pass only one of `--check-schema` and `--upgrade-schema`.
- `docs/server/upgrades.md` adds the check as a step of the upgrade
procedure.

For example, on an empty database:

```console
$ bin/start-uc-server --check-schema
Database schema version: none; this release ends at 3.
Pending steps:
  1 baseline 0 7: runs
  2 widen function param type json: runs
  3 s3 compatible credential type: runs
The schema allows the upgrade: --upgrade-schema would run the steps above.
```

### What doesn't change yet

- Server start still runs Hibernate's `update`, and both commands are
optional and run by hand. #2117 switches that.

### Tests

Ran locally on H2 with `UC_TEST_MIGRATION_CHECKS=true`: compiled all
modules and their tests with checkstyle, and ran the schema migration
tests, the option parser tests and the catalog SDK tests. CI runs the
full suite on H2, PostgreSQL 18 and MySQL 8.

<details><summary><b>📐 Design notes &amp; details</b></summary>

### Design

- `checkSchema()` walks the pending steps with the same decision as the
upgrade (`runs()` from #2114), but against the expected schema after
each step instead of a real run, then compares the result with the
schema of the last version. A step that failed counts as pending,
because the upgrade deletes its record first.
- It takes no run lock, so a run in progress can change the answer. That
trade-off lets it run next to serving servers on PostgreSQL and MySQL.
- `runCommand(boolean upgrade, ...)` serves both options, so the
configuration refusals are shared. In `OptionParser`, an `OptionGroup`
makes the two options exclusive.
- The upgrade's refusal of a step that was not recorded as its run's
only change now points at `--check-schema` to see the database's state.

### Test coverage

- `SchemaMigratorTest`: checks an empty database without changing it, a
versioned database with a pending step, a failed step as one to run
again (the failed record stays), and a database whose schema differs
(exit 1).
- `SchemaGateTest`: both commands refuse each bad configuration.
- `OptionParserTest`: parses each command, and refuses both at once.
- Local runs: the runs listed above were on this branch before its last
merge of `main`, which brought in #1902, #2063, #2084, #2085, #2086 and
#2111. CI runs on the merged head.

### Stack

Part 5 of 8 of the schema-upgrade stack:

1. #2045 [Server] Add the schema steps and a manual --upgrade-schema
command
2. #2112 [Server] Adopt existing databases in --upgrade-schema
3. #2113 [Build] Check the schema steps on every pull request
4. #2114 [Server] Retry a schema upgrade that stopped part way
5. #2115 [Server] Add a read-only --check-schema command (this PR)
6. #2116 [Build] Build the sample database instead of checking it in
7. #2117 [Server] Let only the schema steps change the schema
8. #2118 [Server] Add a temporary fallback to Hibernate schema updates

</details>

**PR Checklist**

- [x] 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.
- [x] If you've fixed a bug or added code that should be tested, add
tests!
- [x] If you've added or modified a feature, documentation in `docs` is
updated

This pull request and its description were written by Isaac.

---------

Signed-off-by: Shubham Bansal <[email protected]>
Co-authored-by: Isaac <[email protected]>
yili-db pushed a commit that referenced this pull request Nov 19, 2026
## 🥞 Stacked PR
#2115 has merged, so this PR's own changes are its whole diff against
`main`.
-
[stack/uc-flyway-schema](#2045)
(merged)
-
[stack/uc-upgrade-adopt](#2112)
(merged)
-
[stack/uc-upgrade-merge-checks](#2113)
(merged)
-
[stack/uc-upgrade-retry](#2114)
(merged)
-
[stack/uc-upgrade-check-schema](#2115)
(merged)
-
[**stack/uc-sample-database-built**](#2116)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2116/files)]
← _this PR_
-
[stack/uc-flyway-owns-schema](#2117)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2117/files/727e167d1206b36e7bbb1e30fb18bd5ee0d4be7f..0a120a3c682986c926845a85ad249df1720e5d4c)]
-
[stack/uc-hibernate-fallback](#2118)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2118/files/0a120a3c682986c926845a85ad249df1720e5d4c..97bc44b5dfb75eb27fdddc33db6ea208680234ac)]

---------
The quickstart's sample database, `etc/db/h2db.mv.db`, is no longer
checked in to git. The build makes it from the schema steps and the
sample data, so it always has this release's schema and schema history.

### What you see

- `build/sbt buildSampleDatabase` builds `etc/db/h2db.mv.db`, and keeps
a file that exists. To reset the sample data, move the file aside and
build again (the quickstart says how). The folder must be on a file
system that supports hard links.
- In a source checkout, `bin/start-uc-server` builds the sample database
when it is missing, but only for a command line that starts the server:
one with only the port options, in any spelling the option parser takes
and with a value it accepts as a port number. `--check-schema`,
`--upgrade-schema`, `--version`, `--help` and their short or abbreviated
forms don't build it. It builds the file whatever database the
configuration uses, and starts the server even when that build fails.
- The tarball and the Docker image ship a sample database that their own
build makes, never a local copy that a local server may have changed.
- The build ignores the environment's `UC_SERVER_*` variables, so a
deployment's settings don't change or break the sample database.
- The Python client's tests build the sample database before they start
the server.
- `tests/test_tutorial.py` refuses to run when `etc/db/h2db.mv.db`
exists, since git no longer shows whether a local copy changed.
- The quickstart now says `build/sbt package buildSampleDatabase`.

### Compatibility

- `etc/db/h2db.mv.db` is no longer in git. If you changed the sample
database in a checkout from before this change, copy it somewhere safe
before you update the checkout: git deletes the file, or refuses to
update while it has local changes.

### What doesn't change yet

- Server start still runs Hibernate's `update`. On the built sample
database, it changes nothing, because the steps build the same schema.
#2117 switches start to a schema check.

### Tests

- `SampleDatabaseTest`:
- builds the sample database, runs `--check-schema` on it and checks the
sample catalog, tables, volumes and functions;
- refuses an existing file and leaves its bytes unchanged; two builds at
the same time leave one file, and the other build fails because the file
exists;
- builds with a deployment environment variable set that would make any
other server configuration invalid;
- checks `bin/start-uc-server` against the real `OptionParser` for each
kind of command line (the port options in their spellings, signed,
overflowing and non-numeric values, schema commands, `--version`,
`--help`, unknown options, `--`), that the launcher knows every option
the parser has, and that a failed build still starts the server.
- Ran locally on H2. `build/sbt buildSampleDatabase` run twice keeps the
file. The tarball was not built locally, and no enabled CI job builds
it. In CI, the Helm chart tests build the Docker image, the Python
client tests run, and the full suite runs on H2, PostgreSQL 18 and MySQL
8.

<details><summary><b>📐 Design notes &amp; details</b></summary>

### Design

- A checked-in database would need a manual rebuild for every new schema
step. Building it from the steps keeps it at this release's schema, with
a schema history that `--upgrade-schema` and #2117's start check accept.
- `SampleDatabase` (formerly the test class `PopulateTestDatabase`)
lives in its own sbt project, `examples/sample-database`, with a
compile-scope dependency on the server. Neither the server jar nor the
server's test classes hold it.
- It sets up the schema with the schema steps, as `--upgrade-schema`
does, then writes the sample data through the repositories. It builds
into a file next to the target and links it into place only when it is
done (a hard link never replaces a file that exists), so a failed or
concurrent build leaves no partial file that `bin/start-uc-server` would
take for the sample database.
- The tarball task builds a fresh copy under `target/` and replaces any
`etc/db/h2db.*` it copied. The Dockerfile's build stage does not copy
`etc/`; it runs `buildSampleDatabase`, and the runtime image takes
`etc/` from the build context (`.dockerignore` leaves out
`etc/db/h2db.*` and `etc/db/building-*`) and the built database from the
build stage.
- `bin/start-uc-server` builds the file only when `build/sbt` is there
and executable, and the command line starts the server (`starts_server`,
a copy of the parser's rules for the port options). The Docker image
holds the server's sources but not `build/sbt`, and a volume mounted
over `etc/db` stays empty.
- The `populateTestDB` sbt task is gone; `buildSampleDatabase` replaces
it.

### Stack

Part 6 of 8 of the schema-upgrade stack:

1. #2045 [Server] Add the schema steps and a manual --upgrade-schema
command
2. #2112 [Server] Adopt existing databases in --upgrade-schema
3. #2113 [Build] Check the schema steps on every pull request
4. #2114 [Server] Retry a schema upgrade that stopped part way
5. #2115 [Server] Add a read-only --check-schema command
6. #2116 [Build] Build the sample database instead of checking it in
(this PR)
7. #2117 [Server] Let only the schema steps change the schema
8. #2118 [Server] Add a temporary fallback to Hibernate schema updates

</details>

**PR Checklist**

- [x] 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.
- [x] If you've fixed a bug or added code that should be tested, add
tests!
- [x] If you've added or modified a feature, documentation in `docs` is
updated

This pull request and its description were written by Isaac.

---------

Signed-off-by: Shubham Bansal <[email protected]>
Co-authored-by: Isaac <[email protected]>
yili-db pushed a commit that referenced this pull request Nov 19, 2026
## 🥞 Stacked PR
Use this
[link](https://github.com/unitycatalog/unitycatalog/pull/2117/files/727e167d1206b36e7bbb1e30fb18bd5ee0d4be7f..0a120a3c682986c926845a85ad249df1720e5d4c)
to review incremental changes.
-
[stack/uc-flyway-schema](#2045)
(merged)
-
[stack/uc-upgrade-adopt](#2112)
(merged)
-
[stack/uc-upgrade-merge-checks](#2113)
(merged)
-
[stack/uc-upgrade-retry](#2114)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2114/files)]
-
[stack/uc-upgrade-check-schema](#2115)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2115/files/d4c1b003a0e576debded4b91a28b256d02507f67..0028bc22bb2e6ebd02e11048a2d7560ad023be19)]
-
[stack/uc-sample-database-built](#2116)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2116/files/0028bc22bb2e6ebd02e11048a2d7560ad023be19..727e167d1206b36e7bbb1e30fb18bd5ee0d4be7f)]
-
[**stack/uc-flyway-owns-schema**](#2117)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2117/files/727e167d1206b36e7bbb1e30fb18bd5ee0d4be7f..0a120a3c682986c926845a85ad249df1720e5d4c)]
← _this PR_
-
[stack/uc-hibernate-fallback](#2118)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2118/files/0a120a3c682986c926845a85ad249df1720e5d4c..97bc44b5dfb75eb27fdddc33db6ea208680234ac)]

---------
This PR makes the schema steps the only way Unity Catalog's schema
changes. The server no longer lets Hibernate build or change the schema
at start. Instead, it checks that the database is at this release's
schema, and refuses to start otherwise. The Helm chart runs
`--upgrade-schema` in an init container before each server pod starts.

### What you see

- Before the first start on a new database, run `bin/start-uc-server
--upgrade-schema` once. A source checkout's quickstart sample database
needs none. An in-memory database (`server.env=test`, or a named
`jdbc:h2:mem:<name>;DB_CLOSE_DELAY=-1` URL; unnamed in-memory URLs are
refused) is the exception: it lasts only as long as the server, so the
server sets it up itself, and `--upgrade-schema` succeeds on it without
doing anything.
- The server refuses to start on a database that is not at this
release's last step, or whose schema history fails Flyway's check (a
failed step, also a newer release's, or an edited or missing step). The
start refuses what `--check-schema` and `--upgrade-schema` refuse. The
message says what to do: the command to run, or, for a history the
commands refuse too, to run the release that applied the steps or
restore the backup. For example:

    ```console
The database schema is at version none, and this release needs version
2. Stop every server of the previous release, run bin/start-uc-server
--upgrade-schema with this release, then start the server.
    ```

- To upgrade from 0.7.0, stop the servers, back up the database, run
`--upgrade-schema` with the new release, then start it. See
`docs/server/upgrades.md`.
- `etc/conf/hibernate.properties` no longer sets
`hibernate.hbm2ddl.auto=update`. If your file still sets
`hibernate.hbm2ddl.auto` (to `update` or another value), the server sets
it to `none` and logs a warning. Any other schema action setting that
isn't `none` (`jakarta.persistence.schema-generation.database.action`,
its `javax.` form, or a suffixed form such as
`hibernate.hbm2ddl.auto.orm`) makes the start refuse, also when it comes
from a JVM system property or a `hibernate.properties` on the classpath.
- The start also refuses what `--upgrade-schema` refuses:
`hibernate.default_schema` or `hibernate.default_catalog`, H2 in server
mode, and a database other than H2, PostgreSQL and MySQL. Before,
Hibernate built a schema on any database.
- With authorization enabled, the authorization library runs `CREATE
TABLE IF NOT EXISTS casbin_rule` at every start, so the database user
keeps the CREATE privilege.
- A server that sets up its own test database (`server.env=test`, or no
`hibernate.properties`) gives it a name of its own and shuts it down
when it closes, so a later server in the same JVM starts on an empty
one. A database the configuration names is left as it is.
- Helm chart:
- An `upgrade-schema` init container runs `bin/start-uc-server
--upgrade-schema` in each server pod, after
`server.deployment.extraInitContainers`. For an in-memory database it
does nothing.
- The update strategy defaults to `Recreate`, so all old server pods
stop before new ones start, which an upgrade with schema steps needs.
The server is unavailable during an upgrade until the new pods are
ready. `RollingUpdate` can still be set, for an upgrade without schema
steps.
- `server.deployment.replicaCount` above 1 with the file database fails
to render.
  - The chart no longer renders `hibernate.hbm2ddl.auto=update`.
- `docs/server/helm.md` covers backups, the init container's log,
database proxies as native sidecars, scaling to 0 and restoring the
backup before `helm rollback`, and why not to use `helm upgrade
--atomic`.

### Compatibility

- A database not at this release's schema no longer starts: run
`bin/start-uc-server --upgrade-schema` first.
- `hibernate.hbm2ddl.auto` in `hibernate.properties` is ignored with a
warning. Any other schema action setting that isn't `none` is refused,
also from a JVM system property or a classpath `hibernate.properties`.
- `hibernate.default_schema` and `hibernate.default_catalog` are
refused: put the schema in the JDBC URL.
- The Helm chart's update strategy defaults to `Recreate` (a values file
that sets `RollingUpdate` keeps it), and the file database allows one
replica.

### What doesn't change yet

- There is no way back to Hibernate's `update` yet. #2118 adds
`server.schema-management=hibernate` as a temporary fallback.
- The Helm upgrade test covers H2 and PostgreSQL. Once the MySQL Helm PR
#2119 lands, it should cover MySQL too.

### Tests

- `SchemaMigratorTest`: the start refuses a history the commands refuse
(a newer release's failed step, edited and missing steps), with advice
that gets past each refusal.
- `SchemaGateTest`: the start and both commands on a missing H2 file, an
empty database, and each in-memory URL form (`mem:`, `.`, `memFS:`,
`memLZF:`, `nioMemFS:`, `nioMemLZF:`), where `--upgrade-schema` succeeds
without doing anything.
- `UnityCatalogServerTest`: a server built from its own configuration
refuses a mistyped H2 path without creating a file; two servers with
their own test databases don't share one, and a closed one's database is
gone; a configured in-memory database, and a file database behind a
leftover in-memory URL setting, are left alone; an injected database
keeps its tables.
- `HibernateConfiguratorTest`: a schema action set as a JVM system
property is refused (in a child JVM).
- Helm render checks: `Recreate` renders by default and `RollingUpdate`
when set, `replicaCount` above 1 is rejected for the file database, and
the init container renders for an in-memory configuration and mounts the
configuration and database volume.
- Ran on H2, PostgreSQL 18 and MySQL 8 locally: the start-gate,
migrator, server and configurator tests and the schema migration tests;
the full server suite on H2. CI runs the full suite on all three
databases and the Helm install and upgrade tests.

<details><summary><b>📐 Design notes &amp; details</b></summary>

### Design

- Start runs `requireCurrentSchema()` on the migrator's own small pool:
the recorded version must be this build's last step, and Flyway's
validation must pass. It takes no run lock and changes nothing. A
database newer than this release gets the "newer than this release"
refusal; an empty one gets "The database has no Unity Catalog schema
yet".
- `HibernateConfigurator` refuses every schema action but `none`
(`hibernate.hbm2ddl.auto`,
`jakarta.persistence.schema-generation.database.action` and its `javax.`
form, also with a contributor suffix such as
`hibernate.hbm2ddl.auto.orm`) before the pool or the session factory
exists, and reads JVM system properties and a classpath
`hibernate.properties` the way Hibernate does. `validate` is refused
too. Only the server's own `etc/conf/hibernate.properties` gets the
lenient path (its schema action turned to `none` with a warning, which
also overrides a JVM system property for it), so an old file keeps
working.
- The whole test suite now builds its schemas with the steps:
`TemplateDatabases`, `TestDatabases`, `MySqlDatabases` and
`TestDatabase` (with `hbm2ddl` set to `none`), plus `KeyMapperTest` and
`BaseAccessControlCRUDTest`. `BaselineMatchesEntitiesTest` keeps
checking that the steps match the entities.
- Helm: the init container shares the server container's volume mounts
through a new `unitycatalog.server.volumeMounts` helper. It runs after
`extraInitContainers`, so a database proxy run there as a native sidecar
(`restartPolicy: Always`) is up first; a proxy in `extraContainers`
starts only after the init containers. The update strategy defaults to
`Recreate`, also when an upgrade with `--reuse-values` carries no value
from an older release: an upgrade with schema steps changes the database
schema, so the old servers must stop before the new ones start.
`RollingUpdate` can be set for an upgrade without schema steps.
- Helm CI: the "Upgrade from the base chart" step builds the server
image from the pull request's base (`HEAD^1`), installs the base chart
with it, creates a catalog, runs `helm upgrade` to this chart and image,
and checks the catalog is still there. It runs on H2 and on PostgreSQL
with two replicas, whose init containers both run the upgrade under the
run lock. The workflow now also triggers on changes to the migration
code, the steps, the effect files, `UnityCatalogServer.java`,
`OptionParser.java` and `bin/start-uc-server`.
- Helm: the init container's environment has only what
`--upgrade-schema` needs to reach the database: the database password as
`UC_HIBERNATE_CONNECTION_PASSWORD` (the way #2080 passes it to the
server) and, on MySQL, the driver mount and `JDK_JAVA_OPTIONS` from
#2119, through the new `unitycatalog.server.dbPasswordEnv` and
`unitycatalog.server.mysqlDriverEnv` helpers. Its environment has no
storage credentials. It shares the server container's volume mounts,
including the GCS key files, through `unitycatalog.server.volumeMounts`,
so the two can't drift apart. The server container keeps one `env` list.
- `docs/server/deployment.md` drops the manual `ALTER` statements for
`uc_properties.property_value`: new installs get the wide column from
the steps, and a pre-0.7.0 database gets it from starting 0.7.0 once.

### Test coverage

-
`SchemaMigratorTest.serverRefusesToStartOnADatabaseNotAtThisReleasesSchema`:
a pending step, a failed step, an edited step, a step missing below the
recorded one, and a newer schema.
- `SchemaGateTest`: refuses to start on a database that is not set up,
and sets up an in-memory database at start.
- `HibernateConfiguratorTest`: `neverLetsHibernateChangeTheSchema`,
`refusesASchemaActionOtherThanNone` (each setting form), and
`refusesHibernatesOwnDefaultSchema`.
- Local runs: the runs listed above were on this branch before its last
merge of `main`, which brought in #1902, #2063, #2084, #2085, #2086 and
#2111. CI runs on the merged head.

### Stack

Part 7 of 8 of the schema-upgrade stack:

1. #2045 [Server] Add the schema steps and a manual --upgrade-schema
command
2. #2112 [Server] Adopt existing databases in --upgrade-schema
3. #2113 [Build] Check the schema steps on every pull request
4. #2114 [Server] Retry a schema upgrade that stopped part way
5. #2115 [Server] Add a read-only --check-schema command
6. #2116 [Build] Build the sample database instead of checking it in
7. #2117 [Server] Let only the schema steps change the schema (this PR)
8. #2118 [Server] Add a temporary fallback to Hibernate schema updates

</details>

**PR Checklist**

- [x] 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.
- [x] If you've fixed a bug or added code that should be tested, add
tests!
- [x] If you've added or modified a feature, documentation in `docs` is
updated

This pull request and its description were written by Isaac.

---------

Signed-off-by: Shubham Bansal <[email protected]>
Co-authored-by: Isaac <[email protected]>
yili-db pushed a commit that referenced this pull request Nov 20, 2026
**PR Checklist**

- [x] 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.
- [x] 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 (not needed, bug fix only)

**Description of changes**

Creating a function with a long parameter type fails with a 500:

```
POST /api/2.1/unity-catalog/functions  (a parameter with a 352 character STRUCT type_text)
500 INTERNAL ... Value too long for column "TYPE_TEXT CHARACTER VARYING(255)"
```

The same happens for a long `full_data_type`, a parameter comment over
255 characters, or a long parameter default. The unitycatalog-ai client
sends each docstring argument description as the parameter comment, so a
function with a detailed docstring can't be registered. Table columns
don't have this problem because `uc_columns` stores `type_text` as a
large text column and `comment` in 65535 characters.

#2013 fixed the same thing for `uc_function_params.type_json`. This PR
widens the remaining columns the same way, with one single-statement
step per column for H2, MySQL and PostgreSQL, each with its own effect
file:

- V5 `uc_function_params.type_text` and V6 `uc_functions.full_data_type`
use the width of `uc_columns.type_text` (16777215, so CLOB, mediumtext
or text)
- V7 `uc_function_params.comment`, V8 `parameter_default` and V9
`uc_schemas.comment` use 65536, `mediumtext` on MySQL. A long schema
comment failed with the same 500 while a table comment of the same
length worked
- V10 `uc_volumes.comment` uses 65536, the volume comment's `maxLength`
in `api/all.yaml`, so every comment the API accepts fits. On MySQL that
is `mediumtext`, which also holds 65536 multi-byte characters, since
MySQL counts `text` in bytes

MySQL counts `text` in bytes, so 65535 there holds fewer characters when
they are multi-byte, while H2 and PostgreSQL count characters. All four
widened comment and default columns are therefore 65536 on H2 and
PostgreSQL and `mediumtext` on MySQL, which holds 65536 multi-byte
characters. Hibernate maps a length above 65535 to `mediumtext` on
MySQL, so the entities use 65536 and `BaselineMatchesEntitiesTest`
agrees on all three databases. The existing table, column and model
comments are still `text` on MySQL, which is a separate change.

Each step only changes a column type. On H2 the steps use the plain
`ALTER COLUMN c <type>` form, which keeps the NOT NULL on `type_text`
(the effect file shows `nullable=NO` before and after), so no step says
NOT NULL on H2 or PostgreSQL. The `comment` columns are quoted because
JSqlParser, which the step rules in #2113 use, reads COMMENT as a
keyword and can't parse the unquoted statement. Catalog, credential and
external location comments are still 255 and can follow in a separate
PR.

**Testing**

`SdkFunctionCRUDTest.testFunctionWithLongTypesAndComments` creates a
function with a long STRUCT parameter type, a long return parameter
type, a long return type, and distinct long parameter comment and
default values, and reads them back. `BaseSchemaCRUDTest` and
`BaseVolumeCRUDTest` now update the comment to a 300 character one and
read it back. `BaseVolumeCRUDTest` and `BaseSchemaCRUDTest` then update
the comment to 65536 `é` characters, over 65535 bytes in UTF-8, and read
it back, and `SdkFunctionCRUDTest` now uses 65536 `é` characters for the
parameter comment and 65536 `ü` characters for the default. With the
volume or schema column left at 65535 the update fails with a 500 on H2.
The MySQL and PostgreSQL runs in CI cover the multi-byte case there.
These fail with the 500 before the fix and pass after it on H2.
`MigrationStepRulesTest`, `BaselineMatchesEntitiesTest` and
`SchemaMigratorTest` pass on H2. I also ran the `MigrationStepRulesTest`
from #2113 against these steps with `UC_TEST_MIGRATION_CHECKS=true`, and
all 11 tests pass on H2, including `eachStepIsOneAllowedStatement` and
`typeChangesWiden`. I wrote the MySQL and PostgreSQL effect files by
hand from the existing ones because I couldn't run Docker locally, so
the upgrade tests in CI check those.

Main is merged in. It added steps V3 and V4, so these steps are now V5
to V10. #2234 also adds V5 to V10, so whichever of the two merges second
gets renumbered above the other.

---------

Signed-off-by: Maha Rana Yadavalli <[email protected]>
Co-authored-by: Maha Rana Yadavalli <[email protected]>
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.

2 participants