From 642589db4d839378eaa7a9a1e3fe8eaae7b15b7e Mon Sep 17 00:00:00 2001 From: TriplEight Date: Sun, 22 Mar 2026 15:21:45 +0100 Subject: [PATCH] ci: fix mysql migration and diesel schema overwrite in integration tests Two bugs exposed by the integration test workflow: 1. MySQL migration 2022-07-27: groups_users and collections_groups used UNIQUE instead of PRIMARY KEY. Diesel requires primary keys on all tables for schema introspection (print-schema). PostgreSQL and SQLite migrations already used PRIMARY KEY correctly. 2. diesel.toml has [print_schema] configured, so \`diesel migration run\` rewrites src/db/schema.rs with backend-specific types after running. This corrupted the checked-in schema before cargo test could compile, causing E0277 CompatibleType errors for every query. Fix by restoring the file immediately after each migration run. --- .github/workflows/integration-test.yml | 12 ++++++++++-- .../mysql/2022-07-27-110000_add_group_support/up.sql | 6 +++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index 5c9b31c8..e9314851 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -87,8 +87,13 @@ jobs: # Verify that all PostgreSQL migrations apply cleanly to a fresh database. # This catches broken SQL before it reaches a production deployment. + # Restore src/db/schema.rs after running: diesel.toml has [print_schema] + # configured, so diesel rewrites the file with backend-specific types after + # migration. The checked-in schema.rs must be restored before compiling. - name: Run PostgreSQL migrations - run: diesel migration run --migration-dir migrations/postgresql + run: | + diesel migration run --migration-dir migrations/postgresql + git checkout -- src/db/schema.rs # Run the test suite with a live PostgreSQL instance available. # Existing tests are unit tests (no DB access), but DATABASE_URL is set @@ -152,8 +157,11 @@ jobs: run: cargo install diesel_cli --no-default-features --features mysql # Verify that all MySQL migrations apply cleanly to a fresh database. + # Restore src/db/schema.rs for the same reason as the PostgreSQL job above. - name: Run MySQL migrations - run: diesel migration run --migration-dir migrations/mysql + run: | + diesel migration run --migration-dir migrations/mysql + git checkout -- src/db/schema.rs # Run the test suite with a live MySQL instance available. - name: Run tests (mysql) diff --git a/migrations/mysql/2022-07-27-110000_add_group_support/up.sql b/migrations/mysql/2022-07-27-110000_add_group_support/up.sql index 6d40638a..b46dc0a8 100644 --- a/migrations/mysql/2022-07-27-110000_add_group_support/up.sql +++ b/migrations/mysql/2022-07-27-110000_add_group_support/up.sql @@ -11,7 +11,7 @@ CREATE TABLE `groups` ( CREATE TABLE groups_users ( groups_uuid CHAR(36) NOT NULL REFERENCES `groups` (uuid), users_organizations_uuid VARCHAR(36) NOT NULL REFERENCES users_organizations (uuid), - UNIQUE (groups_uuid, users_organizations_uuid) + PRIMARY KEY (groups_uuid, users_organizations_uuid) ); CREATE TABLE collections_groups ( @@ -19,5 +19,5 @@ CREATE TABLE collections_groups ( groups_uuid CHAR(36) NOT NULL REFERENCES `groups` (uuid), read_only BOOLEAN NOT NULL, hide_passwords BOOLEAN NOT NULL, - UNIQUE (collections_uuid, groups_uuid) -); \ No newline at end of file + PRIMARY KEY (collections_uuid, groups_uuid) +);