0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-04 10:39:43 +08:00
discourse/.skills/discourse-migration
David Taylor 0a54093115
PERF: Instant db provisioning with structure.sql (#39788)
By default, Rails maintains a `db/structure.sql` file in the repository.
This contains the 'current' database schema, and is intended to quickly
provision new database without having to run all migrations from
scratch. Historically we've avoided this for a few reasons:

1. Our migrations are sometimes used to insert **rows** into the
database. These are not captured in the schema

2. When Rails restores a schema, it adds all the included migrations in
`schema_migrations`, but it did not include our custom
`schema_migration_details` table, which is critical to parts of our app

3. Plugins make things more complicated. We cannot use automatic dumping
of the structure in development environments, because people may have
different sets of plugins.

This PR enables the use of `structure.sql`. Essentially:

1. Adds a `db:dump_structure` task which creates a clean `structure.sql`
in a temporary database (similar to our existing `annotate:clean` for
annotations).

2. Adds a `db:check_structure_dump` which runs migrations from scratch
and verifies they do not introduce any rows in the database. This will
be run in CI.

3. Updates CI to remove our custom database caching. The `structure.sql`
loading is approximately as fast

The `db:check_structure_dump` detected a number of issues, but these
have now been resolved one-by-one in separate PRs.

The bulk of `db:migrate` is now the 'seed' step, and the majority of
that is the installation of system themes. Performance improvements
there could be explored in future.
2026-05-14 15:48:34 +01:00
..
SKILL.md PERF: Instant db provisioning with structure.sql (#39788) 2026-05-14 15:48:34 +01:00