Skip to content

Database schema and Phase 8 migrations disagree on pilot foreign keys #17

Description

@danielmarv

Summary

On staging at 635adc7, a database created from the checked-in migration history is immediately reported as drifted by prisma migrate dev. The Phase 8 migrations create foreign keys that packages/database/prisma/schema.prisma does not declare.

Reproduction

  1. Create an empty PostgreSQL database.
  2. Set DATABASE_URL to it.
  3. Run pnpm db:generate && pnpm db:migrate.
  4. All ten checked-in migrations apply. Prisma then prompts for another migration because the resulting database differs from the current schema.

Unsafe generated diff

The generated reconciliation migration would drop 28 foreign keys and one index, including constraints on Pilot, PilotParticipant, PilotSupportCase, PilotFarmerImport, PilotDecision, PilotConfiguration, and TrainingAssignment. It was not retained because that would weaken referential integrity merely to silence drift.

The pre-existing local clycites database also contains 20260723160925_phase_9_enterprise_dashboard from origin/Daniel-Dev, which is not in staging history. That separate branch database was preserved; an isolated clycites_wp1_staging database reproduced the Phase 8 schema mismatch independently.

Provenance

git blame and migration history point to commit 3cb62a2 (feat(pilot): add bootstrap and preflight scripts for pilot management) as introducing both the Phase 8 schema and migrations in their inconsistent state.

Required resolution

Reconcile schema.prisma with the intended Phase 8 referential-integrity contract. Prefer restoring the missing Prisma relation declarations if the migration constraints are authoritative. Add a fresh-database CI check that applies all migrations and then verifies zero schema drift. Do not resolve this with db push, migrate reset against shared data, or a migration that drops the constraints without an explicit architecture decision.

Blocks

Blocks WP1 hardening baseline closeout because the brief requires migration-clean database initialization before integration tests.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions