| 1 | // Package linkstore is what is left of Docs' own Home link store: the |
| 2 | // migrations every Docs database has already applied. Docs links Home |
| 3 | // identities through home/connect now, in connect's home_identity_links, |
| 4 | // and moves this package's rows there once, at boot |
| 5 | // (internal/docs/home_links_move.go), dropping these tables as it does. |
| 6 | // |
| 7 | // The migrations stay because they are in every database's ledger |
| 8 | // (migrations are immutable once applied), and because a new database |
| 9 | // still creates docs_identity_links on the way: principalstore's first |
| 10 | // migration puts a trigger on it, which the move then re-points. |
| 11 | package linkstore |
| 12 | |
| 13 | import ( |
| 14 | "embed" |
| 15 | "io/fs" |
| 16 | |
| 17 | "amadan.net/rastrillo/rastrillo/migrate" |
| 18 | ) |
| 19 | |
| 20 | //go:embed migrations/*.sql |
| 21 | var migrations embed.FS |
| 22 | |
| 23 | // Schema is the applied docs_identity_link set, unchanged. |
| 24 | var Schema = migrate.MustFromFS(migrations, "docs_identity_link") |
| 25 | |
| 26 | //go:embed principals/migrations/*.sql |
| 27 | var forPrincipals embed.FS |
| 28 | |
| 29 | // ForPrincipals goes immediately before principalstore.Schema, and only in |
| 30 | // the team schema. A database that moved its links onto connect while team |
| 31 | // mode was off has no docs_identity_links, and principalstore's first |
| 32 | // migration cannot create its trigger on a missing table, so turning team |
| 33 | // mode on later would refuse to boot. This puts the old table back, empty, |
| 34 | // for that one migration; the move at boot re-points the trigger and drops |
| 35 | // it again. Wherever the table still exists it does nothing. |
| 36 | var ForPrincipals = migrate.MustFromFS(mustSub(forPrincipals, "principals"), "docs_identity_link_principals") |
| 37 | |
| 38 | func mustSub(f fs.FS, dir string) fs.FS { |
| 39 | sub, err := fs.Sub(f, dir) |
| 40 | if err != nil { |
| 41 | panic(err) |
| 42 | } |
| 43 | return sub |
| 44 | } |
| 45 | |