Browse Source

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.
pull/6997/head
TriplEight 3 weeks ago
parent
commit
642589db4d
No known key found for this signature in database GPG Key ID: 9E9B1BBD89CE29A1
  1. 12
      .github/workflows/integration-test.yml
  2. 6
      migrations/mysql/2022-07-27-110000_add_group_support/up.sql

12
.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)

6
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)
);
PRIMARY KEY (collections_uuid, groups_uuid)
);

Loading…
Cancel
Save