| 1 | package contra |
| 2 | |
| 3 | import ( |
| 4 | "embed" |
| 5 | |
| 6 | "github.com/carlosframework/rastrillo/migrate" |
| 7 | "github.com/carlosframework/rastrillo/sessions" |
| 8 | ) |
| 9 | |
| 10 | //go:embed migrations/*.sql |
| 11 | var migrationFS embed.FS |
| 12 | |
| 13 | // Schema is this app's own migrations, in order — nothing else. It is what |
| 14 | // `rastrillo migration generate` and `rastrillo migration check` read and |
| 15 | // write: both replay a set into an in-memory database and diff the result |
| 16 | // against Models, so Schema must never carry a framework subsystem's |
| 17 | // migrations too. Mixed in, the diff would see tables Models knows nothing |
| 18 | // about and want to drop every one of them. |
| 19 | // |
| 20 | // Add to it with `rastrillo migration generate` after changing a model, or |
| 21 | // `rastrillo migration new <name>` to write one by hand. Migrations apply at |
| 22 | // boot and are never re-run or reversed: never edit one that has shipped, |
| 23 | // add a new one instead, and never delete data to update. |
| 24 | // |
| 25 | // A migration that adds a table also adds it to the greps |
| 26 | // (internal/contratest/greps_test.go), on the same commit. That is not a |
| 27 | // convention, it is the standing rule: a new storage surface lands with its |
| 28 | // canary or it does not land. |
| 29 | var Schema = migrate.MustFromFS(migrationFS, "contra") |
| 30 | |
| 31 | // BootSchema is everything applied at boot, in order, and it is what App() |
| 32 | // hands to migrate.Apply. Separate from Schema for the reason above: |
| 33 | // generate and check would misread a subsystem's tables as ones Models |
| 34 | // forgot. |
| 35 | // |
| 36 | // Merge's argument order is apply order, so a subsystem another one reads |
| 37 | // goes first. |
| 38 | var BootSchema = migrate.Merge(sessions.Schema, Schema) |
| 39 | |