oficina / calendar Public

Clone
git clone https://amadan.net/oficina/calendar

Plain git — no account needed to clone.

Download

Download this file

1package calendar
2
3import (
4 "embed"
5
6 "amadan.net/rastrillo/rastrillo/migrate"
7 "amadan.net/rastrillo/rastrillo/sessions"
8)
9
10//go:embed migrations/*.sql
11var migrationFS embed.FS
12
13// Schema is this app's own migrations, in order — nothing else. It is
14// what `rastrillo migration generate` and `rastrillo migration check` read
15// and write: both work by replaying a set into an in-memory database
16// and diffing the result against Models, so Schema must never carry a
17// framework subsystem's migrations too — mixed in, the diff would see
18// tables (sessions, auth_links, ...) that Models knows nothing about
19// and want to drop every one of them.
20//
21// Add to it with `rastrillo migration generate` after changing a
22// model, or `rastrillo migration new <name>` to write one by hand.
23// Migrations apply at boot and are never re-run or reversed: never
24// edit one that has shipped, add a new one instead.
25var Schema = migrate.MustFromFS(migrationFS, "calendar")
26
27// BootSchema is everything applied at boot, in order — every framework
28// subsystem's migrations plus this app's own — and it is what New hands
29// to migrate.Apply. It is a separate variable from Schema for the same
30// reason Schema must stay narrow: generate and check would misread a
31// subsystem's tables as ones Models forgot, and propose dropping every
32// one of them.
33//
34// Merge's argument order is apply order, and this order is load-bearing
35// rather than alphabetical: auth's own backfill migration reads the
36// sessions table, so sessions.Schema must apply first. Get this line
37// wrong and boot either skips a subsystem's tables or fails on a
38// migration that references one that does not exist yet.
39var BootSchema = migrate.Merge(sessions.Schema, authSchema, Schema)
40