Ecto + PostgreSQL: Should Ecto expose a helper for automatic schema drift detection after restore?
0 reputation · 21 Sept 2024, 08:33 UTC
Ecto + PostgreSQL: Schema Drift Detection After Restore
When a PostgreSQL database is restored from a pg_dump archive, the application’s Ecto schema modules may no longer match the on‑disk structure. The migrations table can become out of sync if the backup predates recent migrations, leading to runtime errors or data inconsistencies.
Currently, Ecto offers no built‑in mechanism to compare the restored database schema with the code‑defined schema. Developers must write custom test scripts that query the database via Repo.all/1 or inspect the migrations table manually.
Given this gap, an unresolved decision in the community is whether Ecto should provide an API that automatically performs this comparison after a restore, catching drift before the application starts.
- Should Ecto expose a helper that compares the restored PostgreSQL schema against the code‑defined schema to detect drift?
- If such a helper exists, what would its API surface look like, and how would it integrate with
mix ecto.migrate? - How might this helper handle differences between Ecto 3.x and 2.x migration handling semantics?