@jam-overture/loom 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/application/application.d.ts +109 -0
- package/dist/application/application.js +97 -0
- package/dist/application/memory.d.ts +20 -0
- package/dist/application/memory.js +79 -0
- package/dist/application/store.d.ts +101 -0
- package/dist/application/store.js +25 -0
- package/dist/audience/audience.d.ts +36 -0
- package/dist/audience/audience.js +41 -0
- package/dist/audience/compose.d.ts +112 -0
- package/dist/audience/compose.js +134 -0
- package/dist/audience/memory.d.ts +14 -0
- package/dist/audience/memory.js +71 -0
- package/dist/audience/overlay-store.d.ts +343 -0
- package/dist/audience/overlay-store.js +217 -0
- package/dist/audience/rule.d.ts +121 -0
- package/dist/audience/rule.js +78 -0
- package/dist/cli/index.d.ts +3 -4
- package/dist/cli/index.js +3 -4
- package/dist/cli/templates.js +19 -0
- package/dist/data/adapter.d.ts +9 -1
- package/dist/data/adapter.js +2 -0
- package/dist/data/plan.js +0 -0
- package/dist/data/resolution.d.ts +23 -1
- package/dist/data/resolve.d.ts +31 -4
- package/dist/data/resolve.js +11 -3
- package/dist/ids.d.ts +10 -0
- package/dist/ids.js +11 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/interpretation/anthropic.d.ts +1 -1
- package/dist/interpretation/anthropic.js +2 -22
- package/dist/interpretation/client.d.ts +1 -1
- package/dist/interpretation/materialize.js +67 -22
- package/dist/interpretation/openai-compatible.d.ts +36 -0
- package/dist/interpretation/openai-compatible.js +79 -0
- package/dist/interpretation/status.d.ts +19 -0
- package/dist/interpretation/status.js +26 -0
- package/dist/live/index.d.ts +73 -0
- package/dist/live/index.js +73 -0
- package/dist/live/pages.d.ts +187 -0
- package/dist/live/pages.js +161 -0
- package/dist/live/pull.d.ts +147 -0
- package/dist/live/pull.js +398 -0
- package/dist/live/pulling.d.ts +79 -0
- package/dist/live/pulling.js +117 -0
- package/dist/live/window.d.ts +129 -0
- package/dist/live/window.js +132 -0
- package/dist/patch.d.ts +54 -0
- package/dist/patch.js +44 -0
- package/dist/project/closing.d.ts +51 -0
- package/dist/project/closing.js +53 -0
- package/dist/project/memory.d.ts +20 -0
- package/dist/project/memory.js +97 -0
- package/dist/project/project.d.ts +90 -0
- package/dist/project/project.js +91 -0
- package/dist/project/store.d.ts +135 -0
- package/dist/project/store.js +41 -0
- package/dist/registered.d.ts +64 -0
- package/dist/registered.js +118 -0
- package/dist/render/addressed.d.ts +35 -0
- package/dist/render/addressed.js +79 -0
- package/dist/render/behaviour-adjust.d.ts +11 -19
- package/dist/render/behaviour-adjust.js +75 -21
- package/dist/render/behaviour-present.d.ts +8 -0
- package/dist/render/behaviour-present.js +57 -6
- package/dist/render/behaviour.d.ts +98 -17
- package/dist/render/behaviour.js +91 -26
- package/dist/render/control-name.d.ts +68 -0
- package/dist/render/control-name.js +37 -0
- package/dist/render/diagnostics.d.ts +72 -0
- package/dist/render/diagnostics.js +7 -0
- package/dist/render/document-theme.d.ts +70 -0
- package/dist/render/document-theme.js +139 -0
- package/dist/render/editable.d.ts +15 -1
- package/dist/render/editable.js +13 -1
- package/dist/render/expected.d.ts +98 -0
- package/dist/render/expected.js +88 -0
- package/dist/render/index.d.ts +4 -0
- package/dist/render/index.js +4 -0
- package/dist/render/reads.d.ts +11 -0
- package/dist/render/reads.js +12 -1
- package/dist/render/render.d.ts +11 -0
- package/dist/render/render.js +294 -53
- package/dist/render/request.d.ts +8 -1
- package/dist/render/request.js +1 -0
- package/dist/render/slots.d.ts +52 -0
- package/dist/render/slots.js +24 -0
- package/dist/render/theme.d.ts +54 -1
- package/dist/render/theme.js +23 -1
- package/dist/render/unshown.d.ts +152 -0
- package/dist/render/unshown.js +80 -0
- package/dist/runtime/analysis.d.ts +94 -9
- package/dist/runtime/analysis.js +54 -9
- package/dist/runtime/assessment.d.ts +36 -2
- package/dist/runtime/assessment.js +27 -2
- package/dist/runtime/auto-apply-ceiling.d.ts +54 -0
- package/dist/runtime/auto-apply-ceiling.js +66 -0
- package/dist/runtime/checks.d.ts +148 -0
- package/dist/runtime/checks.js +112 -0
- package/dist/runtime/disposition.d.ts +96 -0
- package/dist/runtime/disposition.js +46 -0
- package/dist/runtime/gate.js +91 -10
- package/dist/runtime/index.d.ts +4 -0
- package/dist/runtime/index.js +4 -0
- package/dist/runtime/irreversibility.d.ts +64 -0
- package/dist/runtime/irreversibility.js +45 -0
- package/dist/runtime/nesting.d.ts +13 -1
- package/dist/runtime/nesting.js +41 -24
- package/dist/runtime/pipeline.d.ts +43 -0
- package/dist/runtime/pipeline.js +10 -2
- package/dist/runtime/policy-change.d.ts +93 -0
- package/dist/runtime/policy-change.js +305 -0
- package/dist/runtime/policy-log.d.ts +406 -0
- package/dist/runtime/policy-log.js +285 -0
- package/dist/runtime/policy.d.ts +8 -6
- package/dist/runtime/policy.js +5 -2
- package/dist/runtime/repointing.js +0 -0
- package/dist/runtime/reversibility.d.ts +11 -9
- package/dist/runtime/stakes.d.ts +129 -1
- package/dist/runtime/stakes.js +240 -26
- package/dist/runtime/vocabulary.d.ts +164 -7
- package/dist/runtime/vocabulary.js +181 -8
- package/dist/sdk/audit.d.ts +174 -3
- package/dist/sdk/audit.js +176 -17
- package/dist/sdk/catalogue.d.ts +9 -1
- package/dist/sdk/conformance.d.ts +37 -3
- package/dist/sdk/conformance.js +25 -4
- package/dist/sdk/definition.d.ts +129 -5
- package/dist/sdk/definition.js +66 -0
- package/dist/sdk/registry.d.ts +45 -2
- package/dist/sdk/registry.js +102 -1
- package/dist/signals/acted.contract.d.ts +21 -0
- package/dist/signals/acted.contract.js +236 -0
- package/dist/signals/acted.d.ts +359 -0
- package/dist/signals/acted.js +135 -0
- package/dist/signals/action-change.d.ts +507 -0
- package/dist/signals/action-change.js +265 -0
- package/dist/signals/action.d.ts +331 -0
- package/dist/signals/action.js +182 -0
- package/dist/signals/agenda.d.ts +585 -0
- package/dist/signals/agenda.js +295 -0
- package/dist/signals/applied-window.contract.d.ts +23 -0
- package/dist/signals/applied-window.contract.js +160 -0
- package/dist/signals/arrivals.contract.d.ts +21 -0
- package/dist/signals/arrivals.contract.js +180 -0
- package/dist/signals/arrivals.d.ts +375 -0
- package/dist/signals/arrivals.js +254 -0
- package/dist/signals/arriving.d.ts +210 -0
- package/dist/signals/arriving.js +133 -0
- package/dist/signals/audiences.d.ts +528 -0
- package/dist/signals/audiences.js +255 -0
- package/dist/signals/broadcast.d.ts +33 -17
- package/dist/signals/broadcast.js +255 -32
- package/dist/signals/change.d.ts +378 -0
- package/dist/signals/change.js +327 -0
- package/dist/signals/collect.d.ts +169 -34
- package/dist/signals/collect.js +186 -38
- package/dist/signals/conversion.d.ts +348 -0
- package/dist/signals/conversion.js +235 -0
- package/dist/signals/copy-change.d.ts +553 -0
- package/dist/signals/copy-change.js +377 -0
- package/dist/signals/copy.d.ts +337 -0
- package/dist/signals/copy.js +211 -0
- package/dist/signals/correlated.contract.d.ts +24 -0
- package/dist/signals/correlated.contract.js +94 -0
- package/dist/signals/counters.d.ts +97 -0
- package/dist/signals/counters.js +160 -0
- package/dist/signals/deliver.d.ts +23 -4
- package/dist/signals/deliver.js +34 -6
- package/dist/signals/deployment-change.d.ts +395 -0
- package/dist/signals/deployment-change.js +309 -0
- package/dist/signals/deployment.d.ts +278 -0
- package/dist/signals/deployment.js +178 -0
- package/dist/signals/door.d.ts +114 -0
- package/dist/signals/door.js +77 -0
- package/dist/signals/expire.d.ts +192 -0
- package/dist/signals/expire.js +213 -0
- package/dist/signals/fold.d.ts +10 -0
- package/dist/signals/fold.js +5 -1
- package/dist/signals/form-action.d.ts +302 -0
- package/dist/signals/form-action.js +169 -0
- package/dist/signals/form-copy.d.ts +523 -0
- package/dist/signals/form-copy.js +346 -0
- package/dist/signals/forms.d.ts +247 -0
- package/dist/signals/forms.js +147 -0
- package/dist/signals/frontier.d.ts +268 -0
- package/dist/signals/frontier.js +145 -0
- package/dist/signals/funnel-change.d.ts +548 -0
- package/dist/signals/funnel-change.js +361 -0
- package/dist/signals/funnel-hours.contract.d.ts +21 -0
- package/dist/signals/funnel-hours.contract.js +221 -0
- package/dist/signals/funnel-hours.d.ts +293 -0
- package/dist/signals/funnel-hours.js +99 -0
- package/dist/signals/funnel.d.ts +592 -0
- package/dist/signals/funnel.js +231 -0
- package/dist/signals/health.d.ts +694 -0
- package/dist/signals/health.js +573 -0
- package/dist/signals/index.d.ts +60 -0
- package/dist/signals/index.js +60 -0
- package/dist/signals/ingest.d.ts +56 -1
- package/dist/signals/ingest.js +91 -1
- package/dist/signals/inside.d.ts +190 -0
- package/dist/signals/inside.js +263 -0
- package/dist/signals/join.d.ts +56 -0
- package/dist/signals/join.js +60 -0
- package/dist/signals/journal.d.ts +123 -9
- package/dist/signals/kept.contract.d.ts +22 -0
- package/dist/signals/kept.contract.js +111 -0
- package/dist/signals/kinds.d.ts +8 -6
- package/dist/signals/kinds.js +14 -6
- package/dist/signals/library-action.d.ts +430 -0
- package/dist/signals/library-action.js +336 -0
- package/dist/signals/library-agenda-change.d.ts +324 -0
- package/dist/signals/library-agenda-change.js +199 -0
- package/dist/signals/library-agenda.d.ts +258 -0
- package/dist/signals/library-agenda.js +167 -0
- package/dist/signals/library-change.d.ts +477 -0
- package/dist/signals/library-change.js +335 -0
- package/dist/signals/library-copy-change.d.ts +498 -0
- package/dist/signals/library-copy-change.js +476 -0
- package/dist/signals/library-pace.d.ts +319 -0
- package/dist/signals/library-pace.js +305 -0
- package/dist/signals/library-reach-change.d.ts +646 -0
- package/dist/signals/library-reach-change.js +542 -0
- package/dist/signals/library-reach.d.ts +377 -0
- package/dist/signals/library-reach.js +227 -0
- package/dist/signals/library-senders-change.d.ts +457 -0
- package/dist/signals/library-senders-change.js +367 -0
- package/dist/signals/library-senders-reach-change.d.ts +486 -0
- package/dist/signals/library-senders-reach-change.js +538 -0
- package/dist/signals/library-senders-reach.d.ts +340 -0
- package/dist/signals/library-senders-reach.js +252 -0
- package/dist/signals/library-senders.d.ts +271 -0
- package/dist/signals/library-senders.js +180 -0
- package/dist/signals/library-word-reach-change.d.ts +567 -0
- package/dist/signals/library-word-reach-change.js +564 -0
- package/dist/signals/library.d.ts +306 -0
- package/dist/signals/library.js +178 -0
- package/dist/signals/memory.d.ts +9 -0
- package/dist/signals/memory.js +246 -14
- package/dist/signals/migrate.d.ts +20 -4
- package/dist/signals/migrate.js +269 -8
- package/dist/signals/notice.d.ts +389 -0
- package/dist/signals/notice.js +250 -0
- package/dist/signals/pace-change.d.ts +501 -0
- package/dist/signals/pace-change.js +310 -0
- package/dist/signals/pace.d.ts +296 -0
- package/dist/signals/pace.js +291 -0
- package/dist/signals/page-views.d.ts +365 -0
- package/dist/signals/page-views.js +218 -0
- package/dist/signals/part-pace.d.ts +378 -0
- package/dist/signals/part-pace.js +333 -0
- package/dist/signals/parts.d.ts +354 -0
- package/dist/signals/parts.js +232 -0
- package/dist/signals/postgres.d.ts +16 -2
- package/dist/signals/postgres.js +753 -76
- package/dist/signals/progress.d.ts +212 -0
- package/dist/signals/progress.js +150 -0
- package/dist/signals/ratios.d.ts +108 -0
- package/dist/signals/ratios.js +40 -0
- package/dist/signals/reach.d.ts +309 -0
- package/dist/signals/reach.js +93 -0
- package/dist/signals/readable.d.ts +34 -0
- package/dist/signals/readable.js +34 -0
- package/dist/signals/readership.d.ts +381 -0
- package/dist/signals/readership.js +308 -0
- package/dist/signals/region-pages.d.ts +173 -0
- package/dist/signals/region-pages.js +62 -0
- package/dist/signals/region.d.ts +287 -0
- package/dist/signals/region.js +198 -0
- package/dist/signals/retention.d.ts +163 -0
- package/dist/signals/retention.js +75 -0
- package/dist/signals/rhythm.d.ts +302 -0
- package/dist/signals/rhythm.js +262 -0
- package/dist/signals/rollup.d.ts +194 -4
- package/dist/signals/rollup.js +0 -0
- package/dist/signals/schema.d.ts +1069 -1
- package/dist/signals/schema.js +393 -3
- package/dist/signals/signal.d.ts +237 -11
- package/dist/signals/signal.js +70 -10
- package/dist/signals/silence-census.d.ts +205 -0
- package/dist/signals/silence-census.js +87 -0
- package/dist/signals/silences.d.ts +1147 -0
- package/dist/signals/silences.js +996 -0
- package/dist/signals/subtrees.d.ts +123 -0
- package/dist/signals/subtrees.js +102 -0
- package/dist/signals/tally.d.ts +262 -12
- package/dist/signals/unread.d.ts +292 -0
- package/dist/signals/unread.js +137 -0
- package/dist/signals/window-agenda.d.ts +276 -0
- package/dist/signals/window-agenda.js +83 -0
- package/dist/signals/window-figures.d.ts +148 -0
- package/dist/signals/window-figures.js +42 -0
- package/dist/signals/window-funnels.d.ts +88 -0
- package/dist/signals/window-funnels.js +47 -0
- package/dist/signals/window.d.ts +866 -0
- package/dist/signals/window.js +693 -0
- package/dist/signals/words.d.ts +24 -0
- package/dist/signals/words.js +24 -0
- package/dist/store/cache.d.ts +101 -0
- package/dist/store/cache.js +149 -0
- package/dist/store/history.d.ts +82 -0
- package/dist/store/history.js +36 -0
- package/dist/store/index.d.ts +30 -0
- package/dist/store/index.js +30 -0
- package/dist/store/memory.d.ts +2 -1
- package/dist/store/memory.js +48 -12
- package/dist/store/migrate.d.ts +106 -0
- package/dist/store/migrate.js +323 -7
- package/dist/store/postgres-applications.d.ts +4 -0
- package/dist/store/postgres-applications.js +197 -0
- package/dist/store/postgres-audience.d.ts +14 -0
- package/dist/store/postgres-audience.js +272 -0
- package/dist/store/postgres-holds.d.ts +10 -1
- package/dist/store/postgres-holds.js +116 -101
- package/dist/store/postgres-policy-log.d.ts +14 -0
- package/dist/store/postgres-policy-log.js +240 -0
- package/dist/store/postgres-projects.d.ts +4 -0
- package/dist/store/postgres-projects.js +217 -0
- package/dist/store/postgres.d.ts +17 -1
- package/dist/store/postgres.js +60 -9
- package/dist/store/replay.d.ts +102 -1
- package/dist/store/replay.js +190 -19
- package/dist/store/reseed.d.ts +238 -0
- package/dist/store/reseed.js +308 -0
- package/dist/store/schema.d.ts +762 -2
- package/dist/store/schema.js +218 -5
- package/dist/store/source.d.ts +57 -1
- package/dist/store/source.js +65 -1
- package/dist/store/store.d.ts +29 -6
- package/dist/submit/resolve.d.ts +1 -1
- package/dist/submit/resolve.js +2 -1
- package/dist/telemetry/calibration.d.ts +25 -0
- package/dist/telemetry/calibration.js +27 -1
- package/dist/telemetry/event.d.ts +391 -33
- package/dist/telemetry/event.js +84 -20
- package/dist/telemetry/index.d.ts +2 -0
- package/dist/telemetry/index.js +2 -0
- package/dist/telemetry/journal.d.ts +104 -3
- package/dist/telemetry/journal.js +9 -0
- package/dist/telemetry/lookup.d.ts +27 -0
- package/dist/telemetry/lookup.js +18 -0
- package/dist/telemetry/memory.js +33 -1
- package/dist/telemetry/migrate.js +22 -1
- package/dist/telemetry/postgres.d.ts +10 -1
- package/dist/telemetry/postgres.js +188 -90
- package/dist/telemetry/remeasure.d.ts +78 -0
- package/dist/telemetry/remeasure.js +83 -0
- package/dist/telemetry/retention.d.ts +2 -2
- package/dist/telemetry/schema.d.ts +17 -0
- package/dist/telemetry/schema.js +27 -1
- package/dist/telemetry/sink.d.ts +2 -2
- package/dist/telemetry/window.d.ts +135 -0
- package/dist/telemetry/window.js +101 -0
- package/dist/testing/application-contract.d.ts +14 -0
- package/dist/testing/application-contract.js +270 -0
- package/dist/testing/audience-overlay-contract.d.ts +31 -0
- package/dist/testing/audience-overlay-contract.js +354 -0
- package/dist/testing/contracts.d.ts +13 -7
- package/dist/testing/contracts.js +13 -7
- package/dist/testing/definitions.d.ts +78 -0
- package/dist/testing/definitions.js +134 -9
- package/dist/testing/doubles.d.ts +103 -0
- package/dist/testing/doubles.js +143 -0
- package/dist/testing/index.d.ts +2 -2
- package/dist/testing/index.js +2 -2
- package/dist/testing/journal-contract.js +297 -6
- package/dist/testing/model-contract.d.ts +110 -0
- package/dist/testing/model-contract.js +150 -0
- package/dist/testing/policy-log-contract.d.ts +26 -0
- package/dist/testing/policy-log-contract.js +344 -0
- package/dist/testing/project-contract.d.ts +14 -0
- package/dist/testing/project-contract.js +266 -0
- package/dist/testing/reader-signal-contract.d.ts +27 -2
- package/dist/testing/reader-signal-contract.js +475 -5
- package/dist/testing/store-contract.d.ts +7 -1
- package/dist/testing/store-contract.js +84 -3
- package/dist/theme/apply.d.ts +20 -1
- package/dist/theme/apply.js +5 -3
- package/dist/theme/contrast.d.ts +19 -14
- package/dist/theme/contrast.js +181 -17
- package/dist/theme/derive.d.ts +22 -0
- package/dist/theme/derive.js +54 -1
- package/dist/theme/library.js +1 -1
- package/dist/theme/measure.d.ts +34 -0
- package/dist/theme/measure.js +30 -1
- package/dist/theme/palettes.js +7 -7
- package/dist/theme/ramp.d.ts +64 -0
- package/dist/theme/ramp.js +114 -0
- package/dist/theme/registry.d.ts +9 -0
- package/dist/theme/registry.js +11 -1
- package/dist/theme/separation.d.ts +97 -3
- package/dist/theme/separation.js +75 -0
- package/dist/tree/apply.js +13 -0
- package/dist/tree/compare.d.ts +9 -0
- package/dist/tree/compare.js +18 -0
- package/dist/tree/mutation.d.ts +18 -0
- package/dist/tree/mutation.js +24 -12
- package/dist/tree/navigation.d.ts +5 -0
- package/dist/tree/navigation.js +32 -10
- package/dist/tree/outline.d.ts +7 -0
- package/dist/tree/outline.js +9 -5
- package/dist/write/computed.d.ts +60 -0
- package/dist/write/computed.js +61 -0
- package/dist/write/held.d.ts +59 -0
- package/dist/write/index.d.ts +5 -2
- package/dist/write/index.js +5 -2
- package/dist/write/reseed.d.ts +151 -0
- package/dist/write/reseed.js +184 -0
- package/dist/write/revert.js +2 -16
- package/package.json +25 -3
- package/dist/runtime/inverse-interpreter.d.ts +0 -90
- package/dist/runtime/inverse-interpreter.js +0 -56
package/dist/store/migrate.d.ts
CHANGED
|
@@ -37,10 +37,87 @@ export declare const TREE_STORE_DDL: readonly string[];
|
|
|
37
37
|
* the entire reason the read exists.
|
|
38
38
|
*/
|
|
39
39
|
export declare const HOLD_STORE_DDL: readonly string[];
|
|
40
|
+
/**
|
|
41
|
+
* The policy log's schema, as statements a host can run.
|
|
42
|
+
*
|
|
43
|
+
* Its own list for the reason the hold store's is: the three are separately
|
|
44
|
+
* useful. A deployment that judges with one policy it has never edited has no
|
|
45
|
+
* reason to carry this table, and one that records policy changes may well keep
|
|
46
|
+
* them beside its trees or somewhere else entirely.
|
|
47
|
+
*
|
|
48
|
+
* The index is not decoration. `judgedUnder` resolves the fingerprint on a
|
|
49
|
+
* disposition into the policy text it was judged under, and a screen showing a
|
|
50
|
+
* page of records asks it once per record; without the index each of those is a
|
|
51
|
+
* scan of every policy revision the deployment has recorded.
|
|
52
|
+
*/
|
|
53
|
+
export declare const POLICY_LOG_DDL: readonly string[];
|
|
40
54
|
/**
|
|
41
55
|
* Creates the tables if they are absent. Every statement is `IF NOT EXISTS`, so
|
|
42
56
|
* running it against a populated database is a no-op rather than a hazard.
|
|
43
57
|
*/
|
|
58
|
+
/**
|
|
59
|
+
* The projects table.
|
|
60
|
+
*
|
|
61
|
+
* Carries no `application_id` default and no backfill, unlike every other statement
|
|
62
|
+
* here: the rows that already exist belong to `app_default` by the default on
|
|
63
|
+
* their own columns, and a row *for* `app_default` is seeded by the deployment
|
|
64
|
+
* rather than conjured by DDL — a migration that invented a project's name
|
|
65
|
+
* would be guessing, which 0260 refuses.
|
|
66
|
+
*/
|
|
67
|
+
export declare const APPLICATION_STORE_DDL: readonly string[];
|
|
68
|
+
/**
|
|
69
|
+
* The projects the applications are grouped under.
|
|
70
|
+
*
|
|
71
|
+
* Its own list rather than a statement in the one above, on the terms this file
|
|
72
|
+
* already sets: a deployment adds a seam by adding its `ensure` call on
|
|
73
|
+
* purpose. They are run together by `db:push` because an application's
|
|
74
|
+
* `project_id` would otherwise point at nothing.
|
|
75
|
+
*
|
|
76
|
+
* **It must run after `ensureApplicationStoreSchema`, not before.** That one
|
|
77
|
+
* renames the `loom_projects` which briefly held applications; this one then
|
|
78
|
+
* creates a fresh table under the freed name. The other order silently loses
|
|
79
|
+
* the grouping table — `CREATE TABLE IF NOT EXISTS` sees the old one, skips,
|
|
80
|
+
* and the rename carries it off — with no error anywhere.
|
|
81
|
+
*/
|
|
82
|
+
export declare const PROJECT_STORE_DDL: readonly string[];
|
|
83
|
+
/**
|
|
84
|
+
* Moving the ids themselves, which the rename above does not.
|
|
85
|
+
*
|
|
86
|
+
* Every row written before 12 October names `prj_default` in a column that now
|
|
87
|
+
* means an application, and `app_default` is what `DEFAULT_APPLICATION_ID`
|
|
88
|
+
* parses to. Six tables carry it, and each update is idempotent because it
|
|
89
|
+
* matches only the old value.
|
|
90
|
+
*
|
|
91
|
+
* **Each one is guarded on its table existing**, which the first draft was not
|
|
92
|
+
* and a test caught: a deployment adds a seam by adding its `ensure` call on
|
|
93
|
+
* purpose, so one that never switched telemetry or the policy log on has no
|
|
94
|
+
* such table, and an unguarded `UPDATE` took the whole migration down with
|
|
95
|
+
* `42P01` rather than skipping what was not there.
|
|
96
|
+
*
|
|
97
|
+
* Separate from the DDL because it is data: a host reading `db:push` can see
|
|
98
|
+
* exactly which rows are touched, rather than finding an `UPDATE` folded into a
|
|
99
|
+
* list called schema.
|
|
100
|
+
*/
|
|
101
|
+
export declare const APPLICATION_ID_MIGRATION: readonly string[];
|
|
102
|
+
/**
|
|
103
|
+
* The tables a page's audience rules and its per-audience forms are kept in
|
|
104
|
+
* (0263).
|
|
105
|
+
*
|
|
106
|
+
* Its own list for the reason the other four are theirs: a deployment serving
|
|
107
|
+
* one form of every page has no reason to carry either table, and nothing else
|
|
108
|
+
* here reads them. A host adds them by adding its `ensure` call on purpose.
|
|
109
|
+
*
|
|
110
|
+
* **No backfill and no migration of anything.** Both tables are new, nothing
|
|
111
|
+
* was ever stored in another shape, and a page with no rows in either is served
|
|
112
|
+
* exactly as it is today — the base tree, which is what `audiencesFor` answers
|
|
113
|
+
* for an empty rule list.
|
|
114
|
+
*
|
|
115
|
+
* No index beyond the keys. Both reads are a seek on the key's own prefix: the
|
|
116
|
+
* rules' head is the newest revision under `(application_id, tree_id)`, which
|
|
117
|
+
* the primary key already orders, and a page's forms are a range under the same
|
|
118
|
+
* prefix. An index here would be a second copy of the key.
|
|
119
|
+
*/
|
|
120
|
+
export declare const AUDIENCE_OVERLAY_DDL: readonly string[];
|
|
44
121
|
export declare const ensureTreeStoreSchema: (db: LoomDatabase) => Promise<void>;
|
|
45
122
|
/**
|
|
46
123
|
* Creates the hold table if it is absent. Idempotent on the same terms.
|
|
@@ -51,4 +128,33 @@ export declare const ensureTreeStoreSchema: (db: LoomDatabase) => Promise<void>;
|
|
|
51
128
|
* something else.
|
|
52
129
|
*/
|
|
53
130
|
export declare const ensureHoldStoreSchema: (db: LoomDatabase) => Promise<void>;
|
|
131
|
+
/**
|
|
132
|
+
* Creates the policy log's table if it is absent. Idempotent on the same terms,
|
|
133
|
+
* and separate for the same reason: a deployment that wants a record of who
|
|
134
|
+
* changed its acceptance policy gets it by adding this call on purpose.
|
|
135
|
+
*/
|
|
136
|
+
export declare const ensurePolicyLogSchema: (db: LoomDatabase) => Promise<void>;
|
|
137
|
+
/**
|
|
138
|
+
* Creates the projects table if it is absent. Idempotent, and separate for the
|
|
139
|
+
* same reason the other three are: a deployment that wants more than one
|
|
140
|
+
* project gets the table by adding this call on purpose.
|
|
141
|
+
*/
|
|
142
|
+
export declare const ensureApplicationStoreSchema: (db: LoomDatabase) => Promise<void>;
|
|
143
|
+
/**
|
|
144
|
+
* Creates the projects table if it is absent. Idempotent on the same terms.
|
|
145
|
+
*/
|
|
146
|
+
export declare const ensureProjectStoreSchema: (db: LoomDatabase) => Promise<void>;
|
|
147
|
+
/**
|
|
148
|
+
* Carries `prj_default` to `app_default` across every table that names an
|
|
149
|
+
* application. Safe to run on a database that has already been carried, and on
|
|
150
|
+
* one that was never on the old value.
|
|
151
|
+
*/
|
|
152
|
+
export declare const migrateApplicationIds: (db: LoomDatabase) => Promise<void>;
|
|
153
|
+
/**
|
|
154
|
+
* Creates the audience dimension's two tables if they are absent. Idempotent,
|
|
155
|
+
* and separate for the reason the other four are: a deployment that wants to
|
|
156
|
+
* serve one page to more than one audience gets the tables by adding this call
|
|
157
|
+
* on purpose.
|
|
158
|
+
*/
|
|
159
|
+
export declare const ensureAudienceOverlaySchema: (db: LoomDatabase) => Promise<void>;
|
|
54
160
|
//# sourceMappingURL=migrate.d.ts.map
|
package/dist/store/migrate.js
CHANGED
|
@@ -21,12 +21,15 @@ import { sql } from "drizzle-orm";
|
|
|
21
21
|
*/
|
|
22
22
|
export const TREE_STORE_DDL = [
|
|
23
23
|
`CREATE TABLE IF NOT EXISTS loom_trees (
|
|
24
|
-
|
|
24
|
+
application_id text NOT NULL DEFAULT 'app_default',
|
|
25
|
+
tree_id text NOT NULL,
|
|
25
26
|
revision integer NOT NULL,
|
|
26
27
|
document jsonb NOT NULL,
|
|
27
|
-
updated_at timestamptz NOT NULL DEFAULT now()
|
|
28
|
+
updated_at timestamptz NOT NULL DEFAULT now(),
|
|
29
|
+
PRIMARY KEY (application_id, tree_id)
|
|
28
30
|
)`,
|
|
29
31
|
`CREATE TABLE IF NOT EXISTS loom_revisions (
|
|
32
|
+
application_id text NOT NULL DEFAULT 'app_default',
|
|
30
33
|
tree_id text NOT NULL,
|
|
31
34
|
revision integer NOT NULL,
|
|
32
35
|
proposal_id text NOT NULL,
|
|
@@ -34,8 +37,33 @@ export const TREE_STORE_DDL = [
|
|
|
34
37
|
provenance jsonb NOT NULL,
|
|
35
38
|
applied_at text NOT NULL,
|
|
36
39
|
answered_by text,
|
|
37
|
-
PRIMARY KEY (tree_id, revision)
|
|
40
|
+
PRIMARY KEY (application_id, tree_id, revision)
|
|
38
41
|
)`,
|
|
42
|
+
/*
|
|
43
|
+
* **The migration, for a database that predates projects (0260).**
|
|
44
|
+
*
|
|
45
|
+
* Two statements per table and both are needed. The column is additive and
|
|
46
|
+
* defaulted, so every row already written becomes the default project's —
|
|
47
|
+
* 0260 clause 5, *nothing is migrated by guessing*: those rows belong to the
|
|
48
|
+
* deployment that wrote them, and one project named for it is the honest
|
|
49
|
+
* answer rather than a distribution somebody invented.
|
|
50
|
+
*
|
|
51
|
+
* The key then has to widen, because a tree id is only unique **within** a
|
|
52
|
+
* project now and the old key says it is unique everywhere. Dropping by the
|
|
53
|
+
* name Postgres gives a primary key and re-adding is idempotent: after the
|
|
54
|
+
* first run the constraint exists again under the same name, so a second run
|
|
55
|
+
* drops and rebuilds an identical key. On a table created by the statements
|
|
56
|
+
* above it is already right and the pair is a no-op.
|
|
57
|
+
*
|
|
58
|
+
* Ordering matters and is why these are not beside their tables: the column
|
|
59
|
+
* must exist on both before either key can name it.
|
|
60
|
+
*/
|
|
61
|
+
`ALTER TABLE loom_trees ADD COLUMN IF NOT EXISTS application_id text NOT NULL DEFAULT 'app_default'`,
|
|
62
|
+
`ALTER TABLE loom_revisions ADD COLUMN IF NOT EXISTS application_id text NOT NULL DEFAULT 'app_default'`,
|
|
63
|
+
`ALTER TABLE loom_trees DROP CONSTRAINT IF EXISTS loom_trees_pkey`,
|
|
64
|
+
`ALTER TABLE loom_trees ADD PRIMARY KEY (application_id, tree_id)`,
|
|
65
|
+
`ALTER TABLE loom_revisions DROP CONSTRAINT IF EXISTS loom_revisions_pkey`,
|
|
66
|
+
`ALTER TABLE loom_revisions ADD PRIMARY KEY (application_id, tree_id, revision)`,
|
|
39
67
|
/**
|
|
40
68
|
* For a database that already has the table: `CREATE TABLE IF NOT EXISTS`
|
|
41
69
|
* silently leaves an existing table alone, columns and all, so a column added
|
|
@@ -83,23 +111,272 @@ export const TREE_STORE_DDL = [
|
|
|
83
111
|
*/
|
|
84
112
|
export const HOLD_STORE_DDL = [
|
|
85
113
|
`CREATE TABLE IF NOT EXISTS loom_holds (
|
|
86
|
-
|
|
114
|
+
application_id text NOT NULL DEFAULT 'app_default',
|
|
115
|
+
proposal_id text NOT NULL,
|
|
87
116
|
tree_id text NOT NULL,
|
|
88
117
|
base_revision integer NOT NULL,
|
|
89
118
|
intent jsonb NOT NULL,
|
|
90
119
|
proposal jsonb NOT NULL,
|
|
91
120
|
disposition jsonb NOT NULL,
|
|
92
|
-
held_at text NOT NULL
|
|
121
|
+
held_at text NOT NULL,
|
|
122
|
+
PRIMARY KEY (application_id, proposal_id)
|
|
93
123
|
)`,
|
|
94
|
-
|
|
95
|
-
|
|
124
|
+
/*
|
|
125
|
+
* **The project, for a database that predates it (0260).** Same shape as the
|
|
126
|
+
* tree store's above: the column is additive and defaulted, then the key
|
|
127
|
+
* widens, then the indexes are rebuilt to lead with it.
|
|
128
|
+
*
|
|
129
|
+
* The indexes are dropped by name rather than created `IF NOT EXISTS`,
|
|
130
|
+
* because the names do not change — an existing index on the old columns
|
|
131
|
+
* would be left exactly as it was, and every read of this table would go on
|
|
132
|
+
* scanning across projects while appearing to be indexed.
|
|
133
|
+
*/
|
|
134
|
+
`ALTER TABLE loom_holds ADD COLUMN IF NOT EXISTS application_id text NOT NULL DEFAULT 'app_default'`,
|
|
135
|
+
`ALTER TABLE loom_holds DROP CONSTRAINT IF EXISTS loom_holds_pkey`,
|
|
136
|
+
`ALTER TABLE loom_holds ADD PRIMARY KEY (application_id, proposal_id)`,
|
|
137
|
+
`DROP INDEX IF EXISTS loom_holds_tree_id_held_at_idx`,
|
|
138
|
+
`DROP INDEX IF EXISTS loom_holds_held_at_proposal_id_idx`,
|
|
139
|
+
`CREATE INDEX IF NOT EXISTS loom_holds_tree_id_held_at_idx ON loom_holds (application_id, tree_id, held_at)`,
|
|
140
|
+
`CREATE INDEX IF NOT EXISTS loom_holds_held_at_proposal_id_idx ON loom_holds (application_id, held_at, proposal_id)`,
|
|
96
141
|
/** Locked on creation for the reason the tree store's tables are — see above. */
|
|
97
142
|
`ALTER TABLE loom_holds ENABLE ROW LEVEL SECURITY`,
|
|
98
143
|
];
|
|
144
|
+
/**
|
|
145
|
+
* The policy log's schema, as statements a host can run.
|
|
146
|
+
*
|
|
147
|
+
* Its own list for the reason the hold store's is: the three are separately
|
|
148
|
+
* useful. A deployment that judges with one policy it has never edited has no
|
|
149
|
+
* reason to carry this table, and one that records policy changes may well keep
|
|
150
|
+
* them beside its trees or somewhere else entirely.
|
|
151
|
+
*
|
|
152
|
+
* The index is not decoration. `judgedUnder` resolves the fingerprint on a
|
|
153
|
+
* disposition into the policy text it was judged under, and a screen showing a
|
|
154
|
+
* page of records asks it once per record; without the index each of those is a
|
|
155
|
+
* scan of every policy revision the deployment has recorded.
|
|
156
|
+
*/
|
|
157
|
+
export const POLICY_LOG_DDL = [
|
|
158
|
+
`CREATE TABLE IF NOT EXISTS loom_policy_revisions (
|
|
159
|
+
application_id text NOT NULL DEFAULT 'app_default',
|
|
160
|
+
policy_id text NOT NULL,
|
|
161
|
+
revision integer NOT NULL,
|
|
162
|
+
fingerprint text NOT NULL,
|
|
163
|
+
policy jsonb NOT NULL,
|
|
164
|
+
actor text NOT NULL,
|
|
165
|
+
recorded_at text NOT NULL,
|
|
166
|
+
note text,
|
|
167
|
+
PRIMARY KEY (application_id, policy_id, revision)
|
|
168
|
+
)`,
|
|
169
|
+
/* The project, for a database that predates it — see the hold store's note. */
|
|
170
|
+
`ALTER TABLE loom_policy_revisions ADD COLUMN IF NOT EXISTS application_id text NOT NULL DEFAULT 'app_default'`,
|
|
171
|
+
`ALTER TABLE loom_policy_revisions DROP CONSTRAINT IF EXISTS loom_policy_revisions_pkey`,
|
|
172
|
+
`ALTER TABLE loom_policy_revisions ADD PRIMARY KEY (application_id, policy_id, revision)`,
|
|
173
|
+
`DROP INDEX IF EXISTS loom_policy_revisions_fingerprint_idx`,
|
|
174
|
+
`CREATE INDEX IF NOT EXISTS loom_policy_revisions_fingerprint_idx ON loom_policy_revisions (application_id, policy_id, fingerprint)`,
|
|
175
|
+
/** Locked on creation for the reason the tree store's tables are — see above. */
|
|
176
|
+
`ALTER TABLE loom_policy_revisions ENABLE ROW LEVEL SECURITY`,
|
|
177
|
+
];
|
|
99
178
|
/**
|
|
100
179
|
* Creates the tables if they are absent. Every statement is `IF NOT EXISTS`, so
|
|
101
180
|
* running it against a populated database is a no-op rather than a hazard.
|
|
102
181
|
*/
|
|
182
|
+
/**
|
|
183
|
+
* The projects table.
|
|
184
|
+
*
|
|
185
|
+
* Carries no `application_id` default and no backfill, unlike every other statement
|
|
186
|
+
* here: the rows that already exist belong to `app_default` by the default on
|
|
187
|
+
* their own columns, and a row *for* `app_default` is seeded by the deployment
|
|
188
|
+
* rather than conjured by DDL — a migration that invented a project's name
|
|
189
|
+
* would be guessing, which 0260 refuses.
|
|
190
|
+
*/
|
|
191
|
+
export const APPLICATION_STORE_DDL = [
|
|
192
|
+
/**
|
|
193
|
+
* The rename, first and guarded.
|
|
194
|
+
*
|
|
195
|
+
* `loom_applications` was created as `loom_projects` on 12 October and lived
|
|
196
|
+
* under that name for about an hour, because *project* was the wrong word for
|
|
197
|
+
* the thing with the pages — the maintainer's hierarchy is **account >
|
|
198
|
+
* project > application**, and this is the third. Postgres has no
|
|
199
|
+
* `RENAME … IF EXISTS`, so the catalogue is asked first; a database that never
|
|
200
|
+
* saw the old name skips it, and one that already renamed skips it too.
|
|
201
|
+
*
|
|
202
|
+
* It runs before the `CREATE TABLE IF NOT EXISTS` below rather than after, so
|
|
203
|
+
* a database holding the old table is renamed into the new one instead of
|
|
204
|
+
* ending up with both and the rows in the wrong one.
|
|
205
|
+
*/
|
|
206
|
+
`DO $$
|
|
207
|
+
BEGIN
|
|
208
|
+
IF EXISTS (SELECT FROM pg_tables WHERE schemaname = current_schema() AND tablename = 'loom_projects')
|
|
209
|
+
AND EXISTS (SELECT FROM information_schema.columns
|
|
210
|
+
WHERE table_name = 'loom_projects' AND column_name = 'host')
|
|
211
|
+
AND NOT EXISTS (SELECT FROM pg_tables WHERE schemaname = current_schema() AND tablename = 'loom_applications')
|
|
212
|
+
THEN
|
|
213
|
+
ALTER TABLE loom_projects RENAME TO loom_applications;
|
|
214
|
+
ALTER TABLE loom_applications RENAME COLUMN project_id TO application_id;
|
|
215
|
+
END IF;
|
|
216
|
+
END
|
|
217
|
+
$$`,
|
|
218
|
+
`CREATE TABLE IF NOT EXISTS loom_applications (
|
|
219
|
+
application_id text PRIMARY KEY,
|
|
220
|
+
name text NOT NULL,
|
|
221
|
+
created_at text NOT NULL,
|
|
222
|
+
host text,
|
|
223
|
+
closed_at text
|
|
224
|
+
)`,
|
|
225
|
+
/**
|
|
226
|
+
* The grouping an application belongs to. Defaulted so a row written before
|
|
227
|
+
* projects existed keeps answering, which is the device every scoped column
|
|
228
|
+
* in this file uses.
|
|
229
|
+
*/
|
|
230
|
+
`ALTER TABLE loom_applications ADD COLUMN IF NOT EXISTS project_id text NOT NULL DEFAULT 'prj_default'`,
|
|
231
|
+
/**
|
|
232
|
+
* As every other table here does. It matters on a managed Postgres whose
|
|
233
|
+
* anon role can reach the schema: without it, the list of a deployment's
|
|
234
|
+
* applications — their names and the hosts they run on — is readable by
|
|
235
|
+
* anyone holding the publishable key.
|
|
236
|
+
*/
|
|
237
|
+
/**
|
|
238
|
+
* **Closing, for a database that predates it (0289).** Additive, nullable and
|
|
239
|
+
* undefaulted, which is the only honest value: every row written before this
|
|
240
|
+
* column existed belonged to an application that was open, and still does.
|
|
241
|
+
*
|
|
242
|
+
* This store has no delete, so there is no earlier spelling of *gone* to
|
|
243
|
+
* carry across — nothing was ever removed, which is what makes the backfill
|
|
244
|
+
* no backfill at all.
|
|
245
|
+
*/
|
|
246
|
+
`ALTER TABLE loom_applications ADD COLUMN IF NOT EXISTS closed_at text`,
|
|
247
|
+
`ALTER TABLE loom_applications ENABLE ROW LEVEL SECURITY`,
|
|
248
|
+
];
|
|
249
|
+
/**
|
|
250
|
+
* The projects the applications are grouped under.
|
|
251
|
+
*
|
|
252
|
+
* Its own list rather than a statement in the one above, on the terms this file
|
|
253
|
+
* already sets: a deployment adds a seam by adding its `ensure` call on
|
|
254
|
+
* purpose. They are run together by `db:push` because an application's
|
|
255
|
+
* `project_id` would otherwise point at nothing.
|
|
256
|
+
*
|
|
257
|
+
* **It must run after `ensureApplicationStoreSchema`, not before.** That one
|
|
258
|
+
* renames the `loom_projects` which briefly held applications; this one then
|
|
259
|
+
* creates a fresh table under the freed name. The other order silently loses
|
|
260
|
+
* the grouping table — `CREATE TABLE IF NOT EXISTS` sees the old one, skips,
|
|
261
|
+
* and the rename carries it off — with no error anywhere.
|
|
262
|
+
*/
|
|
263
|
+
export const PROJECT_STORE_DDL = [
|
|
264
|
+
`CREATE TABLE IF NOT EXISTS loom_projects (
|
|
265
|
+
project_id text PRIMARY KEY,
|
|
266
|
+
name text NOT NULL,
|
|
267
|
+
created_at text NOT NULL,
|
|
268
|
+
repository text,
|
|
269
|
+
closed_at text
|
|
270
|
+
)`,
|
|
271
|
+
/** The repository a project names, for a database that predates it (0292). */
|
|
272
|
+
`ALTER TABLE loom_projects ADD COLUMN IF NOT EXISTS repository text`,
|
|
273
|
+
/**
|
|
274
|
+
* **At most one project per repository**, enforced here rather than checked
|
|
275
|
+
* before the insert.
|
|
276
|
+
*
|
|
277
|
+
* A check and then an insert is a race two people registering the same
|
|
278
|
+
* repository at the same moment would lose quietly — one of them would take
|
|
279
|
+
* ownership of the other's write-back destination, and nothing afterwards
|
|
280
|
+
* could say which. The index makes it the database's answer, the way the
|
|
281
|
+
* primary key already makes *already taken* the database's answer about an
|
|
282
|
+
* id.
|
|
283
|
+
*
|
|
284
|
+
* Partial, because `NULL` is the ordinary state and a plain unique index
|
|
285
|
+
* would admit exactly one project with no repository.
|
|
286
|
+
*/
|
|
287
|
+
`CREATE UNIQUE INDEX IF NOT EXISTS loom_projects_repository_idx ON loom_projects (repository) WHERE repository IS NOT NULL`,
|
|
288
|
+
/** Closing, for a database that predates it — see the applications' note above. */
|
|
289
|
+
`ALTER TABLE loom_projects ADD COLUMN IF NOT EXISTS closed_at text`,
|
|
290
|
+
`ALTER TABLE loom_projects ENABLE ROW LEVEL SECURITY`,
|
|
291
|
+
];
|
|
292
|
+
/**
|
|
293
|
+
* Moving the ids themselves, which the rename above does not.
|
|
294
|
+
*
|
|
295
|
+
* Every row written before 12 October names `prj_default` in a column that now
|
|
296
|
+
* means an application, and `app_default` is what `DEFAULT_APPLICATION_ID`
|
|
297
|
+
* parses to. Six tables carry it, and each update is idempotent because it
|
|
298
|
+
* matches only the old value.
|
|
299
|
+
*
|
|
300
|
+
* **Each one is guarded on its table existing**, which the first draft was not
|
|
301
|
+
* and a test caught: a deployment adds a seam by adding its `ensure` call on
|
|
302
|
+
* purpose, so one that never switched telemetry or the policy log on has no
|
|
303
|
+
* such table, and an unguarded `UPDATE` took the whole migration down with
|
|
304
|
+
* `42P01` rather than skipping what was not there.
|
|
305
|
+
*
|
|
306
|
+
* Separate from the DDL because it is data: a host reading `db:push` can see
|
|
307
|
+
* exactly which rows are touched, rather than finding an `UPDATE` folded into a
|
|
308
|
+
* list called schema.
|
|
309
|
+
*/
|
|
310
|
+
export const APPLICATION_ID_MIGRATION = [
|
|
311
|
+
"loom_trees",
|
|
312
|
+
"loom_revisions",
|
|
313
|
+
"loom_holds",
|
|
314
|
+
"loom_policy_revisions",
|
|
315
|
+
"loom_telemetry",
|
|
316
|
+
"loom_applications",
|
|
317
|
+
].map((table) => `DO $$
|
|
318
|
+
BEGIN
|
|
319
|
+
IF EXISTS (SELECT FROM pg_tables WHERE schemaname = current_schema() AND tablename = '${table}')
|
|
320
|
+
THEN
|
|
321
|
+
UPDATE ${table} SET application_id = 'app_default' WHERE application_id = 'prj_default';
|
|
322
|
+
END IF;
|
|
323
|
+
END
|
|
324
|
+
$$`);
|
|
325
|
+
/**
|
|
326
|
+
* The tables a page's audience rules and its per-audience forms are kept in
|
|
327
|
+
* (0263).
|
|
328
|
+
*
|
|
329
|
+
* Its own list for the reason the other four are theirs: a deployment serving
|
|
330
|
+
* one form of every page has no reason to carry either table, and nothing else
|
|
331
|
+
* here reads them. A host adds them by adding its `ensure` call on purpose.
|
|
332
|
+
*
|
|
333
|
+
* **No backfill and no migration of anything.** Both tables are new, nothing
|
|
334
|
+
* was ever stored in another shape, and a page with no rows in either is served
|
|
335
|
+
* exactly as it is today — the base tree, which is what `audiencesFor` answers
|
|
336
|
+
* for an empty rule list.
|
|
337
|
+
*
|
|
338
|
+
* No index beyond the keys. Both reads are a seek on the key's own prefix: the
|
|
339
|
+
* rules' head is the newest revision under `(application_id, tree_id)`, which
|
|
340
|
+
* the primary key already orders, and a page's forms are a range under the same
|
|
341
|
+
* prefix. An index here would be a second copy of the key.
|
|
342
|
+
*/
|
|
343
|
+
export const AUDIENCE_OVERLAY_DDL = [
|
|
344
|
+
`CREATE TABLE IF NOT EXISTS loom_audience_rules (
|
|
345
|
+
application_id text NOT NULL DEFAULT 'app_default',
|
|
346
|
+
tree_id text NOT NULL,
|
|
347
|
+
revision integer NOT NULL,
|
|
348
|
+
rules jsonb NOT NULL,
|
|
349
|
+
actor text NOT NULL,
|
|
350
|
+
recorded_at text NOT NULL,
|
|
351
|
+
PRIMARY KEY (application_id, tree_id, revision)
|
|
352
|
+
)`,
|
|
353
|
+
`CREATE TABLE IF NOT EXISTS loom_audience_forms (
|
|
354
|
+
application_id text NOT NULL DEFAULT 'app_default',
|
|
355
|
+
tree_id text NOT NULL,
|
|
356
|
+
audience_id text NOT NULL,
|
|
357
|
+
delta jsonb NOT NULL,
|
|
358
|
+
base_revision integer NOT NULL,
|
|
359
|
+
actor text NOT NULL,
|
|
360
|
+
authored_at text NOT NULL,
|
|
361
|
+
withdrawn_by text,
|
|
362
|
+
withdrawn_at text,
|
|
363
|
+
PRIMARY KEY (application_id, tree_id, audience_id)
|
|
364
|
+
)`,
|
|
365
|
+
/**
|
|
366
|
+
* For a database that already has the table, on the terms the `answered_by`
|
|
367
|
+
* statement above sets out.
|
|
368
|
+
*
|
|
369
|
+
* Nullable with no default and no backfill: `NULL` is *this form is the one
|
|
370
|
+
* its audience is served*, which every row written before these columns is.
|
|
371
|
+
* There is no earlier spelling of *withdrawn* to carry across, because until
|
|
372
|
+
* now a form could not be taken out of service at all (0403).
|
|
373
|
+
*/
|
|
374
|
+
`ALTER TABLE loom_audience_forms ADD COLUMN IF NOT EXISTS withdrawn_by text`,
|
|
375
|
+
`ALTER TABLE loom_audience_forms ADD COLUMN IF NOT EXISTS withdrawn_at text`,
|
|
376
|
+
/** Locked on creation for the reason the tree store's tables are — see above. */
|
|
377
|
+
`ALTER TABLE loom_audience_rules ENABLE ROW LEVEL SECURITY`,
|
|
378
|
+
`ALTER TABLE loom_audience_forms ENABLE ROW LEVEL SECURITY`,
|
|
379
|
+
];
|
|
103
380
|
export const ensureTreeStoreSchema = async (db) => {
|
|
104
381
|
await runStatements(db, TREE_STORE_DDL);
|
|
105
382
|
};
|
|
@@ -114,6 +391,45 @@ export const ensureTreeStoreSchema = async (db) => {
|
|
|
114
391
|
export const ensureHoldStoreSchema = async (db) => {
|
|
115
392
|
await runStatements(db, HOLD_STORE_DDL);
|
|
116
393
|
};
|
|
394
|
+
/**
|
|
395
|
+
* Creates the policy log's table if it is absent. Idempotent on the same terms,
|
|
396
|
+
* and separate for the same reason: a deployment that wants a record of who
|
|
397
|
+
* changed its acceptance policy gets it by adding this call on purpose.
|
|
398
|
+
*/
|
|
399
|
+
export const ensurePolicyLogSchema = async (db) => {
|
|
400
|
+
await runStatements(db, POLICY_LOG_DDL);
|
|
401
|
+
};
|
|
402
|
+
/**
|
|
403
|
+
* Creates the projects table if it is absent. Idempotent, and separate for the
|
|
404
|
+
* same reason the other three are: a deployment that wants more than one
|
|
405
|
+
* project gets the table by adding this call on purpose.
|
|
406
|
+
*/
|
|
407
|
+
export const ensureApplicationStoreSchema = async (db) => {
|
|
408
|
+
await runStatements(db, APPLICATION_STORE_DDL);
|
|
409
|
+
};
|
|
410
|
+
/**
|
|
411
|
+
* Creates the projects table if it is absent. Idempotent on the same terms.
|
|
412
|
+
*/
|
|
413
|
+
export const ensureProjectStoreSchema = async (db) => {
|
|
414
|
+
await runStatements(db, PROJECT_STORE_DDL);
|
|
415
|
+
};
|
|
416
|
+
/**
|
|
417
|
+
* Carries `prj_default` to `app_default` across every table that names an
|
|
418
|
+
* application. Safe to run on a database that has already been carried, and on
|
|
419
|
+
* one that was never on the old value.
|
|
420
|
+
*/
|
|
421
|
+
export const migrateApplicationIds = async (db) => {
|
|
422
|
+
await runStatements(db, APPLICATION_ID_MIGRATION);
|
|
423
|
+
};
|
|
424
|
+
/**
|
|
425
|
+
* Creates the audience dimension's two tables if they are absent. Idempotent,
|
|
426
|
+
* and separate for the reason the other four are: a deployment that wants to
|
|
427
|
+
* serve one page to more than one audience gets the tables by adding this call
|
|
428
|
+
* on purpose.
|
|
429
|
+
*/
|
|
430
|
+
export const ensureAudienceOverlaySchema = async (db) => {
|
|
431
|
+
await runStatements(db, AUDIENCE_OVERLAY_DDL);
|
|
432
|
+
};
|
|
117
433
|
const runStatements = async (db, statements) => {
|
|
118
434
|
for (const statement of statements) {
|
|
119
435
|
await db.execute(sql.raw(statement));
|