Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
c70c490
[Build] Check the schema steps on every pull request
shba24 Nov 10, 2026
76ea533
[Build] Tighten the schema step rules after review
shba24 Nov 11, 2026
6d7c5d1
[Build] Check effect files and fixed inputs through one column check
shba24 Nov 11, 2026
659f7f4
[Build] Simplify the enum member check and correct the index rule doc
shba24 Nov 11, 2026
0159c18
[Build] Catch unbounded numeric and dropped MySQL defaults in the ste…
shba24 Nov 11, 2026
37ba0ad
[Build] Refuse a later-step index on a text column too long to index
shba24 Nov 12, 2026
779528a
[Build] Size the whole index key, and refuse types the rule can't bound
shba24 Nov 12, 2026
a4f5da3
[Build] Count the index entry's headers in the key-size rule
shba24 Nov 12, 2026
c1e1e27
[Build] Run the schema step checks in the all-tests rows
shba24 Nov 12, 2026
c77fd19
[Build] Close the index-size and enum gaps Yi found in the step rules
shba24 Nov 12, 2026
79620ca
[Build] Refuse a later-step partial index
shba24 Nov 12, 2026
e33ad77
[Build] Let updateSchemaDumps write the effect files of several new s…
shba24 Nov 12, 2026
070da79
[Build] Read a PostgreSQL negative numeric scale as negative in the s…
shba24 Nov 12, 2026
e1f8cac
[Build] Allow only literal defaults, and re-size an index whose colum…
shba24 Nov 12, 2026
8de2526
[Build] Say why the schema step check failed, and record steps with t…
shba24 Nov 12, 2026
431a23e
[Build] Re-size an index only when a column's type, size or scale cha…
shba24 Nov 12, 2026
a395b2c
[Build] Move the domain reviewer's Flyway line to its own PR
shba24 Nov 12, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ jobs:
${{ matrix.validation-mode == 'spark-tests' && 'Spark tests' || 'All tests' }}
(Spark ${{ matrix.spark-version }}${{ matrix.delta-version != '' && format(', Delta {0}', matrix.delta-version) || '' }}${{ matrix.test-database && format(', {0}', matrix.test-database) || '' }})
continue-on-error: ${{ matrix.non-blocking || false }}
# The all-tests rows (H2, PostgreSQL 18, MySQL 8) also run the schema step checks, which run only
# with this set.
env:
UC_TEST_MIGRATION_CHECKS: ${{ matrix.validation-mode == 'all-tests' && 'true' || 'false' }}
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -111,3 +115,40 @@ jobs:
# to H2 here; an empty value would skip the license check and fail the database lookup.
test-database: ${{ matrix.test-database || 'H2' }}
use-spark-source-cache: ${{ matrix.spark-source-build }}
- name: Check that the schema step checks ran
if: matrix.validation-mode == 'all-tests'
# Both classes skip their tests without UC_TEST_MIGRATION_CHECKS, so each class's report must
# show tests and none skipped.
run: |
for class in MigrationStepRulesTest BaselineMatchesEntitiesTest; do
report="$(find server/target -name "TEST-io.unitycatalog.server.migrate.$class.xml" | head -n 1)"
if [ -z "$report" ]; then
echo "::error::$class did not run: no test report"
exit 1
fi
if ! grep -qE '<testsuite[^>]* tests="[1-9]' "$report"; then
echo "::error::$class ran no tests"
exit 1
fi
if ! grep -qE '<testsuite[^>]* skipped="0"' "$report"; then
echo "::error::$class skipped tests; is UC_TEST_MIGRATION_CHECKS set?"
exit 1
fi
done

# Databases already ran the merged schema steps, so a pull request may only add steps, and none
# on a release branch.
migration-steps:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
name: Merged migration steps unchanged
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
with:
# HEAD^1, the first parent of the merge commit, is the code this change starts from.
fetch-depth: 2
- name: Check merged migration steps
env:
# The base branch name tells the script whether the pull request targets a release branch.
BASE_BRANCH: ${{ github.base_ref }}
run: dev/check-migration-steps.sh "$(git rev-parse HEAD^1)" "$BASE_BRANCH"
7 changes: 6 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,12 @@ Conventions:

- **Read paths pass `readOnly = true`; write paths pass `false`.** A path that needs a specific isolation level passes it explicitly; it applies to that transaction only, and Hikari resets it when the connection returns to the pool.
- **DAOs extend `IdentifiableDAO`** (UUID id plus name), are annotated `@Entity @Table(name = "uc_...")`, use Lombok (`@Getter @Setter @SuperBuilder @NoArgsConstructor @AllArgsConstructor`), and expose static `from(XInfo)` and instance `toXInfo()` converters. Keep business logic out of DAOs.
- **Backends:** H2 by default (embedded, file-based). MySQL and PostgreSQL are supported for a persistent deployment, configured in `etc/conf/hibernate.properties` (point at your database and add the JDBC driver); see `docs/server/deployment.md`. Hibernate is configured in `persist/utils/HibernateConfigurator`. Tests run on H2 by default; `build/sbt -J-Xmx6G testPostgres18` or `testMySQL8` (or `UC_TEST_DATABASE=POSTGRES_18` / `MYSQL_8`) runs them on PostgreSQL 18 or MySQL 8.4 in Docker, each test on its own database, and fails rather than skips when Docker is not available. When adding schema, keep any index or column change safe across a server restart on an existing database, and portable across all three backends.
- **Backends:** H2 by default (embedded, file-based). MySQL and PostgreSQL are supported for a persistent deployment, configured in `etc/conf/hibernate.properties` (point at your database and add the JDBC driver); see `docs/server/deployment.md`. Hibernate is configured in `persist/utils/HibernateConfigurator`. Tests run on H2 by default; `build/sbt -J-Xmx6G testPostgres18` or `testMySQL8` (or `UC_TEST_DATABASE=POSTGRES_18` / `MYSQL_8`) runs them on PostgreSQL 18 or MySQL 8.4 in Docker, each test on its own database, and fails rather than skips when Docker is not available. When adding schema, keep any index or column change safe across a server restart on an existing database, and portable across H2, MySQL and PostgreSQL. A schema change:
- is a new Flyway step for each database under `server/src/main/resources/db/migration/{h2,postgresql,mysql}/`, numbered after the last one; never edit a merged step or its effect file;
- is checked for step order against the PR's base by `dev/check-migration-steps.sh`, so two open PRs can each pass with steps out of order: just before a PR that adds a step merges, rebase it or merge main into it so its step is numbered above every merged one (or turn on the branch protection "Require branches to be up to date before merging"); a release branch (`branch-*`) takes no new steps, so add them on main;
- holds one SQL statement per step; `MigrationStepRulesTest` (run with `UC_TEST_MIGRATION_CHECKS=true`) holds the rules for what a step may change (adding a Java enum constant is not supported yet on PostgreSQL, where it means replacing a CHECK constraint);
- comes with an effect file per database, `server/src/main/resources/schema-effects/{h2,postgresql,mysql}/V<n>.txt`, written by `build/sbt updateSchemaDumps` (PostgreSQL and MySQL need Docker), which only writes them: run the tests with `UC_TEST_MIGRATION_CHECKS=true` afterwards to check them; check it in with the step;
- matches the entities: `BaselineMatchesEntitiesTest` (also run with `UC_TEST_MIGRATION_CHECKS=true`) compares the schema the steps build with the one Hibernate builds from the entities.
- **Enforce invariants at the database level** (unique constraints) rather than only in code, where duplicate creation or races are possible.

## Error handling
Expand Down
4 changes: 2 additions & 2 deletions CODE_REVIEW.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ A fast pre-push scan; each item is expanded in the themes below.
□ api/all.yaml updated and `build/sbt generate` run; no hand-edited generated code?
□ [Component] PR title prefix present? (DCO sign-off is expected but overridable, not a blocker.)
□ Authz: narrowest privilege; create-checks-parent / mutate-checks-self; fails closed?
□ Schema change additive-only (hbm2ddl.auto=update) and portable across H2/MySQL/PostgreSQL?
□ Schema change shipped as new Flyway steps per database (db/migration/<db>/), no edits of merged steps, and portable across H2/MySQL/PostgreSQL?
□ Connector changes hold across the Spark/Delta matrix; all distribution artifacts version-matched?
□ Managed AND external table paths covered; optional deps (e.g. delta-spark) not assumed present?
□ API errors matched by structured code, rendered in the right dialect (UC REST vs Delta/Iceberg)?
Expand Down Expand Up @@ -148,7 +148,7 @@ Each theme lists the concrete checks and the **principle** behind it (so you can
- Use `Option` over sentinel/magic values ("how do you distinguish default 0 from not-measured?").
- Watch perf/complexity regressions and concurrency (synchronized/volatile; static state reset between tests).
- **Release what you acquire**: `stop()` must release everything `init()` or the constructor created (don't leave a session factory unclosed).
- **Persistence schema changes are additive and restart-safe** on an existing database (Hibernate runs `hbm2ddl.auto=update`): add columns or indexes, never drop or retype, and keep it portable across H2, MySQL, and PostgreSQL.
- **Persistence schema changes ship as new Flyway steps** for each database under `server/src/main/resources/db/migration/<db>/` (H2, MySQL, PostgreSQL), never as edits of merged steps, and portable across all three; `BaselineMatchesEntitiesTest` (run with `UC_TEST_MIGRATION_CHECKS=true`) and `RealUpgradeTest` (run with `UC_TEST_UPGRADES=true`) check them.
- **Avoid N+1 DB lookups in list operations** (batch or precompute rather than a lookup per result), and don't buffer a whole HTTP response for a check that can run synchronously.
- **Hold across the Spark/Delta version matrix**: fail fast on incompatible versions rather than failing silently; connector code in the shared tree must compile across the whole cross-build (verify each version and state what you validated); version-match every distribution channel; and keep shims to the differences only, not byte-identical copies.

Expand Down
2 changes: 2 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,8 @@ lazy val server = (project in file("server"))
"javax.xml.bind" % "jaxb-api" % "2.3.1" % Test,
// The upgrade tests run older releases, whose servers read Vert.x's version file at start.
"io.vertx" % "vertx-core" % "4.5.34" % Test,
// Reads the schema steps' SQL in MigrationStepRulesTest (Apache-2.0 or LGPL-2.1; tests only).
"com.github.jsqlparser" % "jsqlparser" % "5.4" % Test,

// Integration testing
"org.testcontainers" % "junit-jupiter" % testcontainersVersion % Test,
Expand Down
76 changes: 76 additions & 0 deletions dev/check-migration-steps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/env bash
#
# Fails when HEAD edits, deletes or renames a schema migration step, or a step's effect file, that
# exists on <base-ref>. Databases already ran those steps, and the effect files tell
# --upgrade-schema what they did, so a change to the schema must be a new step.
# Fails when a new step's version is not above every step on <base-ref> for that database:
# databases already past it would never run it (Flyway refuses such a step).
# Also fails on any new step when <base-branch> is a release branch (branch-*): the step's number
# could clash with a different step on main, and the next upgrade would break.
#
# Usage: dev/check-migration-steps.sh <base-ref> [<base-branch>]
# Needs the history back to the merge base of <base-ref> and HEAD (CI passes HEAD^1, the merge
# commit's first parent, so fetch-depth: 2 is enough). CI passes the pull request's base branch
# name as <base-branch>.

set -euo pipefail
Comment thread
shba24 marked this conversation as resolved.
Resolved
Comment thread
shba24 marked this conversation as resolved.
Resolved
# The paths below are relative to the repository root.
cd "$(git rev-parse --show-toplevel)"

if [[ $# -lt 1 || $# -gt 2 ]]; then
echo "Usage: $0 <base-ref> [<base-branch>]" >&2
exit 2
fi
base_branch=${2:-}

steps_dir=server/src/main/resources/db/migration
effects_dir=server/src/main/resources/schema-effects

if ! merge_base=$(git merge-base "$1" HEAD); then
echo "No merge base between $1 and HEAD; fetch more history." >&2
exit 2
fi

changed=$(git diff --diff-filter=MDRT --name-status "$merge_base" HEAD -- "$steps_dir" "$effects_dir")
if [[ -n "$changed" ]]; then
echo "These merged migration steps or effect files changed since $1:" >&2
echo "$changed" >&2
echo "Merged steps can't change; add a new step under $steps_dir/<db>/ instead." >&2
exit 1
fi
echo "No merged migration step or effect file changed since $1."

# A release branch takes no new steps at all, so say that before checking their numbers.
added=$(git diff --diff-filter=A --name-only "$merge_base" HEAD -- "$steps_dir" "$effects_dir")
if [[ -n "$added" && "$base_branch" == branch-* ]]; then
echo "These migration steps are new on the release branch $base_branch:" >&2
echo "$added" >&2
echo "Release branches take no new steps; add the step on main." >&2
exit 1
fi

# The version of a step file name V<version>__<description>.sql.
version_of() { basename "$1" | sed -n 's/^V\([0-9]*\)__.*/\1/p'; }

added_steps=$(git diff --diff-filter=A --name-only "$merge_base" HEAD -- "$steps_dir")
for step in $added_steps; do
folder=$(dirname "$step")
highest=$(git ls-tree --name-only "$1" -- "$folder/" \
| while read -r f; do version_of "$f"; done | sort -n | tail -n 1)
version=$(version_of "$step")
if [[ ! "$version" =~ ^[0-9]+$ ]]; then
echo "The new step $step has a version that is not a whole number." >&2
echo "Name it V<number>__<description>.sql." >&2
exit 1
fi
# 10# keeps bash from reading a leading zero (V08) as octal.
version=$((10#$version))
if [[ -n "$highest" ]]; then
highest=$((10#$highest))
fi
if [[ -n "$highest" && "$version" -le "$highest" ]]; then
echo "The new step $step is not above step $highest, the highest on $1." >&2
echo "Renumber it above every merged step." >&2
Comment thread
shba24 marked this conversation as resolved.
Resolved
exit 1
fi
done
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,8 @@ private static String laterSchemaWithUcTables(Connection connection) throws SQLE
}
}

private FluentConfiguration flyway() {
/** This build's Flyway configuration; tests add callbacks to it. */
FluentConfiguration flyway() {
return Flyway.configure()
.dataSource(dataSource)
.locations(locations)
Expand Down Expand Up @@ -565,8 +566,26 @@ SchemaSnapshot expected(String version) {
return schema;
}

/** Throws for a database that {@link #upgradeSchema()} must not change. */
/**
* Throws for a database that {@link #upgradeSchema()} must not change, or a build with a
* repeatable step.
*/
private void refuseIfUnsupported(SchemaState state) {
String repeatable =
Arrays.stream(flyway().load().info().all())
// Only this build's steps: the history may record steps of another build.
.filter(
m ->
m.getState().isResolved()
&& m.getVersion() == null
&& !m.getType().isSynthetic())
.map(MigrationInfo::getScript)
.findFirst()
.orElse(null);
if (repeatable != null) {
throw new IllegalStateException(
"This build has a repeatable schema step, which is not supported: " + repeatable);
}
String refusal =
switch (state) {
case AHEAD ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@
import org.hibernate.cfg.JdbcSettings;
import org.hibernate.cfg.SchemaToolingSettings;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;

/**
* The steps build the schema Hibernate builds from the entities, so Hibernate's update at server
* start changes nothing on a database that the steps built.
* start changes nothing on a database that the steps built. Runs with {@code
* UC_TEST_MIGRATION_CHECKS=true}.
*/
@EnabledIfEnvironmentVariable(named = "UC_TEST_MIGRATION_CHECKS", matches = "true")
public class BaselineMatchesEntitiesTest {

@TempDatabase(empty = true)
Expand Down
Loading
Loading