Repository navigation
Restore a db/schema.rb that loads into a fresh database - #57
Merged
Merged
Conversation
The schema committed in 7f502da was dumped from the research database the app shares a server with, so it carried things the app doesn't use and a fresh database can't create: PostGIS and other extensions, the topology schema, enums, public.barcode with a nanoid() default, and 21 other tables (for example oban_jobs, areas, locations). Test databases and new machines couldn't be set up from it. This is the schema as it was before that commit, regenerated from a scratch database (load the old schema, run the migrations, dump), so it holds only the app's tables and needs no extensions beyond plpgsql. The full suite passes on a database loaded from it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016AR3uoZS1uCC8hXmojk3K7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
db/schema.rbcommitted in 7f502da can't be loaded into a fresh database, so test databases and new machines can't be set up from it. It was dumped from the research database the app shares a server with, so it carries things the app doesn't use and a fresh database can't create:postgis,postgis_raster,topology.postgis_topology,postgres_fdw,citext,fuzzystrmatch,pgcrypto,uuid-ossp,btree_gist), thetopologyschema and three enumspublic.barcode, whose id defaults to ananoid(13)functionoban_jobs,areas,locations,farm_fields0,analysis_labs,users_tokens,spatial_ref_sys)This restores the schema as it was before that commit, regenerated from a scratch database (load the old schema, confirm no migration is pending, dump), so it holds only the app's 85 tables and needs no extension beyond
plpgsql. The regenerated file is byte-for-byte the pre-7f502dacd schema.Why not trim the newer file instead
I tried it (removing the extras from the 7f502da file), and it loads after one more fix (
protocolsuses a legacymethocols_id_seqsequence that a fresh database lacks). But 53 specs then fail. The research database has foreign keys the schema the app and its specs were built on doesn't (46 against 17), for exampledatasets.website_idtowebsites, and the factories create records that break them. So the database has drifted from the migrations (see below), and this PR keeps to the migration-built schema the suite was written against.Drift between your database and the migrations
Not changed here, but worth knowing. Compared with this schema, the database 7f502da was dumped from has:
authors.orchid,citations.abstract_backup,affiliations.lno_record_idNOT NULLonaffiliations.person_id, anddatasets.versionwith a default of 1 (the migration-built schema has no default)plots,species,open_id_authentication_*tables, which the migrations still createIf those columns and constraints are meant to be part of the app, they need migrations.
Keeping it loadable
bin/rails db:migratein development rewritesdb/schema.rbfrom whatever database it runs against, which is how the extras got in. To add a migration without that, run it against a scratch database:Testing
rails db:schema:loadinto a fresh PostgreSQL 16 database with no extensions exceptplpgsql(87 tables includingschema_migrationsandar_internal_metadata): loads cleanly.🤖 Generated with Claude Code
https://claude.ai/code/session_016AR3uoZS1uCC8hXmojk3K7