ci: add integration test workflow with live PostgreSQL and MySQL #28

Open
opened 2026-04-05 20:29:01 +02:00 by MrUnknownDE · 0 comments
Owner

Originally created by @TriplEight on 3/22/2026

Two jobs - one per db - each spinning up a service container

  1. diesel migration run --migration-dir migrations/ Verifies every migration applies cleanly to a fresh instance. This is the primary gap: a broken migration would otherwise only surface on production deployment.

  2. cargo test --features with DATABASE_URL set Builds and runs the test suite against the live engine. Existing tests are unit-level (no DB access), but DATABASE_URL is wired in so any future integration tests work without further infrastructure changes.

Service containers: postgres:16, mysql:8.4 (utf8mb4).
diesel CLI binary is cached keyed on Cargo.lock hash to avoid recompiling it on every run.
Triggers on the same path set as build.yml (src/, migrations/, Cargo.*, rust-toolchain.toml).

Two bugs exposed by the integration test workflow

  1. MySQL migration: 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.

add MySQL migration to fix missing primary keys on group tables

groups_users and collections_groups were created with UNIQUE constraints instead of PRIMARY KEY in the 2022-07-27 migration. Add a new migration that promotes the unique indexes to primary keys.

MySQL auto-names a UNIQUE constraint after its first column, so the index names to drop are 'groups_uuid' and 'collections_uuid' respectively.

*Originally created by @TriplEight on 3/22/2026* ## Two jobs - one per db - each spinning up a service container 1. diesel migration run --migration-dir migrations/<db> Verifies every migration applies cleanly to a fresh instance. This is the primary gap: a broken migration would otherwise only surface on production deployment. 2. cargo test --features <db> with DATABASE_URL set Builds and runs the test suite against the live engine. Existing tests are unit-level (no DB access), but DATABASE_URL is wired in so any future integration tests work without further infrastructure changes. Service containers: postgres:16, mysql:8.4 (utf8mb4). diesel CLI binary is cached keyed on Cargo.lock hash to avoid recompiling it on every run. Triggers on the same path set as build.yml (src/**, migrations/**, Cargo.*, rust-toolchain.toml). ## Two bugs exposed by the integration test workflow 1. MySQL migration: 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. ## add MySQL migration to fix missing primary keys on group tables groups_users and collections_groups were created with UNIQUE constraints instead of PRIMARY KEY in the 2022-07-27 migration. Add a new migration that promotes the unique indexes to primary keys. MySQL auto-names a UNIQUE constraint after its first column, so the index names to drop are 'groups_uuid' and 'collections_uuid' respectively.
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/vaultwarden#28