better-supabase 0.25.0 → 0.28.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/dist/{access-sql-bjWFUWlk.js → access-sql-CTDNuxRv.js} +177 -12
- package/dist/ai-sdk/agents/index.d.ts +2 -2
- package/dist/{app-tables-xij_MI5H.d.ts → app-tables-62GqZIhd.d.ts} +1 -1
- package/dist/{authorization-BJV2i8xB.d.ts → authorization-BCG1v0iC.d.ts} +24 -3
- package/dist/{bind-vKDmdu_4.d.ts → bind-C54jD0r3.d.ts} +1 -1
- package/dist/{block-env-wVLz0KMV.d.ts → block-env-CM-LFfj4.d.ts} +3 -3
- package/dist/blocks/ai-chat/index.d.ts +3 -3
- package/dist/blocks/announcements/index.d.ts +3 -3
- package/dist/blocks/api-keys/index.d.ts +1 -1
- package/dist/blocks/attachments/index.d.ts +1 -1
- package/dist/blocks/audit/index.d.ts +2 -2
- package/dist/blocks/automations/index.d.ts +1 -1
- package/dist/blocks/billing/index.d.ts +1 -1
- package/dist/blocks/bookings/index.d.ts +1 -1
- package/dist/blocks/calendar/index.d.ts +1 -1
- package/dist/blocks/comments/index.d.ts +4 -4
- package/dist/blocks/custom-fields/index.js +1 -1
- package/dist/blocks/drive/index.d.ts +1 -1
- package/dist/blocks/employees/index.js +1 -1
- package/dist/blocks/entitlements/index.d.ts +2 -2
- package/dist/blocks/forms/index.d.ts +1 -1
- package/dist/blocks/inbox/index.d.ts +4 -4
- package/dist/blocks/index.d.ts +1 -1
- package/dist/blocks/messaging/index.d.ts +4 -4
- package/dist/blocks/mfa/index.d.ts +1 -1
- package/dist/blocks/notifications/index.d.ts +3 -3
- package/dist/blocks/onboarding/index.d.ts +1 -1
- package/dist/blocks/organizations/index.d.ts +2 -2
- package/dist/blocks/permissions/index.d.ts +1 -1
- package/dist/blocks/push/index.d.ts +1 -1
- package/dist/blocks/reactions/index.d.ts +3 -3
- package/dist/blocks/reminders/index.d.ts +1 -1
- package/dist/blocks/saved-views/index.d.ts +1 -1
- package/dist/blocks/search/index.d.ts +2 -2
- package/dist/blocks/sessions/index.d.ts +1 -1
- package/dist/blocks/settings/index.d.ts +1 -1
- package/dist/blocks/subjects/index.d.ts +1 -1
- package/dist/blocks/tags/index.d.ts +1 -1
- package/dist/blocks/tasks/index.d.ts +1 -1
- package/dist/blocks/tasks/index.js +1 -1
- package/dist/blocks/undo/index.d.ts +1 -1
- package/dist/blocks/usage/index.d.ts +1 -1
- package/dist/blocks/workflow-editor/index.d.ts +3 -3
- package/dist/blocks/workflows/index.d.ts +3 -3
- package/dist/cli/{add-C2pNvVpu.js → add-BKcE_g9D.js} +2 -2
- package/dist/cli/{add-BTVrOGJF.js → add-DUyg9qna.js} +40 -15
- package/dist/cli/add-pDOlqWUa.js +1 -0
- package/dist/cli/{backfill-BicVPugb.js → backfill-r9RELEEh.js} +4 -4
- package/dist/cli/bin.js +1 -1
- package/dist/cli/{blocks-sScN-ik-.js → blocks-DTOFdrxL.js} +1 -1
- package/dist/cli/{blocks-BmYOH4T-.js → blocks-k1OG8XDs.js} +2 -2
- package/dist/cli/{cache-1TfBy2K4.js → cache-Czfw7Iow.js} +1 -1
- package/dist/cli/{codemod-ylE6wGLo.js → codemod-ClmbiLuL.js} +3 -3
- package/dist/cli/{command-BWEEXmtz.js → command-CVzTJSLp.js} +31 -0
- package/dist/cli/{completion-8EDK21xj.js → completion-CNCqE-Gb.js} +1 -1
- package/dist/cli/{completion-BfnKI4QZ.js → completion-Dpk6vh0p.js} +2 -2
- package/dist/cli/{completion-Bt7LMypX.js → completion-DxEXxFpz.js} +2 -2
- package/dist/cli/{config-CeaQMrvS.js → config-D2YUlzrl.js} +1 -1
- package/dist/cli/{config-WKDixoGK.js → config-EjNj3HfT.js} +1 -1
- package/dist/cli/{config-BVfeG3A5.js → config-KvV-sLZL.js} +290 -10
- package/dist/cli/{content-mapper-hUW2nb92.js → content-mapper-ez_mT0d4.js} +2 -2
- package/dist/cli/{db-DwjyUbAh.js → db-uYN6O5Eg.js} +38 -14
- package/dist/cli/{doctor-D3WKFBSv.js → doctor-BD9oo4MG.js} +31 -28
- package/dist/cli/{env-DMgjB_4y.js → env-BK0xKMeU.js} +1 -2
- package/dist/cli/{env-C-Bl6Awn.js → env-Bat6ogep.js} +1 -1
- package/dist/cli/env-Cy2lWBRC.js +1 -0
- package/dist/cli/{env-BCgVZkcb.js → env-DEAtgGoj.js} +2 -2
- package/dist/cli/{exec--Q1ZEWUW.js → exec-Ca5s-ygi.js} +1 -1
- package/dist/cli/{gen-CqsUdsB2.js → gen-8Ya8n2sA.js} +16 -16
- package/dist/cli/in-stack-diff-Cp-tVPj2.js +186 -0
- package/dist/cli/index.d.ts +1 -2
- package/dist/cli/index.js +8 -8
- package/dist/cli/{init-DryZ5Mp1.js → init-DgL3sDfQ.js} +118 -11
- package/dist/cli/{keys-CbaL0lnw.js → keys-CsanNk-2.js} +1 -1
- package/dist/cli/{live-Di45imoV.js → live-CMMEct_F.js} +2 -2
- package/dist/cli/{mcp-BklC-3eK.js → mcp-DEHtzAkq.js} +4 -4
- package/dist/cli/{metadata-7PsBF5Xw.js → metadata-BZh-cOzC.js} +3 -3
- package/dist/cli/migrate-sVs1QYTM.js +306 -0
- package/dist/cli/{migration-safety-Doy9qYO8.js → migration-safety-ClnYNMdq.js} +2 -2
- package/dist/cli/migrations-DWh38tO9.js +117 -0
- package/dist/cli/{module-migration-ZIn1NCMi.js → module-migration-CXfRJIV4.js} +2 -2
- package/dist/cli/{moved-DVwgE8lV.js → moved-Cnb4fp49.js} +1 -1
- package/dist/cli/{parse-B079x40m.js → parse-BWM6IGhF.js} +1 -1
- package/dist/cli/powersync-DURhWDVc.js +1 -0
- package/dist/cli/{powersync-BRGXOCJ0.js → powersync-Dnyr-Wy5.js} +4 -3
- package/dist/cli/{print-Dfqd4DB-.js → print-DJrSr56b.js} +2 -2
- package/dist/cli/{migrations-JtsPYv8g.js → providers-CpaISitn.js} +4 -116
- package/dist/cli/{remove-CQzSCYTu.js → remove-ChaieK3t.js} +6 -6
- package/dist/cli/{render-DWRz-uPQ.js → render-DUNJ4Pss.js} +8 -5
- package/dist/cli/{run-DPLedqTF.js → run-ChCQPYOh.js} +41 -39
- package/dist/cli/{run-j54rk2w-.js → run-Cl9COGuy.js} +10 -10
- package/dist/cli/{run-DmOTMa44.js → run-CxFDjL1Q.js} +4 -4
- package/dist/cli/seed-BJ7c-ktX.js +1 -0
- package/dist/cli/{seed-BMynpMPy.js → seed-BzVLTdRl.js} +3 -3
- package/dist/cli/{shared-CslNcs-R.js → shared-5uqc1GBj.js} +1 -1
- package/dist/cli/{skills-FXAVPLzp.js → skills-0gz_qjVb.js} +1 -1
- package/dist/cli/{snapshot-DdN5GlhH.js → snapshot-DdAP7LWO.js} +3 -3
- package/dist/cli/{source-COARbqch.js → source-2irbWSck.js} +1 -1
- package/dist/cli/{source-args-CDmmFmFG.js → source-args-DAcQt-Mh.js} +1 -1
- package/dist/cli/{spec-CgLNZc_C.js → spec-B7n4Rthp.js} +3 -3
- package/dist/cli/{spec-DIhBQlBF.js → spec-_MS0ym5r.js} +1 -1
- package/dist/cli/{sql-layout-8jrP5gIa.js → sql-layout-DYKkQw1k.js} +21 -7
- package/dist/cli/{stack-DgASZP0K.js → stack-CteM33gC.js} +3 -3
- package/dist/cli/{stack-status-B_Ipd_-z.js → stack-status-BkkYRlXG.js} +1 -1
- package/dist/cli/{stacks-BYlQ96WS.js → stacks-CiDBH1dB.js} +1 -1
- package/dist/cli/{sync-SqyVHRSJ.js → sync-DnSOrQuA.js} +4 -3
- package/dist/cli/table-DeH8X0qz.js +89 -0
- package/dist/cli/{upgrade-CY-vj_qh.js → upgrade-CWdrC-K3.js} +5 -4
- package/dist/cli/{upgrade-D0aLhluU.js → upgrade-cMy5fKkg.js} +3 -3
- package/dist/cli/{version-Bhca9D6q.js → version-C5RAWmrD.js} +1 -1
- package/dist/client/index.d.ts +5 -5
- package/dist/client/native/index.d.ts +4 -4
- package/dist/config/index.d.ts +3 -3
- package/dist/config/index.js +4 -4
- package/dist/{config-CP-WaboC.js → config-CTeR7XHK.js} +3 -3
- package/dist/{config-C19McoGo.js → config-CvJHIy5q.js} +1 -1
- package/dist/{context-BJoHD20l.d.ts → context-BFEX0b7H.d.ts} +106 -3
- package/dist/{controller-CwGXms17.d.ts → controller-Cl6HmMBk.d.ts} +1 -1
- package/dist/create/index.d.ts +62 -3
- package/dist/create/index.js +67 -4
- package/dist/create/lite/index.d.ts +140 -3
- package/dist/create/lite/index.js +399 -47
- package/dist/{entitlements-CsZcfllV.d.ts → entitlements-Y-n4RGAd.d.ts} +1 -1
- package/dist/{field-errors-6BVg31Yp.d.ts → field-errors-Btn3czyz.d.ts} +4 -4
- package/dist/{index-Cagz4Z2k.d.ts → index-8wOL81rB.d.ts} +1 -1
- package/dist/{index-D01wHGSN.d.ts → index-C0_cweyT.d.ts} +6 -6
- package/dist/{index-CbUCGMqj.d.ts → index-CAY7rIQs.d.ts} +2 -2
- package/dist/{index-DOHx3JuB.d.ts → index-DPMVWm_Z.d.ts} +2 -2
- package/dist/{index-C0QuN9_P.d.ts → index-k-SyCzcQ.d.ts} +104 -119
- package/dist/{instances-qz2MCMyK.js → instances-C7qUTjhJ.js} +1 -1
- package/dist/mapper/bin.js +7 -7
- package/dist/mcp/index.d.ts +1 -1
- package/dist/next/index.d.ts +3 -3
- package/dist/{operations-CPhOcuzl.d.ts → operations-DE7SOBw-.d.ts} +1 -1
- package/dist/{options-BOGo1qCA.js → options-B5E2MGIz.js} +3 -1
- package/dist/{options-D2s7fT1s.js → options-COo7_3MX.js} +2 -1
- package/dist/{options-D32-YxnO.js → options-DhoLMknl.js} +3 -1
- package/dist/otel/index.js +4 -4
- package/dist/{ports-Bw7uxPd_.d.ts → ports-DP0bthUk.d.ts} +1 -1
- package/dist/powersync/index.d.ts +2 -2
- package/dist/preset/index.d.ts +3 -3
- package/dist/preset/index.js +3 -3
- package/dist/{preset-BbSWLoXM.js → preset-DwuWNBip.js} +2 -2
- package/dist/{project-TN03XDsA.js → project-Bo1vZqVs.js} +5 -5
- package/dist/{push-token-vykw2JXT.d.ts → push-token-v3xCcVU7.d.ts} +1 -1
- package/dist/react/index.d.ts +5 -5
- package/dist/react/native/index.d.ts +1 -1
- package/dist/react/server.d.ts +5 -5
- package/dist/realtime/index.d.ts +3 -3
- package/dist/realtime/index.js +1 -1
- package/dist/records/index.d.ts +3 -3
- package/dist/{resolved-names-Dsf28_Dr.js → resolved-names-iLBOUaib.js} +2 -2
- package/dist/server/index.d.ts +1 -1
- package/dist/solid/index.d.ts +5 -5
- package/dist/sql/index.d.ts +5 -5
- package/dist/sql/index.js +5 -5
- package/dist/{sql-Dg3W1ENk.js → sql-B7vBP9g0.js} +3577 -1246
- package/dist/ssr/index.d.ts +1 -1
- package/dist/storage/index.js +1 -1
- package/dist/{subjects-NomQg6Eg.d.ts → subjects-BYCL-6hA.d.ts} +15 -1
- package/dist/svelte/index.d.ts +5 -5
- package/dist/{tenant-BRmKZ7aq.d.ts → tenant-CyLEXgot.d.ts} +1 -1
- package/dist/testing/index.d.ts +3 -3
- package/dist/testing/index.js +2 -2
- package/dist/{topic-CpsKVBot.d.ts → topic-B_DGdAEs.d.ts} +1 -1
- package/dist/{topic-F0FKzJyQ.js → topic-DnsNG4Kj.js} +1 -1
- package/dist/{types-CjRwmCRP.d.ts → types-DF8JYEf5.d.ts} +2 -2
- package/dist/vue/index.d.ts +5 -5
- package/dist/{watch-topic-BaMZX139.d.ts → watch-topic-1zIAtiNM.d.ts} +1 -1
- package/dist/workflow-sdk/world/index.js +1 -1
- package/dist/{workflow-sdk-CE8sEK57.js → workflow-sdk-CaEw822d.js} +25 -4
- package/dist/yjs/index.d.ts +1 -1
- package/dist/yjs/index.js +1 -1
- package/package.json +11 -1
- package/schemas/config-v1.json +42 -0
- package/dist/cli/add-Bf1fyCWm.js +0 -1
- package/dist/cli/env-xhwXk5Ri.js +0 -1
- package/dist/cli/in-stack-diff-DQTW53Vf.js +0 -257
- package/dist/cli/powersync-Dq-txa0_.js +0 -1
- package/dist/cli/seed-CO3j_bly.js +0 -1
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import { p as commandMeta, r as defineCliCommand } from "./command-CVzTJSLp.js";
|
|
2
|
+
import { i as plain } from "./style-Bm2X5JrN.js";
|
|
3
|
+
import { n as CliError } from "./errors-BTe6A15O.js";
|
|
4
|
+
import { h as subjectTagArgs } from "./config-KvV-sLZL.js";
|
|
5
|
+
import { r as layoutFor } from "./providers-CpaISitn.js";
|
|
6
|
+
import { d as readSupabaseToml, n as declarativeSchemasDir } from "./supabase-toml-CncmQbO0.js";
|
|
7
|
+
import { n as PLAN_ARGS, r as applyPlan, u as planResult } from "./files-CX71yBm8.js";
|
|
8
|
+
import { join, resolve, sep } from "node:path";
|
|
9
|
+
import { APP_TABLES_MODULE, renderBlocks, setTableFeature } from "better-supabase/sql";
|
|
10
|
+
//#region src/cli/sql/schema-first.ts
|
|
11
|
+
const NAME = String.raw`(?:"?public"?\.)?"?([a-z_][a-z0-9_]*)"?`;
|
|
12
|
+
const TABLE_TARGETS = [
|
|
13
|
+
new RegExp(String.raw`^create\s+table\s+(?:if\s+not\s+exists\s+)?${NAME}`, "iu"),
|
|
14
|
+
new RegExp(String.raw`^alter\s+table\s+(?:if\s+exists\s+)?(?:only\s+)?${NAME}`, "iu"),
|
|
15
|
+
new RegExp(String.raw`^create\s+(?:unique\s+)?index\s+(?:if\s+not\s+exists\s+)?\S+\s+on\s+(?:only\s+)?${NAME}`, "iu"),
|
|
16
|
+
new RegExp(String.raw`^create\s+policy\s+(?:"[^"]+"|\S+)\s+on\s+${NAME}`, "iu"),
|
|
17
|
+
new RegExp(String.raw`^drop\s+policy\s+(?:if\s+exists\s+)?(?:"[^"]+"|\S+)\s+on\s+${NAME}`, "iu"),
|
|
18
|
+
new RegExp(String.raw`^create\s+(?:or\s+replace\s+)?(?:constraint\s+)?trigger\s+\S+[\s\S]*?\son\s+${NAME}\s`, "iu"),
|
|
19
|
+
new RegExp(String.raw`^(?:grant|revoke)\s[\s\S]*?\son\s+(?:table\s+)?${NAME}\s+(?:to|from)\s`, "iu"),
|
|
20
|
+
new RegExp(String.raw`^comment\s+on\s+table\s+${NAME}\s+is`, "iu"),
|
|
21
|
+
new RegExp(String.raw`^drop\s+trigger\s+(?:if\s+exists\s+)?\S+\s+on\s+${NAME}`, "iu")
|
|
22
|
+
];
|
|
23
|
+
/** Statements about a view that sit next to its `create view`. */
|
|
24
|
+
const VIEW_TARGETS = [
|
|
25
|
+
new RegExp(String.raw`^(?:grant|revoke)\s[\s\S]*?\son\s+(?:table\s+)?${NAME}\s+(?:to|from)\s`, "iu"),
|
|
26
|
+
new RegExp(String.raw`^comment\s+on\s+view\s+${NAME}\s+is`, "iu"),
|
|
27
|
+
new RegExp(String.raw`^alter\s+view\s+(?:if\s+exists\s+)?${NAME}`, "iu")
|
|
28
|
+
];
|
|
29
|
+
const DROP_VIEW = new RegExp(String.raw`^drop\s+view\s+(?:if\s+exists\s+)?${NAME}`, "iu");
|
|
30
|
+
const VIEW = new RegExp(String.raw`^create\s+(?:or\s+replace\s+)?view\s+${NAME}`, "iu");
|
|
31
|
+
/** The statement without its leading comment lines. */
|
|
32
|
+
function bare(statement) {
|
|
33
|
+
return statement.replace(LEADING_COMMENTS, "").trim();
|
|
34
|
+
}
|
|
35
|
+
const LEADING_COMMENTS = /^(?:\s*--[^\n]*\n)+/u;
|
|
36
|
+
const DOLLAR_TAG = /^\$[A-Za-z_]*\$/u;
|
|
37
|
+
/**
|
|
38
|
+
* The statements of `sql`, split at semicolons outside quotes, dollar quotes
|
|
39
|
+
* and comments.
|
|
40
|
+
*/
|
|
41
|
+
function statements(sql) {
|
|
42
|
+
const found = [];
|
|
43
|
+
let start = 0;
|
|
44
|
+
let at = 0;
|
|
45
|
+
while (at < sql.length) {
|
|
46
|
+
const char = sql[at];
|
|
47
|
+
if (char === "-" && sql[at + 1] === "-") {
|
|
48
|
+
const end = sql.indexOf("\n", at);
|
|
49
|
+
at = end === -1 ? sql.length : end;
|
|
50
|
+
} else if (char === "/" && sql[at + 1] === "*") {
|
|
51
|
+
const end = sql.indexOf("*/", at + 2);
|
|
52
|
+
at = end === -1 ? sql.length : end + 2;
|
|
53
|
+
} else if (char === "'" || char === "\"") {
|
|
54
|
+
let end = at + 1;
|
|
55
|
+
while (end < sql.length && sql[end] !== char) end += 1;
|
|
56
|
+
at = end + 1;
|
|
57
|
+
} else if (char === "$") {
|
|
58
|
+
const tag = DOLLAR_TAG.exec(sql.slice(at))?.[0];
|
|
59
|
+
if (tag === void 0) at += 1;
|
|
60
|
+
else {
|
|
61
|
+
const end = sql.indexOf(tag, at + tag.length);
|
|
62
|
+
at = end === -1 ? sql.length : end + tag.length;
|
|
63
|
+
}
|
|
64
|
+
} else if (char === ";") {
|
|
65
|
+
found.push(sql.slice(start, at + 1));
|
|
66
|
+
start = at + 1;
|
|
67
|
+
at += 1;
|
|
68
|
+
} else at += 1;
|
|
69
|
+
}
|
|
70
|
+
if (sql.slice(start).trim() !== "") found.push(sql.slice(start));
|
|
71
|
+
return found;
|
|
72
|
+
}
|
|
73
|
+
/** The table or view a statement belongs to, or undefined for anything else. */
|
|
74
|
+
function targetOf(statement, tables, views) {
|
|
75
|
+
const text = statement;
|
|
76
|
+
for (const pattern of TABLE_TARGETS) {
|
|
77
|
+
const name = pattern.exec(text)?.[1];
|
|
78
|
+
if (name !== void 0 && tables.has(name)) return {
|
|
79
|
+
kind: "table",
|
|
80
|
+
name
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
const dropped = DROP_VIEW.exec(text)?.[1];
|
|
84
|
+
if (dropped !== void 0 && views.has(dropped)) return {
|
|
85
|
+
kind: "dropped",
|
|
86
|
+
name: dropped
|
|
87
|
+
};
|
|
88
|
+
for (const pattern of VIEW_TARGETS) {
|
|
89
|
+
const name = pattern.exec(text)?.[1];
|
|
90
|
+
if (name !== void 0 && views.has(name)) return {
|
|
91
|
+
kind: "view",
|
|
92
|
+
name
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
const view = VIEW.exec(text)?.[1];
|
|
96
|
+
return view === void 0 ? void 0 : {
|
|
97
|
+
kind: "view",
|
|
98
|
+
name: view
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* The tags `config` implies for `table`: `subject`, `realtime`,
|
|
103
|
+
* `vector-search`, `json`, `encrypted`, `server` and `events`. `audit`,
|
|
104
|
+
* `audit-reads` and `expose` change the table's SQL only, which the split keeps
|
|
105
|
+
* as written.
|
|
106
|
+
*/
|
|
107
|
+
function tagsFor(config, table) {
|
|
108
|
+
const tags = [];
|
|
109
|
+
for (const [type, subject] of Object.entries(config.subjects)) if (subject.table === table || subject.table === `public.${table}`) {
|
|
110
|
+
const args = subjectTagArgs(type, subject, table);
|
|
111
|
+
if (args !== void 0) tags.push({
|
|
112
|
+
feature: "subject",
|
|
113
|
+
tag: {
|
|
114
|
+
name: "subject",
|
|
115
|
+
args
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
if (config.realtime.tables.some((each) => each === table || each === `public.${table}`)) {
|
|
120
|
+
const user = config.realtime.users[table];
|
|
121
|
+
tags.push({
|
|
122
|
+
feature: "realtime",
|
|
123
|
+
tag: {
|
|
124
|
+
name: "realtime",
|
|
125
|
+
args: {
|
|
126
|
+
...config.realtime.global.includes(table) ? { global: true } : {},
|
|
127
|
+
...user === void 0 ? {} : { user }
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
const vector = config.vectorSearch.find((each) => each.table === table || each.table === `public.${table}`);
|
|
133
|
+
if (vector !== void 0) tags.push({
|
|
134
|
+
feature: "vector-search",
|
|
135
|
+
tag: {
|
|
136
|
+
name: "vector-search",
|
|
137
|
+
args: {
|
|
138
|
+
column: vector.column,
|
|
139
|
+
distance: vector.distance
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
const jsonArgs = {};
|
|
144
|
+
for (const [key, entry] of Object.entries(config.json)) {
|
|
145
|
+
const column = [`${table}.`, `public.${table}.`].map((prefix) => key.startsWith(prefix) ? key.slice(prefix.length) : "").find((name) => name !== "" && !name.includes("."));
|
|
146
|
+
if (column !== void 0) jsonArgs[column] = "import" in entry ? `import:${entry.import}` : entry.type;
|
|
147
|
+
}
|
|
148
|
+
if (Object.keys(jsonArgs).length > 0) tags.push({
|
|
149
|
+
feature: "json",
|
|
150
|
+
tag: {
|
|
151
|
+
name: "json",
|
|
152
|
+
args: jsonArgs
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
const app = config.appTables[table];
|
|
156
|
+
const sealed = Object.entries(app?.columns ?? {}).flatMap(([name, column]) => column.encrypted === true ? [[name, column.type]] : []);
|
|
157
|
+
if (sealed.length > 0) tags.push({
|
|
158
|
+
feature: "encrypted",
|
|
159
|
+
tag: {
|
|
160
|
+
name: "encrypted",
|
|
161
|
+
args: Object.fromEntries(sealed)
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
const hidden = Object.entries(app?.columns ?? {}).flatMap(([name, column]) => column.access === "server" ? [name] : []);
|
|
165
|
+
if (hidden.length > 0) tags.push({
|
|
166
|
+
feature: "server",
|
|
167
|
+
tag: {
|
|
168
|
+
name: "server",
|
|
169
|
+
args: Object.fromEntries(hidden.map((name) => [name, true]))
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
const events = app?.events;
|
|
173
|
+
if (events !== void 0) {
|
|
174
|
+
const on = events === true ? void 0 : events.on;
|
|
175
|
+
const include = events === true ? void 0 : events.include;
|
|
176
|
+
tags.push({
|
|
177
|
+
feature: "events",
|
|
178
|
+
tag: {
|
|
179
|
+
name: "events",
|
|
180
|
+
args: {
|
|
181
|
+
...on === void 0 ? {} : { on: on.join(", ") },
|
|
182
|
+
...include === void 0 ? {} : { include: include.join(", ") }
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
return tags;
|
|
188
|
+
}
|
|
189
|
+
function header(text) {
|
|
190
|
+
return `-- ${text}\n`;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Splits the rendered app tables file into the pg-delta export layout (ADR
|
|
194
|
+
* 0102): `public/tables/<name>.sql` holds a table's create, columns, keys,
|
|
195
|
+
* policies, grants, indexes and triggers, with the table's `@bsb` tags in its
|
|
196
|
+
* comment; `public/views/<name>.sql` holds each view; every other statement
|
|
197
|
+
* goes to `public/_custom/app_tables.sql`. Statements keep their order within a
|
|
198
|
+
* file. `tables` is the app table names.
|
|
199
|
+
*/
|
|
200
|
+
function splitAppTables(config, sql, tables) {
|
|
201
|
+
const known = new Set(tables);
|
|
202
|
+
const all = statements(sql).map((raw) => bare(raw));
|
|
203
|
+
const views = new Set(all.flatMap((statement) => {
|
|
204
|
+
const name = VIEW.exec(statement)?.[1];
|
|
205
|
+
return name === void 0 ? [] : [name];
|
|
206
|
+
}));
|
|
207
|
+
const byTable = /* @__PURE__ */ new Map();
|
|
208
|
+
const byView = /* @__PURE__ */ new Map();
|
|
209
|
+
const rest = [];
|
|
210
|
+
for (const statement of all) {
|
|
211
|
+
if (statement === "") continue;
|
|
212
|
+
const target = targetOf(statement, known, views);
|
|
213
|
+
if (target === void 0) rest.push(statement);
|
|
214
|
+
else if (target.kind !== "dropped") {
|
|
215
|
+
const group = target.kind === "table" ? byTable : byView;
|
|
216
|
+
group.set(target.name, [...group.get(target.name) ?? [], statement]);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
const files = [];
|
|
220
|
+
for (const name of tables) {
|
|
221
|
+
const body = `${(byTable.get(name) ?? []).join("\n\n")}\n`;
|
|
222
|
+
const tagged = tagsFor(config, name).reduce((text, { feature, tag }) => setTableFeature(text, "public", name, feature, true, tag), body);
|
|
223
|
+
files.push({
|
|
224
|
+
path: `public/tables/${name}.sql`,
|
|
225
|
+
contents: `${header("Owned by you since `better-supabase migrate schema-first`.")}${tagged}`
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
for (const [name, statements] of byView) files.push({
|
|
229
|
+
path: `public/views/${name}.sql`,
|
|
230
|
+
contents: `${statements.join("\n\n")}\n`
|
|
231
|
+
});
|
|
232
|
+
if (rest.length > 0) files.push({
|
|
233
|
+
path: "public/_custom/app_tables.sql",
|
|
234
|
+
contents: `${header("Statements of the old app tables file that belong to no single table.")}${rest.join("\n\n")}\n`
|
|
235
|
+
});
|
|
236
|
+
return files;
|
|
237
|
+
}
|
|
238
|
+
//#endregion
|
|
239
|
+
//#region src/cli/commands/migrate.ts
|
|
240
|
+
const MIGRATE_ARGS = {};
|
|
241
|
+
/**
|
|
242
|
+
* The deepest directory that holds both paths. A project in a monorepo keeps
|
|
243
|
+
* its `supabase` folder above its own root, and the plan may not leave `root`.
|
|
244
|
+
*/
|
|
245
|
+
function commonAncestor(first, second) {
|
|
246
|
+
const left = resolve(first).split(sep);
|
|
247
|
+
const right = resolve(second).split(sep);
|
|
248
|
+
const shared = [];
|
|
249
|
+
for (const [index, part] of left.entries()) {
|
|
250
|
+
if (part !== right[index]) break;
|
|
251
|
+
shared.push(part);
|
|
252
|
+
}
|
|
253
|
+
return shared.join(sep) || sep;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Writes the tables that `appTables` renders as files you own under
|
|
257
|
+
* `supabase/schemas` (ADR 0102), with the config's per-table features as `@bsb`
|
|
258
|
+
* tags in each table's comment. The config keeps working until you delete
|
|
259
|
+
* `appTables`, so run `upgrade` after removing it.
|
|
260
|
+
*/
|
|
261
|
+
async function runMigrateSchemaFirst(config, args, deps = {}) {
|
|
262
|
+
const tables = Object.keys(config.appTables);
|
|
263
|
+
if (tables.length === 0) return {
|
|
264
|
+
code: 0,
|
|
265
|
+
output: "appTables is empty; there are no tables to move.",
|
|
266
|
+
data: {
|
|
267
|
+
tables: [],
|
|
268
|
+
files: []
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
const layout = await layoutFor(config, {}, config.blockNames);
|
|
272
|
+
const source = renderBlocks(config.blockNames, layout).find((file) => file.module === APP_TABLES_MODULE && file.kind === "schema");
|
|
273
|
+
if (source === void 0) throw new CliError("usage", "The config renders no app tables file.");
|
|
274
|
+
const dir = join(config.root, declarativeSchemasDir(await readSupabaseToml(config.root)));
|
|
275
|
+
const files = splitAppTables(config, source.contents, tables);
|
|
276
|
+
const plan = {
|
|
277
|
+
root: commonAncestor(config.root, dir),
|
|
278
|
+
base: config.root,
|
|
279
|
+
regenerate: "better-supabase migrate schema-first",
|
|
280
|
+
files: files.map((file) => ({
|
|
281
|
+
path: join(dir, file.path),
|
|
282
|
+
contents: file.contents,
|
|
283
|
+
policy: "create"
|
|
284
|
+
}))
|
|
285
|
+
};
|
|
286
|
+
const applied = await applyPlan(plan, args, deps.paint ?? plain);
|
|
287
|
+
const summary = applied.mode === "write" && applied.drift ? `Wrote ${String(files.length)} files for ${String(tables.length)} tables. Delete appTables (and records) from the config, run \`better-supabase upgrade\` to remove the old app tables file, then \`better-supabase db diff\` to check that the schema is unchanged.` : void 0;
|
|
288
|
+
return planResult(plan, applied, {
|
|
289
|
+
data: {
|
|
290
|
+
tables,
|
|
291
|
+
files: files.map((file) => file.path)
|
|
292
|
+
},
|
|
293
|
+
...summary === void 0 ? {} : { summary }
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
const migrateSchemaFirstCommand = defineCliCommand({
|
|
297
|
+
meta: commandMeta("migrate schema-first"),
|
|
298
|
+
args: {
|
|
299
|
+
...MIGRATE_ARGS,
|
|
300
|
+
"dry-run": PLAN_ARGS["dry-run"],
|
|
301
|
+
check: PLAN_ARGS.check
|
|
302
|
+
},
|
|
303
|
+
run: (args, { config, paint }) => runMigrateSchemaFirst(config, args, { paint })
|
|
304
|
+
});
|
|
305
|
+
//#endregion
|
|
306
|
+
export { migrateSchemaFirstCommand };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { f as INTEGRATIONS } from "./config-
|
|
2
|
-
import { c as splitStatements } from "./shared-
|
|
1
|
+
import { f as INTEGRATIONS } from "./config-KvV-sLZL.js";
|
|
2
|
+
import { c as splitStatements } from "./shared-5uqc1GBj.js";
|
|
3
3
|
import { dirname, join, posix } from "node:path";
|
|
4
4
|
import { readdir } from "node:fs/promises";
|
|
5
5
|
import { INTEGRATION_INFO, groupEntries } from "better-supabase/config";
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { r as layoutFor } from "./providers-CpaISitn.js";
|
|
2
|
+
import { d as readSupabaseToml, p as sqlWorkflow } from "./supabase-toml-CncmQbO0.js";
|
|
3
|
+
import { i as changeLines, r as applyPlan } from "./files-CX71yBm8.js";
|
|
4
|
+
import { a as sqlPlan, n as migrationsDir } from "./sql-layout-DYKkQw1k.js";
|
|
5
|
+
import { resolve } from "node:path";
|
|
6
|
+
import { readFile, readdir } from "node:fs/promises";
|
|
7
|
+
import { moduleSchemaExtensions, renderBlocks } from "better-supabase/sql";
|
|
8
|
+
//#region src/cli/sql/migrations.ts
|
|
9
|
+
/** `YYYYMMDDHHMMSS` in UTC, the Supabase CLI's migration prefix. */
|
|
10
|
+
const migrationStamp = (now) => now.toISOString().replaceAll(/[-:T]/g, "").slice(0, 14);
|
|
11
|
+
/**
|
|
12
|
+
* A stamp for `now`, or one second after the newest migration when that one has
|
|
13
|
+
* the same stamp or a later one: the Supabase CLI keys migrations by stamp, and
|
|
14
|
+
* the data has to run after the schema.
|
|
15
|
+
*/
|
|
16
|
+
function stampAfter(migrations, now) {
|
|
17
|
+
const newest = migrations.map((name) => /^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(?!\d)/.exec(name)).filter((match) => match !== null).map((match) => Date.UTC(Number(match[1]), Number(match[2]) - 1, Number(match[3]), Number(match[4]), Number(match[5]), Number(match[6]))).reduce((max, time) => Math.max(max, time), Number.NEGATIVE_INFINITY);
|
|
18
|
+
const at = Math.floor(now.getTime() / 1e3) * 1e3;
|
|
19
|
+
return migrationStamp(new Date(Math.max(at, newest + 1e3)));
|
|
20
|
+
}
|
|
21
|
+
const EXTENSIONS_SUFFIX = "_better_supabase_extensions.sql";
|
|
22
|
+
const MIGRATION_EXTENSION = /^\s*create\s+extension\s+(?:if\s+not\s+exists\s+)?"?([a-z_][a-z0-9_]*)"?/gim;
|
|
23
|
+
async function unmigratedExtensions(config, files) {
|
|
24
|
+
const dir = migrationsDir(config);
|
|
25
|
+
const existing = await readdir(resolve(config.root, dir)).catch(() => []);
|
|
26
|
+
const created = /* @__PURE__ */ new Set();
|
|
27
|
+
for (const name of existing) {
|
|
28
|
+
if (!name.endsWith(".sql") || name.endsWith(DATA_SUFFIX)) continue;
|
|
29
|
+
const text = await readFile(resolve(config.root, dir, name), "utf-8");
|
|
30
|
+
for (const match of text.matchAll(MIGRATION_EXTENSION)) created.add(match[1].toLowerCase());
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
dir,
|
|
34
|
+
existing,
|
|
35
|
+
missing: moduleSchemaExtensions(files).filter((extension) => !created.has(extension.name))
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
async function writeExtensionsMigration(config, files, dryRun, now) {
|
|
39
|
+
const { dir, existing, missing } = await unmigratedExtensions(config, files);
|
|
40
|
+
if (missing.length === 0) return [];
|
|
41
|
+
const path = `${dir}/${stampAfter(existing, /* @__PURE__ */ new Date(now().getTime() - 1e3))}${EXTENSIONS_SUFFIX}`;
|
|
42
|
+
const applied = await applyPlan(sqlPlan(config, {
|
|
43
|
+
regenerate: "better-supabase upgrade",
|
|
44
|
+
files: [{
|
|
45
|
+
path,
|
|
46
|
+
contents: `-- better-supabase sql: the extensions of ${missing.map((extension) => extension.name).join(", ")}, created before the schema migration that needs them.\n\n${missing.map((extension) => extension.statement).join("\n")}\n`
|
|
47
|
+
}]
|
|
48
|
+
}), { "dry-run": dryRun });
|
|
49
|
+
return [...changeLines(applied), ...dryRun ? [] : ["It creates the extensions the module schemas need, so create the schema migration after it."]];
|
|
50
|
+
}
|
|
51
|
+
const DATA_NEXT = "The better-supabase-data files hold rows and settings a schema diff skips: after the schema migration, run `better-supabase add --adopt`.";
|
|
52
|
+
const DATA_SUFFIX = "_better_supabase_module_data.sql";
|
|
53
|
+
/**
|
|
54
|
+
* A migration without its comment lines, so a reworded comment needs no new
|
|
55
|
+
* one.
|
|
56
|
+
*/
|
|
57
|
+
const statements = (sql) => sql.split("\n").filter((line) => !line.trimStart().startsWith("--")).join("\n").replaceAll(/\n{2,}/g, "\n").trim();
|
|
58
|
+
/**
|
|
59
|
+
* Writes the data files of `blocks` into one migration, meant to run after the
|
|
60
|
+
* schema migration that creates their tables. Every statement is idempotent, so
|
|
61
|
+
* the migration carries all of them, not only the changes.
|
|
62
|
+
*/
|
|
63
|
+
async function dataMigration(config, args, now) {
|
|
64
|
+
if (config.blockNames.length === 0) return {
|
|
65
|
+
code: 0,
|
|
66
|
+
output: "blocks is empty; nothing to write.",
|
|
67
|
+
data: { wrote: false }
|
|
68
|
+
};
|
|
69
|
+
if (sqlWorkflow(config, await readSupabaseToml(config.root)) === "migrations") return {
|
|
70
|
+
code: 0,
|
|
71
|
+
output: "database.sql.workflow is 'migrations', so `better-supabase upgrade` already writes the rows into the module migration; nothing to write.",
|
|
72
|
+
data: { wrote: false }
|
|
73
|
+
};
|
|
74
|
+
const rendered = renderBlocks(config.blockNames, await layoutFor(config, args, config.blockNames));
|
|
75
|
+
const { missing } = await unmigratedExtensions(config, rendered);
|
|
76
|
+
if (missing.length > 0) return {
|
|
77
|
+
code: 1,
|
|
78
|
+
error: [`No migration before the data migration creates ${missing.map((extension) => extension.name).join(", ")}, and the schema migration needs ${missing.length === 1 ? "it" : "them"} while it applies.`, "Run `better-supabase upgrade` to write the extensions migration, then create the schema migration again after it."].join("\n")
|
|
79
|
+
};
|
|
80
|
+
const files = rendered.filter((file) => file.kind === "data");
|
|
81
|
+
const contents = `-- better-supabase add --adopt: the rows and settings of ${files.map((file) => file.module).join(", ")}, which a schema diff skips.\n\nset lock_timeout = '5s';\n\n${files.map((file) => file.contents.trim()).join("\n\n")}\n`;
|
|
82
|
+
const dir = migrationsDir(config);
|
|
83
|
+
const existing = await readdir(resolve(config.root, dir)).catch(() => []);
|
|
84
|
+
const latest = existing.toSorted().findLast((name) => name.endsWith(DATA_SUFFIX));
|
|
85
|
+
if (latest !== void 0 && statements(await readFile(resolve(config.root, dir, latest), "utf-8")) === statements(contents)) return {
|
|
86
|
+
code: 0,
|
|
87
|
+
output: `${dir}/${latest} already has these rows; nothing to write.`,
|
|
88
|
+
data: {
|
|
89
|
+
file: `${dir}/${latest}`,
|
|
90
|
+
wrote: false
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
if (args.check === true) return {
|
|
94
|
+
code: 1,
|
|
95
|
+
error: `${latest === void 0 ? "No data migration holds" : `${dir}/${latest} doesn't hold`} the current rows and settings of the blocks. Run \`better-supabase add --adopt\` after the schema migration.`,
|
|
96
|
+
data: { wrote: false }
|
|
97
|
+
};
|
|
98
|
+
const path = `${dir}/${stampAfter(existing, now())}${DATA_SUFFIX}`;
|
|
99
|
+
const applied = await applyPlan(sqlPlan(config, {
|
|
100
|
+
regenerate: "better-supabase add --adopt",
|
|
101
|
+
files: [{
|
|
102
|
+
path,
|
|
103
|
+
contents
|
|
104
|
+
}]
|
|
105
|
+
}), { "dry-run": args["dry-run"] });
|
|
106
|
+
return {
|
|
107
|
+
code: 0,
|
|
108
|
+
output: changeLines(applied).join("\n"),
|
|
109
|
+
data: {
|
|
110
|
+
file: path,
|
|
111
|
+
wrote: applied.mode === "write",
|
|
112
|
+
files: applied.changes
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
//#endregion
|
|
117
|
+
export { writeExtensionsMigration as a, stampAfter as i, dataMigration as n, migrationStamp as r, DATA_NEXT as t };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { i as stampAfter } from "./migrations-JtsPYv8g.js";
|
|
2
1
|
import { d as readSupabaseToml, p as sqlWorkflow } from "./supabase-toml-CncmQbO0.js";
|
|
3
2
|
import { i as changeLines, r as applyPlan } from "./files-CX71yBm8.js";
|
|
4
|
-
import { a as sqlPlan, n as migrationsDir } from "./sql-layout-
|
|
3
|
+
import { a as sqlPlan, n as migrationsDir } from "./sql-layout-DYKkQw1k.js";
|
|
4
|
+
import { i as stampAfter } from "./migrations-DWh38tO9.js";
|
|
5
5
|
import { resolve } from "node:path";
|
|
6
6
|
import { readFile, readdir } from "node:fs/promises";
|
|
7
7
|
import { moduleSchemaExtensions } from "better-supabase/sql";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as CliError } from "./errors-BTe6A15O.js";
|
|
2
|
-
import { s as positionalIndex } from "./parse-
|
|
2
|
+
import { s as positionalIndex } from "./parse-BWM6IGhF.js";
|
|
3
3
|
//#region src/cli/core/moved.ts
|
|
4
4
|
const API_REPLACEMENT = "defineApi includes every table and block instance, and createOrpc(betterSupabase).router(api) serves it: https://bettersupabase.com/docs/frameworks/orpc#serve-the-api";
|
|
5
5
|
/** Commands removed in 0.15, with what replaces them, longest path first. */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { r as __toESM } from "./rolldown-runtime-kJ_i4yPo.js";
|
|
2
|
-
import { t as GLOBAL_ARGS } from "./command-
|
|
2
|
+
import { t as GLOBAL_ARGS } from "./command-CVzTJSLp.js";
|
|
3
3
|
import { n as CliError } from "./errors-BTe6A15O.js";
|
|
4
4
|
//#region src/cli/core/parse.ts
|
|
5
5
|
/**
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { t as powersyncStreamsCommand } from "./powersync-Dnyr-Wy5.js";
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { p as commandMeta, r as defineCliCommand } from "./command-
|
|
2
|
-
import {
|
|
1
|
+
import { p as commandMeta, r as defineCliCommand } from "./command-CVzTJSLp.js";
|
|
2
|
+
import { r as layoutFor } from "./providers-CpaISitn.js";
|
|
3
3
|
import { n as PLAN_ARGS, r as applyPlan, u as planResult } from "./files-CX71yBm8.js";
|
|
4
|
-
import { n as migrationsDir } from "./sql-layout-
|
|
4
|
+
import { n as migrationsDir } from "./sql-layout-DYKkQw1k.js";
|
|
5
|
+
import { i as stampAfter } from "./migrations-DWh38tO9.js";
|
|
5
6
|
import { existsSync } from "node:fs";
|
|
6
7
|
import { join, resolve } from "node:path";
|
|
7
8
|
import { readFile, readdir } from "node:fs/promises";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as CliError } from "./errors-BTe6A15O.js";
|
|
2
|
-
import {
|
|
3
|
-
import { o as migrationModules, r as latestMigration, u as writesMigrations } from "./module-migration-
|
|
2
|
+
import { n as layout } from "./providers-CpaISitn.js";
|
|
3
|
+
import { o as migrationModules, r as latestMigration, u as writesMigrations } from "./module-migration-CXfRJIV4.js";
|
|
4
4
|
import { existsSync } from "node:fs";
|
|
5
5
|
import { resolve } from "node:path";
|
|
6
6
|
import { SQL_MODULES, contractSignature, customContracts, moduleBody, moduleFilePaths } from "better-supabase/sql";
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { n as CliError } from "./errors-BTe6A15O.js";
|
|
2
|
-
import { d as readSupabaseToml, p as sqlWorkflow } from "./supabase-toml-CncmQbO0.js";
|
|
3
2
|
import { t as importFresh } from "./fresh-import-DzgsGHkX.js";
|
|
4
|
-
import { i as
|
|
5
|
-
import { a as sqlPlan, i as schemasDirOf, n as migrationsDir, r as moduleLayoutFor } from "./sql-layout-8jrP5gIa.js";
|
|
3
|
+
import { i as schemasDirOf, r as moduleLayoutFor } from "./sql-layout-DYKkQw1k.js";
|
|
6
4
|
import { resolve } from "node:path";
|
|
7
|
-
import {
|
|
8
|
-
import { MODULE_ID_TYPES, compileReadSets, moduleIdType, moduleLayout, modulePermissionKeys, moduleSchemaExtensions, renderBlocks, resolveBlocks, scopeProblems, templateFunctions } from "better-supabase/sql";
|
|
5
|
+
import { MODULE_ID_TYPES, compileReadSets, moduleIdType, moduleLayout, modulePermissionKeys, resolveBlocks, scopeProblems, templateFunctions } from "better-supabase/sql";
|
|
9
6
|
import { isReadSet } from "better-supabase";
|
|
10
7
|
//#region src/cli/authorization.ts
|
|
11
8
|
/** How findings name the provider. */
|
|
@@ -265,7 +262,7 @@ function accessProviderFor(config, names) {
|
|
|
265
262
|
case "off": return;
|
|
266
263
|
case "provider": {
|
|
267
264
|
if (!renders || !config.authorization) return mode.access;
|
|
268
|
-
const problems = moduleKeyProblems(config.authorization, modulePermissionKeys(config.blocks, names));
|
|
265
|
+
const problems = moduleKeyProblems(config.authorization, modulePermissionKeys(config.blocks, names, config.subjects));
|
|
269
266
|
if (problems.length > 0) throw new TypeError(problems.map((problem) => problem.message).join("\n"));
|
|
270
267
|
return mode.access;
|
|
271
268
|
}
|
|
@@ -301,113 +298,4 @@ async function layoutFor(config, args, names) {
|
|
|
301
298
|
});
|
|
302
299
|
}
|
|
303
300
|
//#endregion
|
|
304
|
-
|
|
305
|
-
/** `YYYYMMDDHHMMSS` in UTC, the Supabase CLI's migration prefix. */
|
|
306
|
-
const migrationStamp = (now) => now.toISOString().replaceAll(/[-:T]/g, "").slice(0, 14);
|
|
307
|
-
/**
|
|
308
|
-
* A stamp for `now`, or one second after the newest migration when that one has
|
|
309
|
-
* the same stamp or a later one: the Supabase CLI keys migrations by stamp, and
|
|
310
|
-
* the data has to run after the schema.
|
|
311
|
-
*/
|
|
312
|
-
function stampAfter(migrations, now) {
|
|
313
|
-
const newest = migrations.map((name) => /^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(?!\d)/.exec(name)).filter((match) => match !== null).map((match) => Date.UTC(Number(match[1]), Number(match[2]) - 1, Number(match[3]), Number(match[4]), Number(match[5]), Number(match[6]))).reduce((max, time) => Math.max(max, time), Number.NEGATIVE_INFINITY);
|
|
314
|
-
const at = Math.floor(now.getTime() / 1e3) * 1e3;
|
|
315
|
-
return migrationStamp(new Date(Math.max(at, newest + 1e3)));
|
|
316
|
-
}
|
|
317
|
-
const EXTENSIONS_SUFFIX = "_better_supabase_extensions.sql";
|
|
318
|
-
const MIGRATION_EXTENSION = /^\s*create\s+extension\s+(?:if\s+not\s+exists\s+)?"?([a-z_][a-z0-9_]*)"?/gim;
|
|
319
|
-
async function unmigratedExtensions(config, files) {
|
|
320
|
-
const dir = migrationsDir(config);
|
|
321
|
-
const existing = await readdir(resolve(config.root, dir)).catch(() => []);
|
|
322
|
-
const created = /* @__PURE__ */ new Set();
|
|
323
|
-
for (const name of existing) {
|
|
324
|
-
if (!name.endsWith(".sql") || name.endsWith(DATA_SUFFIX)) continue;
|
|
325
|
-
const text = await readFile(resolve(config.root, dir, name), "utf-8");
|
|
326
|
-
for (const match of text.matchAll(MIGRATION_EXTENSION)) created.add(match[1].toLowerCase());
|
|
327
|
-
}
|
|
328
|
-
return {
|
|
329
|
-
dir,
|
|
330
|
-
existing,
|
|
331
|
-
missing: moduleSchemaExtensions(files).filter((extension) => !created.has(extension.name))
|
|
332
|
-
};
|
|
333
|
-
}
|
|
334
|
-
async function writeExtensionsMigration(config, files, dryRun, now) {
|
|
335
|
-
const { dir, existing, missing } = await unmigratedExtensions(config, files);
|
|
336
|
-
if (missing.length === 0) return [];
|
|
337
|
-
const path = `${dir}/${stampAfter(existing, /* @__PURE__ */ new Date(now().getTime() - 1e3))}${EXTENSIONS_SUFFIX}`;
|
|
338
|
-
const applied = await applyPlan(sqlPlan(config, {
|
|
339
|
-
regenerate: "better-supabase upgrade",
|
|
340
|
-
files: [{
|
|
341
|
-
path,
|
|
342
|
-
contents: `-- better-supabase sql: the extensions of ${missing.map((extension) => extension.name).join(", ")}, created before the schema migration that needs them.\n\n${missing.map((extension) => extension.statement).join("\n")}\n`
|
|
343
|
-
}]
|
|
344
|
-
}), { "dry-run": dryRun });
|
|
345
|
-
return [...changeLines(applied), ...dryRun ? [] : ["It creates the extensions the module schemas need, so create the schema migration after it."]];
|
|
346
|
-
}
|
|
347
|
-
const DATA_NEXT = "The better-supabase-data files hold rows and settings a schema diff skips: after the schema migration, run `better-supabase add --adopt`.";
|
|
348
|
-
const DATA_SUFFIX = "_better_supabase_module_data.sql";
|
|
349
|
-
/**
|
|
350
|
-
* A migration without its comment lines, so a reworded comment needs no new
|
|
351
|
-
* one.
|
|
352
|
-
*/
|
|
353
|
-
const statements = (sql) => sql.split("\n").filter((line) => !line.trimStart().startsWith("--")).join("\n").replaceAll(/\n{2,}/g, "\n").trim();
|
|
354
|
-
/**
|
|
355
|
-
* Writes the data files of `blocks` into one migration, meant to run after the
|
|
356
|
-
* schema migration that creates their tables. Every statement is idempotent, so
|
|
357
|
-
* the migration carries all of them, not only the changes.
|
|
358
|
-
*/
|
|
359
|
-
async function dataMigration(config, args, now) {
|
|
360
|
-
if (config.blockNames.length === 0) return {
|
|
361
|
-
code: 0,
|
|
362
|
-
output: "blocks is empty; nothing to write.",
|
|
363
|
-
data: { wrote: false }
|
|
364
|
-
};
|
|
365
|
-
if (sqlWorkflow(config, await readSupabaseToml(config.root)) === "migrations") return {
|
|
366
|
-
code: 0,
|
|
367
|
-
output: "database.sql.workflow is 'migrations', so `better-supabase upgrade` already writes the rows into the module migration; nothing to write.",
|
|
368
|
-
data: { wrote: false }
|
|
369
|
-
};
|
|
370
|
-
const rendered = renderBlocks(config.blockNames, await layoutFor(config, args, config.blockNames));
|
|
371
|
-
const { missing } = await unmigratedExtensions(config, rendered);
|
|
372
|
-
if (missing.length > 0) return {
|
|
373
|
-
code: 1,
|
|
374
|
-
error: [`No migration before the data migration creates ${missing.map((extension) => extension.name).join(", ")}, and the schema migration needs ${missing.length === 1 ? "it" : "them"} while it applies.`, "Run `better-supabase upgrade` to write the extensions migration, then create the schema migration again after it."].join("\n")
|
|
375
|
-
};
|
|
376
|
-
const files = rendered.filter((file) => file.kind === "data");
|
|
377
|
-
const contents = `-- better-supabase add --adopt: the rows and settings of ${files.map((file) => file.module).join(", ")}, which a schema diff skips.\n\nset lock_timeout = '5s';\n\n${files.map((file) => file.contents.trim()).join("\n\n")}\n`;
|
|
378
|
-
const dir = migrationsDir(config);
|
|
379
|
-
const existing = await readdir(resolve(config.root, dir)).catch(() => []);
|
|
380
|
-
const latest = existing.toSorted().findLast((name) => name.endsWith(DATA_SUFFIX));
|
|
381
|
-
if (latest !== void 0 && statements(await readFile(resolve(config.root, dir, latest), "utf-8")) === statements(contents)) return {
|
|
382
|
-
code: 0,
|
|
383
|
-
output: `${dir}/${latest} already has these rows; nothing to write.`,
|
|
384
|
-
data: {
|
|
385
|
-
file: `${dir}/${latest}`,
|
|
386
|
-
wrote: false
|
|
387
|
-
}
|
|
388
|
-
};
|
|
389
|
-
if (args.check === true) return {
|
|
390
|
-
code: 1,
|
|
391
|
-
error: `${latest === void 0 ? "No data migration holds" : `${dir}/${latest} doesn't hold`} the current rows and settings of the blocks. Run \`better-supabase add --adopt\` after the schema migration.`,
|
|
392
|
-
data: { wrote: false }
|
|
393
|
-
};
|
|
394
|
-
const path = `${dir}/${stampAfter(existing, now())}${DATA_SUFFIX}`;
|
|
395
|
-
const applied = await applyPlan(sqlPlan(config, {
|
|
396
|
-
regenerate: "better-supabase add --adopt",
|
|
397
|
-
files: [{
|
|
398
|
-
path,
|
|
399
|
-
contents
|
|
400
|
-
}]
|
|
401
|
-
}), { "dry-run": args["dry-run"] });
|
|
402
|
-
return {
|
|
403
|
-
code: 0,
|
|
404
|
-
output: changeLines(applied).join("\n"),
|
|
405
|
-
data: {
|
|
406
|
-
file: path,
|
|
407
|
-
wrote: applied.mode === "write",
|
|
408
|
-
files: applied.changes
|
|
409
|
-
}
|
|
410
|
-
};
|
|
411
|
-
}
|
|
412
|
-
//#endregion
|
|
413
|
-
export { unsafeKey as _, writeExtensionsMigration as a, layoutFor as c, accessProviderMode as d, accessRequirements as f, providerLabel as g, moduleKeyProblems as h, stampAfter as i, providerOwnsMemberships as l, entitlementsMode as m, dataMigration as n, MEMBERSHIP_CLAIM_MODULES as o, entitlementRequirements as p, migrationStamp as r, layout as s, DATA_NEXT as t, compiledReadSets as u };
|
|
301
|
+
export { compiledReadSets as a, entitlementRequirements as c, providerLabel as d, unsafeKey as f, providerOwnsMemberships as i, entitlementsMode as l, layout as n, accessProviderMode as o, layoutFor as r, accessRequirements as s, MEMBERSHIP_CLAIM_MODULES as t, moduleKeyProblems as u };
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { p as commandMeta, r as defineCliCommand } from "./command-
|
|
1
|
+
import { p as commandMeta, r as defineCliCommand } from "./command-CVzTJSLp.js";
|
|
2
2
|
import { i as plain } from "./style-Bm2X5JrN.js";
|
|
3
3
|
import { n as CliError } from "./errors-BTe6A15O.js";
|
|
4
4
|
import { r as readIfExists, t as display } from "./io-DH1kcmmP.js";
|
|
5
|
-
import {
|
|
5
|
+
import { r as layoutFor } from "./providers-CpaISitn.js";
|
|
6
6
|
import { i as changeLines, n as PLAN_ARGS, r as applyPlan, t as HAND_EDITED, u as planResult } from "./files-CX71yBm8.js";
|
|
7
|
-
import { a as sqlPlan } from "./sql-layout-
|
|
8
|
-
import { g as templateContextFor, i as blocksWiringPath, n as blockClients } from "./add-
|
|
7
|
+
import { a as sqlPlan } from "./sql-layout-DYKkQw1k.js";
|
|
8
|
+
import { g as templateContextFor, i as blocksWiringPath, n as blockClients } from "./add-DUyg9qna.js";
|
|
9
9
|
import { t as detectProject } from "./detect-D9JaAX20.js";
|
|
10
10
|
import { _ as wiringBlocks, a as configObject, c as mask, i as closingIndex, l as properties } from "./config-edit-CrWfk8s3.js";
|
|
11
|
-
import { n as guardedRemoval } from "./sync-
|
|
11
|
+
import { n as guardedRemoval } from "./sync-DnSOrQuA.js";
|
|
12
12
|
import { t as SQL_ARGS } from "./args-UEwg0l-N.js";
|
|
13
|
-
import { t as blockNames } from "./blocks-
|
|
13
|
+
import { t as blockNames } from "./blocks-k1OG8XDs.js";
|
|
14
14
|
import { i as tidyInline, t as cutRange } from "./config-group-C8tjut39.js";
|
|
15
15
|
import { existsSync } from "node:fs";
|
|
16
16
|
import { resolve } from "node:path";
|