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.
Files changed (180) hide show
  1. package/dist/{access-sql-bjWFUWlk.js → access-sql-CTDNuxRv.js} +177 -12
  2. package/dist/ai-sdk/agents/index.d.ts +2 -2
  3. package/dist/{app-tables-xij_MI5H.d.ts → app-tables-62GqZIhd.d.ts} +1 -1
  4. package/dist/{authorization-BJV2i8xB.d.ts → authorization-BCG1v0iC.d.ts} +24 -3
  5. package/dist/{bind-vKDmdu_4.d.ts → bind-C54jD0r3.d.ts} +1 -1
  6. package/dist/{block-env-wVLz0KMV.d.ts → block-env-CM-LFfj4.d.ts} +3 -3
  7. package/dist/blocks/ai-chat/index.d.ts +3 -3
  8. package/dist/blocks/announcements/index.d.ts +3 -3
  9. package/dist/blocks/api-keys/index.d.ts +1 -1
  10. package/dist/blocks/attachments/index.d.ts +1 -1
  11. package/dist/blocks/audit/index.d.ts +2 -2
  12. package/dist/blocks/automations/index.d.ts +1 -1
  13. package/dist/blocks/billing/index.d.ts +1 -1
  14. package/dist/blocks/bookings/index.d.ts +1 -1
  15. package/dist/blocks/calendar/index.d.ts +1 -1
  16. package/dist/blocks/comments/index.d.ts +4 -4
  17. package/dist/blocks/custom-fields/index.js +1 -1
  18. package/dist/blocks/drive/index.d.ts +1 -1
  19. package/dist/blocks/employees/index.js +1 -1
  20. package/dist/blocks/entitlements/index.d.ts +2 -2
  21. package/dist/blocks/forms/index.d.ts +1 -1
  22. package/dist/blocks/inbox/index.d.ts +4 -4
  23. package/dist/blocks/index.d.ts +1 -1
  24. package/dist/blocks/messaging/index.d.ts +4 -4
  25. package/dist/blocks/mfa/index.d.ts +1 -1
  26. package/dist/blocks/notifications/index.d.ts +3 -3
  27. package/dist/blocks/onboarding/index.d.ts +1 -1
  28. package/dist/blocks/organizations/index.d.ts +2 -2
  29. package/dist/blocks/permissions/index.d.ts +1 -1
  30. package/dist/blocks/push/index.d.ts +1 -1
  31. package/dist/blocks/reactions/index.d.ts +3 -3
  32. package/dist/blocks/reminders/index.d.ts +1 -1
  33. package/dist/blocks/saved-views/index.d.ts +1 -1
  34. package/dist/blocks/search/index.d.ts +2 -2
  35. package/dist/blocks/sessions/index.d.ts +1 -1
  36. package/dist/blocks/settings/index.d.ts +1 -1
  37. package/dist/blocks/subjects/index.d.ts +1 -1
  38. package/dist/blocks/tags/index.d.ts +1 -1
  39. package/dist/blocks/tasks/index.d.ts +1 -1
  40. package/dist/blocks/tasks/index.js +1 -1
  41. package/dist/blocks/undo/index.d.ts +1 -1
  42. package/dist/blocks/usage/index.d.ts +1 -1
  43. package/dist/blocks/workflow-editor/index.d.ts +3 -3
  44. package/dist/blocks/workflows/index.d.ts +3 -3
  45. package/dist/cli/{add-C2pNvVpu.js → add-BKcE_g9D.js} +2 -2
  46. package/dist/cli/{add-BTVrOGJF.js → add-DUyg9qna.js} +40 -15
  47. package/dist/cli/add-pDOlqWUa.js +1 -0
  48. package/dist/cli/{backfill-BicVPugb.js → backfill-r9RELEEh.js} +4 -4
  49. package/dist/cli/bin.js +1 -1
  50. package/dist/cli/{blocks-sScN-ik-.js → blocks-DTOFdrxL.js} +1 -1
  51. package/dist/cli/{blocks-BmYOH4T-.js → blocks-k1OG8XDs.js} +2 -2
  52. package/dist/cli/{cache-1TfBy2K4.js → cache-Czfw7Iow.js} +1 -1
  53. package/dist/cli/{codemod-ylE6wGLo.js → codemod-ClmbiLuL.js} +3 -3
  54. package/dist/cli/{command-BWEEXmtz.js → command-CVzTJSLp.js} +31 -0
  55. package/dist/cli/{completion-8EDK21xj.js → completion-CNCqE-Gb.js} +1 -1
  56. package/dist/cli/{completion-BfnKI4QZ.js → completion-Dpk6vh0p.js} +2 -2
  57. package/dist/cli/{completion-Bt7LMypX.js → completion-DxEXxFpz.js} +2 -2
  58. package/dist/cli/{config-CeaQMrvS.js → config-D2YUlzrl.js} +1 -1
  59. package/dist/cli/{config-WKDixoGK.js → config-EjNj3HfT.js} +1 -1
  60. package/dist/cli/{config-BVfeG3A5.js → config-KvV-sLZL.js} +290 -10
  61. package/dist/cli/{content-mapper-hUW2nb92.js → content-mapper-ez_mT0d4.js} +2 -2
  62. package/dist/cli/{db-DwjyUbAh.js → db-uYN6O5Eg.js} +38 -14
  63. package/dist/cli/{doctor-D3WKFBSv.js → doctor-BD9oo4MG.js} +31 -28
  64. package/dist/cli/{env-DMgjB_4y.js → env-BK0xKMeU.js} +1 -2
  65. package/dist/cli/{env-C-Bl6Awn.js → env-Bat6ogep.js} +1 -1
  66. package/dist/cli/env-Cy2lWBRC.js +1 -0
  67. package/dist/cli/{env-BCgVZkcb.js → env-DEAtgGoj.js} +2 -2
  68. package/dist/cli/{exec--Q1ZEWUW.js → exec-Ca5s-ygi.js} +1 -1
  69. package/dist/cli/{gen-CqsUdsB2.js → gen-8Ya8n2sA.js} +16 -16
  70. package/dist/cli/in-stack-diff-Cp-tVPj2.js +186 -0
  71. package/dist/cli/index.d.ts +1 -2
  72. package/dist/cli/index.js +8 -8
  73. package/dist/cli/{init-DryZ5Mp1.js → init-DgL3sDfQ.js} +118 -11
  74. package/dist/cli/{keys-CbaL0lnw.js → keys-CsanNk-2.js} +1 -1
  75. package/dist/cli/{live-Di45imoV.js → live-CMMEct_F.js} +2 -2
  76. package/dist/cli/{mcp-BklC-3eK.js → mcp-DEHtzAkq.js} +4 -4
  77. package/dist/cli/{metadata-7PsBF5Xw.js → metadata-BZh-cOzC.js} +3 -3
  78. package/dist/cli/migrate-sVs1QYTM.js +306 -0
  79. package/dist/cli/{migration-safety-Doy9qYO8.js → migration-safety-ClnYNMdq.js} +2 -2
  80. package/dist/cli/migrations-DWh38tO9.js +117 -0
  81. package/dist/cli/{module-migration-ZIn1NCMi.js → module-migration-CXfRJIV4.js} +2 -2
  82. package/dist/cli/{moved-DVwgE8lV.js → moved-Cnb4fp49.js} +1 -1
  83. package/dist/cli/{parse-B079x40m.js → parse-BWM6IGhF.js} +1 -1
  84. package/dist/cli/powersync-DURhWDVc.js +1 -0
  85. package/dist/cli/{powersync-BRGXOCJ0.js → powersync-Dnyr-Wy5.js} +4 -3
  86. package/dist/cli/{print-Dfqd4DB-.js → print-DJrSr56b.js} +2 -2
  87. package/dist/cli/{migrations-JtsPYv8g.js → providers-CpaISitn.js} +4 -116
  88. package/dist/cli/{remove-CQzSCYTu.js → remove-ChaieK3t.js} +6 -6
  89. package/dist/cli/{render-DWRz-uPQ.js → render-DUNJ4Pss.js} +8 -5
  90. package/dist/cli/{run-DPLedqTF.js → run-ChCQPYOh.js} +41 -39
  91. package/dist/cli/{run-j54rk2w-.js → run-Cl9COGuy.js} +10 -10
  92. package/dist/cli/{run-DmOTMa44.js → run-CxFDjL1Q.js} +4 -4
  93. package/dist/cli/seed-BJ7c-ktX.js +1 -0
  94. package/dist/cli/{seed-BMynpMPy.js → seed-BzVLTdRl.js} +3 -3
  95. package/dist/cli/{shared-CslNcs-R.js → shared-5uqc1GBj.js} +1 -1
  96. package/dist/cli/{skills-FXAVPLzp.js → skills-0gz_qjVb.js} +1 -1
  97. package/dist/cli/{snapshot-DdN5GlhH.js → snapshot-DdAP7LWO.js} +3 -3
  98. package/dist/cli/{source-COARbqch.js → source-2irbWSck.js} +1 -1
  99. package/dist/cli/{source-args-CDmmFmFG.js → source-args-DAcQt-Mh.js} +1 -1
  100. package/dist/cli/{spec-CgLNZc_C.js → spec-B7n4Rthp.js} +3 -3
  101. package/dist/cli/{spec-DIhBQlBF.js → spec-_MS0ym5r.js} +1 -1
  102. package/dist/cli/{sql-layout-8jrP5gIa.js → sql-layout-DYKkQw1k.js} +21 -7
  103. package/dist/cli/{stack-DgASZP0K.js → stack-CteM33gC.js} +3 -3
  104. package/dist/cli/{stack-status-B_Ipd_-z.js → stack-status-BkkYRlXG.js} +1 -1
  105. package/dist/cli/{stacks-BYlQ96WS.js → stacks-CiDBH1dB.js} +1 -1
  106. package/dist/cli/{sync-SqyVHRSJ.js → sync-DnSOrQuA.js} +4 -3
  107. package/dist/cli/table-DeH8X0qz.js +89 -0
  108. package/dist/cli/{upgrade-CY-vj_qh.js → upgrade-CWdrC-K3.js} +5 -4
  109. package/dist/cli/{upgrade-D0aLhluU.js → upgrade-cMy5fKkg.js} +3 -3
  110. package/dist/cli/{version-Bhca9D6q.js → version-C5RAWmrD.js} +1 -1
  111. package/dist/client/index.d.ts +5 -5
  112. package/dist/client/native/index.d.ts +4 -4
  113. package/dist/config/index.d.ts +3 -3
  114. package/dist/config/index.js +4 -4
  115. package/dist/{config-CP-WaboC.js → config-CTeR7XHK.js} +3 -3
  116. package/dist/{config-C19McoGo.js → config-CvJHIy5q.js} +1 -1
  117. package/dist/{context-BJoHD20l.d.ts → context-BFEX0b7H.d.ts} +106 -3
  118. package/dist/{controller-CwGXms17.d.ts → controller-Cl6HmMBk.d.ts} +1 -1
  119. package/dist/create/index.d.ts +62 -3
  120. package/dist/create/index.js +67 -4
  121. package/dist/create/lite/index.d.ts +140 -3
  122. package/dist/create/lite/index.js +399 -47
  123. package/dist/{entitlements-CsZcfllV.d.ts → entitlements-Y-n4RGAd.d.ts} +1 -1
  124. package/dist/{field-errors-6BVg31Yp.d.ts → field-errors-Btn3czyz.d.ts} +4 -4
  125. package/dist/{index-Cagz4Z2k.d.ts → index-8wOL81rB.d.ts} +1 -1
  126. package/dist/{index-D01wHGSN.d.ts → index-C0_cweyT.d.ts} +6 -6
  127. package/dist/{index-CbUCGMqj.d.ts → index-CAY7rIQs.d.ts} +2 -2
  128. package/dist/{index-DOHx3JuB.d.ts → index-DPMVWm_Z.d.ts} +2 -2
  129. package/dist/{index-C0QuN9_P.d.ts → index-k-SyCzcQ.d.ts} +104 -119
  130. package/dist/{instances-qz2MCMyK.js → instances-C7qUTjhJ.js} +1 -1
  131. package/dist/mapper/bin.js +7 -7
  132. package/dist/mcp/index.d.ts +1 -1
  133. package/dist/next/index.d.ts +3 -3
  134. package/dist/{operations-CPhOcuzl.d.ts → operations-DE7SOBw-.d.ts} +1 -1
  135. package/dist/{options-BOGo1qCA.js → options-B5E2MGIz.js} +3 -1
  136. package/dist/{options-D2s7fT1s.js → options-COo7_3MX.js} +2 -1
  137. package/dist/{options-D32-YxnO.js → options-DhoLMknl.js} +3 -1
  138. package/dist/otel/index.js +4 -4
  139. package/dist/{ports-Bw7uxPd_.d.ts → ports-DP0bthUk.d.ts} +1 -1
  140. package/dist/powersync/index.d.ts +2 -2
  141. package/dist/preset/index.d.ts +3 -3
  142. package/dist/preset/index.js +3 -3
  143. package/dist/{preset-BbSWLoXM.js → preset-DwuWNBip.js} +2 -2
  144. package/dist/{project-TN03XDsA.js → project-Bo1vZqVs.js} +5 -5
  145. package/dist/{push-token-vykw2JXT.d.ts → push-token-v3xCcVU7.d.ts} +1 -1
  146. package/dist/react/index.d.ts +5 -5
  147. package/dist/react/native/index.d.ts +1 -1
  148. package/dist/react/server.d.ts +5 -5
  149. package/dist/realtime/index.d.ts +3 -3
  150. package/dist/realtime/index.js +1 -1
  151. package/dist/records/index.d.ts +3 -3
  152. package/dist/{resolved-names-Dsf28_Dr.js → resolved-names-iLBOUaib.js} +2 -2
  153. package/dist/server/index.d.ts +1 -1
  154. package/dist/solid/index.d.ts +5 -5
  155. package/dist/sql/index.d.ts +5 -5
  156. package/dist/sql/index.js +5 -5
  157. package/dist/{sql-Dg3W1ENk.js → sql-B7vBP9g0.js} +3577 -1246
  158. package/dist/ssr/index.d.ts +1 -1
  159. package/dist/storage/index.js +1 -1
  160. package/dist/{subjects-NomQg6Eg.d.ts → subjects-BYCL-6hA.d.ts} +15 -1
  161. package/dist/svelte/index.d.ts +5 -5
  162. package/dist/{tenant-BRmKZ7aq.d.ts → tenant-CyLEXgot.d.ts} +1 -1
  163. package/dist/testing/index.d.ts +3 -3
  164. package/dist/testing/index.js +2 -2
  165. package/dist/{topic-CpsKVBot.d.ts → topic-B_DGdAEs.d.ts} +1 -1
  166. package/dist/{topic-F0FKzJyQ.js → topic-DnsNG4Kj.js} +1 -1
  167. package/dist/{types-CjRwmCRP.d.ts → types-DF8JYEf5.d.ts} +2 -2
  168. package/dist/vue/index.d.ts +5 -5
  169. package/dist/{watch-topic-BaMZX139.d.ts → watch-topic-1zIAtiNM.d.ts} +1 -1
  170. package/dist/workflow-sdk/world/index.js +1 -1
  171. package/dist/{workflow-sdk-CE8sEK57.js → workflow-sdk-CaEw822d.js} +25 -4
  172. package/dist/yjs/index.d.ts +1 -1
  173. package/dist/yjs/index.js +1 -1
  174. package/package.json +11 -1
  175. package/schemas/config-v1.json +42 -0
  176. package/dist/cli/add-Bf1fyCWm.js +0 -1
  177. package/dist/cli/env-xhwXk5Ri.js +0 -1
  178. package/dist/cli/in-stack-diff-DQTW53Vf.js +0 -257
  179. package/dist/cli/powersync-Dq-txa0_.js +0 -1
  180. package/dist/cli/seed-CO3j_bly.js +0 -1
@@ -1,22 +1,22 @@
1
- import { a as list, p as commandMeta, r as defineCliCommand } from "./command-BWEEXmtz.js";
1
+ import { a as list, p as commandMeta, r as defineCliCommand } from "./command-CVzTJSLp.js";
2
2
  import { i as plain } from "./style-Bm2X5JrN.js";
3
3
  import { a as parseNames, i as failedResult, n as CliError } from "./errors-BTe6A15O.js";
4
- import { u as catalogFingerprint } from "./cache-1TfBy2K4.js";
5
- import { a as serializeSnapshot, g as serializeGenerator, h as restrictSchemas, o as snapshotFile, r as openSource, t as loadSnapshot } from "./snapshot-DdN5GlhH.js";
6
- import { n as dataMigration } from "./migrations-JtsPYv8g.js";
7
- import { d as GEN_TASKS, p as isGenTask } from "./config-BVfeG3A5.js";
4
+ import { u as catalogFingerprint } from "./cache-Czfw7Iow.js";
5
+ import { a as serializeSnapshot, g as serializeGenerator, h as restrictSchemas, o as snapshotFile, r as openSource, t as loadSnapshot } from "./snapshot-DdAP7LWO.js";
6
+ import { d as GEN_TASKS, p as isGenTask } from "./config-KvV-sLZL.js";
8
7
  import { c as insideRoot, r as applyPlan, u as planResult } from "./files-CX71yBm8.js";
9
- import { n as runGen } from "./run-j54rk2w-.js";
10
- import { t as syncModules } from "./sync-SqyVHRSJ.js";
11
- import { t as addModules } from "./add-C2pNvVpu.js";
12
- import { n as listModules, t as printModule } from "./print-Dfqd4DB-.js";
13
- import { a as sourceFlags, i as sourceArgs, n as SOURCE_ARGS } from "./source-args-CDmmFmFG.js";
14
- import { a as runMetadataGen, n as checkMetadataFlags, t as EMITS } from "./metadata-7PsBF5Xw.js";
15
- import { a as runEnv } from "./env-BCgVZkcb.js";
16
- import { c as watchLoop, o as parseInterval, r as specOptionsFromConfig, s as stampFiles, t as runSpec } from "./spec-CgLNZc_C.js";
17
- import { n as runPowerSync } from "./powersync-BRGXOCJ0.js";
18
- import { t as runSeed } from "./seed-BMynpMPy.js";
19
- import { t as upgrade } from "./upgrade-CY-vj_qh.js";
8
+ import { n as runGen } from "./run-Cl9COGuy.js";
9
+ import { n as dataMigration } from "./migrations-DWh38tO9.js";
10
+ import { t as syncModules } from "./sync-DnSOrQuA.js";
11
+ import { t as addModules } from "./add-BKcE_g9D.js";
12
+ import { n as listModules, t as printModule } from "./print-DJrSr56b.js";
13
+ import { a as sourceFlags, i as sourceArgs, n as SOURCE_ARGS } from "./source-args-DAcQt-Mh.js";
14
+ import { a as runMetadataGen, n as checkMetadataFlags, t as EMITS } from "./metadata-BZh-cOzC.js";
15
+ import { a as runEnv } from "./env-DEAtgGoj.js";
16
+ import { c as watchLoop, o as parseInterval, r as specOptionsFromConfig, s as stampFiles, t as runSpec } from "./spec-B7n4Rthp.js";
17
+ import { n as runPowerSync } from "./powersync-Dnyr-Wy5.js";
18
+ import { t as runSeed } from "./seed-BzVLTdRl.js";
19
+ import { t as upgrade } from "./upgrade-CWdrC-K3.js";
20
20
  import { existsSync } from "node:fs";
21
21
  import { resolve } from "node:path";
22
22
  //#region src/cli/commands/sql.ts
@@ -0,0 +1,186 @@
1
+ import { n as CliError } from "./errors-BTe6A15O.js";
2
+ import { t as connect } from "./db-CQCLx7cx.js";
3
+ import { basename, join } from "node:path";
4
+ import { readFile, readdir } from "node:fs/promises";
5
+ import { gatePlan } from "better-supabase/create";
6
+ //#region src/cli/in-stack-diff.ts
7
+ /**
8
+ * Schemas the platform owns. The declarative files may add policies to their
9
+ * tables (`storage.objects`), so those policies are dropped and replayed, but
10
+ * the schemas themselves are kept.
11
+ */
12
+ const PLATFORM_SCHEMAS = /* @__PURE__ */ new Set([
13
+ "_analytics",
14
+ "_realtime",
15
+ "auth",
16
+ "cron",
17
+ "extensions",
18
+ "graphql",
19
+ "graphql_public",
20
+ "information_schema",
21
+ "net",
22
+ "pgbouncer",
23
+ "pgmq",
24
+ "pgsodium",
25
+ "pgsodium_masks",
26
+ "pgtle",
27
+ "realtime",
28
+ "repack",
29
+ "storage",
30
+ "supabase_functions",
31
+ "supabase_migrations",
32
+ "tiger",
33
+ "tiger_data",
34
+ "topology",
35
+ "vault"
36
+ ]);
37
+ /** Why the Supabase CLI could not start its shadow database. */
38
+ const SHADOW_FAILURE = /could not create shared memory segment|No space left on device|shmget|shadow database/i;
39
+ function isShadowFailure(output) {
40
+ return SHADOW_FAILURE.test(output);
41
+ }
42
+ /** The migration versions (`<digits>_name.sql`) the stack has not applied. */
43
+ function pendingMigrations(files, applied) {
44
+ return files.filter((file) => {
45
+ const version = /^(\d+)_/.exec(basename(file))?.[1];
46
+ return version !== void 0 && !applied.has(version);
47
+ });
48
+ }
49
+ const MIGRATION_HEADER = `-- Generated by better-supabase db diff from the running stack with pg-delta.
50
+ -- The SQL compares two databases, so review it before you apply it: check
51
+ -- the order of the statements and drop the ones you didn't mean to change.
52
+ `;
53
+ /** UTC `YYYYMMDDHHMMSS`, the Supabase CLI's migration version. */
54
+ function migrationVersion(now) {
55
+ return now.toISOString().replaceAll(/[-:T]/g, "").slice(0, 14);
56
+ }
57
+ /**
58
+ * Pg-delta is an optional peer (with `@supabase/pg-topo`) that only `db diff`
59
+ * needs, so it loads on demand. Without it, `db diff` says how to install it.
60
+ */
61
+ async function loadPgDelta(load = () => import("@supabase/pg-delta")) {
62
+ try {
63
+ return await load();
64
+ } catch {
65
+ throw new CliError("dependency_missing", "better-supabase needs \"@supabase/pg-delta\" and \"@supabase/pg-topo\" to plan the diff. Install them: pnpm add -D @supabase/pg-delta @supabase/pg-topo", { suggestion: "pnpm add -D @supabase/pg-delta @supabase/pg-topo" });
66
+ }
67
+ }
68
+ /**
69
+ * `pg` is an optional peer that pg-delta shares; the pools it takes come from
70
+ * it.
71
+ */
72
+ async function openPgPool(url) {
73
+ try {
74
+ const mod = await import("pg");
75
+ const { Pool } = mod.default ?? mod;
76
+ return new Pool({ connectionString: url });
77
+ } catch {
78
+ throw new CliError("dependency_missing", "better-supabase needs the \"pg\" package to diff the schema. Install it: pnpm add -D pg", { suggestion: "pnpm add -D pg" });
79
+ }
80
+ }
81
+ async function appliedVersions(client) {
82
+ const rows = await client.query("select version from supabase_migrations.schema_migrations").then((result) => result.rows).catch(() => []);
83
+ return new Set(rows.map((row) => row.version));
84
+ }
85
+ function behindMessage(behind) {
86
+ return `The stack has not applied ${String(behind.length)} migration(s) (${behind.slice(0, 3).join(", ")}${behind.length > 3 ? ", ..." : ""}), so the diff would repeat them. Run supabase migration up, then diff again.`;
87
+ }
88
+ /** One SQL statement per action, each ended with a semicolon. */
89
+ function actionsSql(actions) {
90
+ return actions.map((action) => {
91
+ const sql = action.sql.trim();
92
+ return sql.endsWith(";") ? sql : `${sql};`;
93
+ }).join("\n\n");
94
+ }
95
+ /**
96
+ * Diffs the declarative schema against the running stack with pg-delta's
97
+ * library plan, connected as the stack's `postgres` role: objects owned by
98
+ * `supabase_admin` are invisible to pg-delta, so a shadow that role created
99
+ * would look empty. The plan: it creates a shadow database on the stack's
100
+ * cluster, loads the files into it, and plans the changes from the stack to the
101
+ * shadow. Renames are applied only when a hint confirms them, and destructive
102
+ * actions are blocked unless `allowDataLoss` is set. The shadow is always
103
+ * dropped.
104
+ */
105
+ async function inStackDiff(options) {
106
+ const open = options.open ?? connect;
107
+ const loadDelta = options.loadDelta ?? loadPgDelta;
108
+ const openPool = options.openPool ?? openPgPool;
109
+ const log = options.log ?? (() => {});
110
+ const main = await open(options.url);
111
+ try {
112
+ const behind = pendingMigrations(options.migrations, await appliedVersions(main.client));
113
+ if (behind.length > 0) throw new CliError("check_failed", behindMessage(behind), { suggestion: "supabase migration up" });
114
+ } finally {
115
+ await main.close();
116
+ }
117
+ const delta = await loadDelta();
118
+ const hints = options.hints ?? [];
119
+ const files = await Promise.all(options.files.map(async (file) => ({
120
+ name: file,
121
+ sql: await readFile(join(options.root, file), "utf-8")
122
+ })));
123
+ log("Creating a shadow database on the stack");
124
+ const shadow = await delta.provisionCoLocatedShadow(options.url).catch((cause) => {
125
+ throw new CliError("failed", cause instanceof Error ? cause.message : String(cause));
126
+ });
127
+ const target = await openPool(options.url);
128
+ const scratch = await openPool(shadow.url);
129
+ try {
130
+ const planFiles = (accept) => delta.planSchemaFiles(target, scratch, files, {
131
+ profile: delta.supabaseProfile,
132
+ renames: "prompt",
133
+ seedAssumedSchemas: true,
134
+ acceptRenames: accept
135
+ });
136
+ log(`Planning ${String(files.length)} schema file(s) with pg-delta`);
137
+ let result = await planFiles([]);
138
+ let gate = gatePlan(describePlan(delta, result.plan), {
139
+ hints,
140
+ allowDataLoss: options.allowDataLoss === true
141
+ });
142
+ if (gate.accepted.length > 0) {
143
+ result = await planFiles(result.plan.renameCandidates.filter((candidate) => gate.accepted.some((accepted) => accepted.from === delta.encodeId(candidate.from) && accepted.to === delta.encodeId(candidate.to))));
144
+ gate = gatePlan(describePlan(delta, result.plan), {
145
+ hints,
146
+ allowDataLoss: options.allowDataLoss === true
147
+ });
148
+ }
149
+ const sql = gate.blocked ? "" : actionsSql(result.plan.actions);
150
+ const diagnostics = [
151
+ ...result.loadDiagnostics,
152
+ ...result.targetDiagnostics,
153
+ ...result.driftDiagnostics
154
+ ];
155
+ return {
156
+ sql,
157
+ gate,
158
+ issues: gate.issues,
159
+ diagnostics,
160
+ skipped: result.skipped
161
+ };
162
+ } finally {
163
+ await Promise.allSettled([target.end(), scratch.end()]);
164
+ await shadow.cleanup();
165
+ }
166
+ }
167
+ /** The plan with stable ids written as strings, the shape `gatePlan` reads. */
168
+ function describePlan(delta, plan) {
169
+ return {
170
+ actions: plan.actions,
171
+ renameCandidates: plan.renameCandidates.map((candidate) => ({
172
+ kind: candidate.kind,
173
+ from: delta.encodeId(candidate.from),
174
+ to: delta.encodeId(candidate.to),
175
+ status: candidate.status,
176
+ ...candidate.reason === void 0 ? {} : { reason: candidate.reason }
177
+ }))
178
+ };
179
+ }
180
+ /** The migration files under `supabase/migrations`, relative to the root. */
181
+ async function migrationFiles(root, supabaseDir) {
182
+ const dir = join(supabaseDir, "migrations");
183
+ return (await readdir(join(root, dir)).catch(() => [])).filter((name) => name.endsWith(".sql")).toSorted().map((name) => join(dir, name));
184
+ }
185
+ //#endregion
186
+ export { migrationFiles as a, isShadowFailure as i, PLATFORM_SCHEMAS as n, migrationVersion as o, inStackDiff as r, MIGRATION_HEADER as t };
@@ -119,7 +119,6 @@ interface CliEnv {
119
119
  * The directory with `pg_dump` and `psql` for `db diff --in-stack`; found
120
120
  * from the stack's postmaster otherwise.
121
121
  */
122
- readonly BSB_PG_BIN?: string | undefined;
123
122
  /** Every variable of the run, for the processes the CLI starts. */
124
123
  readonly [PROCESS_ENV]?: Readonly<Record<string, string | undefined>>;
125
124
  }
@@ -798,6 +797,6 @@ export declare function emitModule(model: Model, options: EmitOptions): string;
798
797
  export declare function loadConfig(cwd: string, explicit?: string, environment?: string, path?: string | undefined): Promise<ResolvedConfig>;
799
798
  //#endregion
800
799
  //#region src/cli/version.d.ts
801
- export declare const VERSION = "0.25.0";
800
+ export declare const VERSION = "0.28.0";
802
801
  //#endregion
803
802
  export type { Catalog, CatalogCheck, CatalogColumn, CatalogColumnGrant, CatalogEnum, CatalogForeignKey, CatalogFunction, CatalogFunctionArg, CatalogGrant, CatalogIndex, CatalogPolicy, CatalogTable, CatalogTrigger, CatalogUnique, Choice, Cli, CliArgs, CliCommand, CliCommandDef, CliContext, CliEnv, CliErrorCode, CliErrorOptions, CliIo, CliLog, CliProblem, CliProblemExtensions, CommandResult, CreateCliOptions, ExitCode, ExtrasFunction, ExtrasHook, ExtrasHookFunction, ExtrasTable, ForeignKeyAction, Format, GeneratorMetadata, IntrospectionSource, ManagementSourceOptions, NextStep, Paint, Prompter, Queryable, RunOptions, RunResult, Snapshot, SnapshotBucket, SnapshotExtras };
package/dist/cli/index.js CHANGED
@@ -1,12 +1,12 @@
1
- import { a as list, r as defineCliCommand } from "./command-BWEEXmtz.js";
2
- import { i as run, n as createCli, r as help, t as commandNames } from "./run-DPLedqTF.js";
3
- import { t as VERSION } from "./version-Bhca9D6q.js";
1
+ import { a as list, r as defineCliCommand } from "./command-CVzTJSLp.js";
2
+ import { i as run, n as createCli, r as help, t as commandNames } from "./run-ChCQPYOh.js";
3
+ import { t as VERSION } from "./version-C5RAWmrD.js";
4
4
  import { n as CliError, t as CLI_ERRORS_URL } from "./errors-BTe6A15O.js";
5
- import { a as serializeSnapshot, i as parseSnapshot, l as introspect, t as loadSnapshot } from "./snapshot-DdN5GlhH.js";
6
- import { a as emitBlockConfig, l as buildModel, o as GENERATED_HEADER, r as renderFiles, s as emitModule } from "./render-DWRz-uPQ.js";
7
- import { a as toCatalog, n as managementSource, r as pgSource } from "./source-COARbqch.js";
8
- import { s as loadConfig } from "./config-BVfeG3A5.js";
9
- import { n as runGen } from "./run-j54rk2w-.js";
5
+ import { a as serializeSnapshot, i as parseSnapshot, l as introspect, t as loadSnapshot } from "./snapshot-DdAP7LWO.js";
6
+ import { a as emitBlockConfig, l as buildModel, o as GENERATED_HEADER, r as renderFiles, s as emitModule } from "./render-DUNJ4Pss.js";
7
+ import { a as toCatalog, n as managementSource, r as pgSource } from "./source-2irbWSck.js";
8
+ import { s as loadConfig } from "./config-KvV-sLZL.js";
9
+ import { n as runGen } from "./run-Cl9COGuy.js";
10
10
  //#region src/cli/introspect/from-catalog.ts
11
11
  /**
12
12
  * Builds a snapshot from catalog records: the inverse of `toCatalog`. Tests and
@@ -1,20 +1,94 @@
1
- import { a as list, p as commandMeta, r as defineCliCommand } from "./command-BWEEXmtz.js";
1
+ import { a as list, 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 } from "./io-DH1kcmmP.js";
5
- import { l as TYPEGEN_VERSION } from "./cache-1TfBy2K4.js";
6
- import { a as findConfig, s as loadConfig } from "./config-BVfeG3A5.js";
7
- import { r as contentMapperFiles } from "./content-mapper-hUW2nb92.js";
8
- import { i as changeLines, n as PLAN_ARGS, r as applyPlan, u as planResult } from "./files-CX71yBm8.js";
9
- import { C as promptConventions, S as hasConventionFlags, _ as templatePlan, b as conventionFlags, c as AUTHZ_NOTE, d as chooseIntegrations, f as integrationFiles, g as templateContextFor, h as parseIntegrations, i as blocksWiringPath, l as createUrlParam, m as packagesFor, o as writeDesign, p as overwrite, r as blockConfigImport, s as readPresetInput, u as CANCELLED, v as CONVENTION_ARGS, w as withConventions, x as defaultConventions, y as CONVENTION_COMPLETIONS } from "./add-BTVrOGJF.js";
10
- import { a as wiringFiles, c as baseFiles, f as needsLib, i as wiringChecklist, m as suggestedIntegrations, n as latestMigrationVersion, o as wiringFor, p as resolveIntegrations, r as configInstances, s as TEMPLATES } from "./migration-safety-Doy9qYO8.js";
5
+ import { l as TYPEGEN_VERSION } from "./cache-Czfw7Iow.js";
6
+ import { a as serializeSnapshot, t as loadSnapshot } from "./snapshot-DdAP7LWO.js";
7
+ import { a as toCatalog } from "./source-2irbWSck.js";
8
+ import { a as findConfig, s as loadConfig } from "./config-KvV-sLZL.js";
9
+ import { r as contentMapperFiles } from "./content-mapper-ez_mT0d4.js";
10
+ import { c as insideRoot, i as changeLines, n as PLAN_ARGS, r as applyPlan, u as planResult } from "./files-CX71yBm8.js";
11
+ import { C as promptConventions, S as hasConventionFlags, _ as templatePlan, b as conventionFlags, c as AUTHZ_NOTE, d as chooseIntegrations, f as integrationFiles, g as templateContextFor, h as parseIntegrations, i as blocksWiringPath, l as createUrlParam, m as packagesFor, o as writeDesign, p as overwrite, r as blockConfigImport, s as readPresetInput, u as CANCELLED, v as CONVENTION_ARGS, w as withConventions, x as defaultConventions, y as CONVENTION_COMPLETIONS } from "./add-DUyg9qna.js";
12
+ import { a as wiringFiles, c as baseFiles, f as needsLib, i as wiringChecklist, m as suggestedIntegrations, n as latestMigrationVersion, o as wiringFor, p as resolveIntegrations, r as configInstances, s as TEMPLATES } from "./migration-safety-ClnYNMdq.js";
11
13
  import { n as installCommand, t as detectProject } from "./detect-D9JaAX20.js";
12
- import { s as enablePgDelta, t as syncModules } from "./sync-SqyVHRSJ.js";
14
+ import { s as enablePgDelta, t as syncModules } from "./sync-DnSOrQuA.js";
13
15
  import { existsSync } from "node:fs";
14
16
  import { join, posix, resolve } from "node:path";
15
- import { glob, readFile } from "node:fs/promises";
17
+ import { glob, readFile, readdir } from "node:fs/promises";
16
18
  import { groupConfig, resolveConfig } from "better-supabase/config";
17
19
  import { PRESETS, PRESET_NAMES, conventionConfig, designConfig, glueCommand, integrationsForFramework, isPresetName, presetBlocksSource, presetGlue, presetSpec, resolvePreset } from "better-supabase/preset";
20
+ //#region src/cli/init-existing.ts
21
+ /** Where `init --from <url>` writes the schema it read. */
22
+ const SNAPSHOT_PATH = "supabase/snapshot.json";
23
+ const DATABASE_URL = /^postgres(?:ql)?:\/\//u;
24
+ /** Whether `--from` names a database rather than a preset, design or file. */
25
+ const isDatabaseUrl = (value) => DATABASE_URL.test(value);
26
+ async function sqlFiles(dir) {
27
+ if (!existsSync(dir)) return 0;
28
+ return (await readdir(dir, {
29
+ withFileTypes: true,
30
+ recursive: true
31
+ })).filter((entry) => entry.isFile() && entry.name.endsWith(".sql")).length;
32
+ }
33
+ /** The tables in the project's saved snapshot, or none without one. */
34
+ async function snapshotTables(config, env, root) {
35
+ const path = join(root, SNAPSHOT_PATH);
36
+ if (!existsSync(path)) return [];
37
+ try {
38
+ return toCatalog(await loadSnapshot(config, env, { snapshotPath: path })).tables;
39
+ } catch {
40
+ return [];
41
+ }
42
+ }
43
+ /**
44
+ * The migrations, schema files and snapshot tables of the Supabase folder in
45
+ * `root`, or `undefined` for a project without one.
46
+ */
47
+ async function detectExisting(config, env, root) {
48
+ const supabase = join(root, "supabase");
49
+ if (!existsSync(supabase)) return;
50
+ const [migrations, schemaFiles, tables] = await Promise.all([
51
+ sqlFiles(join(supabase, "migrations")),
52
+ sqlFiles(join(supabase, "schemas")),
53
+ snapshotTables(config, env, root)
54
+ ]);
55
+ return {
56
+ migrations,
57
+ schemaFiles,
58
+ tables: tables.map((table) => `${table.schema}.${table.name}`)
59
+ };
60
+ }
61
+ /** The lines `init` prints for an existing project. */
62
+ function existingLines(found) {
63
+ return [`Found an existing Supabase project: ${[
64
+ `${String(found.migrations)} migration(s)`,
65
+ `${String(found.schemaFiles)} schema file(s)`,
66
+ `${String(found.tables.length)} table(s) in ${SNAPSHOT_PATH}`
67
+ ].join(", ")}.`, "init changed nothing in the database and added no blocks; each step after it is optional."];
68
+ }
69
+ /**
70
+ * Reads the database at `url` and plans a snapshot of its schema, so `gen`,
71
+ * `doctor` and block detection see tables made in the dashboard.
72
+ */
73
+ async function planSnapshotFrom(config, env, root, url) {
74
+ const snapshot = await loadSnapshot(config, env, {
75
+ dbUrl: url,
76
+ live: true
77
+ });
78
+ return {
79
+ tables: snapshot.extras.tables.length,
80
+ plan: {
81
+ root,
82
+ regenerate: "better-supabase init --from",
83
+ files: [{
84
+ path: insideRoot(root, SNAPSHOT_PATH, "--from"),
85
+ contents: serializeSnapshot(snapshot),
86
+ note: `${String(snapshot.extras.tables.length)} tables`
87
+ }]
88
+ }
89
+ };
90
+ }
91
+ //#endregion
18
92
  //#region src/cli/project/workspace.ts
19
93
  const unquote = (value) => value.replace(/\s+#.*$/, "").trim().replace(/^(["'])(.*)\1$/, "$2");
20
94
  /** The `packages` globs of `pnpm-workspace.yaml`, in block or flow style. */
@@ -121,6 +195,11 @@ const INIT_ARGS = {
121
195
  description: "How the SQL modules reach the database: pg-delta (the default), migra or migrations",
122
196
  valueHint: "pg-delta|migra|migrations"
123
197
  },
198
+ from: {
199
+ type: "string",
200
+ description: "Where the project starts: a postgres:// URL (reads its schema into supabase/snapshot.json), or a preset, design code, URL or file like --preset",
201
+ valueHint: "url|name|code|file"
202
+ },
124
203
  preset: {
125
204
  type: "string",
126
205
  description: "A named preset, a design code from /create, its URL or a downloaded design file: the config starts from it, and init writes its modules and lib/blocks.ts",
@@ -232,7 +311,14 @@ function withDesign(files, design) {
232
311
  }
233
312
  return out;
234
313
  }
235
- async function runInit(config, args, prompts, now = () => /* @__PURE__ */ new Date()) {
314
+ async function runInit(config, given, prompts, now = () => /* @__PURE__ */ new Date(), env = {}) {
315
+ const databaseFrom = given.from !== void 0 && isDatabaseUrl(given.from) ? given.from : void 0;
316
+ if (given.from !== void 0 && given.preset !== void 0) throw new CliError("usage", "Pass --from or --preset, not both.");
317
+ const withPreset = {
318
+ ...given,
319
+ preset: given.from
320
+ };
321
+ const args = given.from === void 0 || databaseFrom !== void 0 ? given : withPreset;
236
322
  const flags = conventionFlags(args);
237
323
  const chosen = await chosenPreset(args, flags, prompts, config.root);
238
324
  if (chosen !== null && "code" in chosen) return chosen;
@@ -307,8 +393,10 @@ async function runInit(config, args, prompts, now = () => /* @__PURE__ */ new Da
307
393
  force
308
394
  });
309
395
  if (applied.mode === "check" && applied.drift) return planResult(templatePlan(root, files, "better-supabase init", config.root), applied);
396
+ const existing = await detectExisting(config, env, config.root);
310
397
  const lines = [
311
398
  project.frameworks.length > 0 ? `Found ${project.frameworks.join(", ")}${where}.` : `No framework found${where}.`,
399
+ ...existing === void 0 ? [] : ["", ...existingLines(existing)],
312
400
  "",
313
401
  ...changeLines(applied),
314
402
  ...workflow === "pg-delta" ? await enablePgDelta(root, args["dry-run"] === true, config.root) : []
@@ -328,6 +416,16 @@ async function runInit(config, args, prompts, now = () => /* @__PURE__ */ new Da
328
416
  });
329
417
  lines.push(...changeLines(wrote));
330
418
  }
419
+ let snapshotTables;
420
+ if (databaseFrom !== void 0) {
421
+ const read = await planSnapshotFrom(config, env, config.root, databaseFrom);
422
+ const wrote = await applyPlan(read.plan, {
423
+ ...args,
424
+ force: true
425
+ });
426
+ snapshotTables = read.tables;
427
+ lines.push("", ...changeLines(wrote));
428
+ }
331
429
  if (createUrlParam(args.preset, "authz") !== void 0) lines.push("", AUTHZ_NOTE);
332
430
  if (chosen !== null) {
333
431
  const presetConfig = resolveConfig(groupConfig({
@@ -388,6 +486,13 @@ async function runInit(config, args, prompts, now = () => /* @__PURE__ */ new Da
388
486
  command: `better-supabase gen${cwdFlag}`,
389
487
  when: "generates the typed client"
390
488
  },
489
+ ...existing === void 0 ? [] : [{
490
+ command: `better-supabase doctor${cwdFlag}`,
491
+ when: "reports which tables each rung covers"
492
+ }, {
493
+ command: `better-supabase table <table> enable <feature>${cwdFlag}`,
494
+ when: "turns on a feature for one of your tables"
495
+ }],
391
496
  {
392
497
  command: "better-supabase skills install",
393
498
  when: "installs the agent skills"
@@ -407,6 +512,8 @@ async function runInit(config, args, prompts, now = () => /* @__PURE__ */ new Da
407
512
  ...inPackage ? { package: target.dir } : {},
408
513
  integrations,
409
514
  ...chosen === null ? {} : { preset: chosen.value },
515
+ ...existing === void 0 ? {} : { existing },
516
+ ...snapshotTables === void 0 ? {} : { snapshotTables },
410
517
  files: applied.changes,
411
518
  hints
412
519
  },
@@ -425,7 +532,7 @@ const initCommand = defineCliCommand({
425
532
  ...CONVENTION_COMPLETIONS,
426
533
  preset: () => PRESET_NAMES
427
534
  },
428
- run: (args, { config, io }) => runInit(config, args, io.prompts)
535
+ run: (args, { config, io, env }) => runInit(config, args, io.prompts, void 0, env)
429
536
  });
430
537
  /** The `blocks` and `appTables` keys a design adds to the preset's config. */
431
538
  function designKeys(resolved, design) {
@@ -1,4 +1,4 @@
1
- import { p as commandMeta, r as defineCliCommand } from "./command-BWEEXmtz.js";
1
+ import { p as commandMeta, r as defineCliCommand } from "./command-CVzTJSLp.js";
2
2
  import { t as display } from "./io-DH1kcmmP.js";
3
3
  import { m as supabaseDir } from "./supabase-toml-CncmQbO0.js";
4
4
  import { i as changeLines, r as applyPlan } from "./files-CX71yBm8.js";
@@ -1,6 +1,6 @@
1
1
  import { r as errorText } from "./errors-BTe6A15O.js";
2
- import "./source-COARbqch.js";
3
- import { l as tableObject, n as exposed, s as qualified, t as catalogOf } from "./shared-CslNcs-R.js";
2
+ import "./source-2irbWSck.js";
3
+ import { l as tableObject, n as exposed, s as qualified, t as catalogOf } from "./shared-5uqc1GBj.js";
4
4
  //#region src/cli/doctor/reserved-roles.ts
5
5
  /**
6
6
  * Supautils' `reserved_roles` on Supabase. Nobody but a superuser may alter,
@@ -1,9 +1,9 @@
1
- import { p as commandMeta, r as defineCliCommand } from "./command-BWEEXmtz.js";
2
- import { a as envelope, i as run } from "./run-DPLedqTF.js";
3
- import { t as VERSION } from "./version-Bhca9D6q.js";
1
+ import { p as commandMeta, r as defineCliCommand } from "./command-CVzTJSLp.js";
2
+ import { a as envelope, i as run } from "./run-ChCQPYOh.js";
3
+ import { t as VERSION } from "./version-C5RAWmrD.js";
4
4
  import { n as CliError } from "./errors-BTe6A15O.js";
5
5
  import { n as consentToken } from "./agent-CbuPvI2x.js";
6
- import { C as optional, D as record, N as unknown, a as array, d as is, j as string$1, k as safeParse, o as boolean, t as PROCESS_ENV, x as object } from "./env-DMgjB_4y.js";
6
+ import { C as optional, D as record, N as unknown, a as array, d as is, j as string$1, k as safeParse, o as boolean, t as PROCESS_ENV, x as object } from "./env-BK0xKMeU.js";
7
7
  import { createInterface } from "node:readline";
8
8
  import { answerLine } from "better-supabase/mcp";
9
9
  //#region src/cli/mcp/server.ts
@@ -1,8 +1,8 @@
1
1
  import { n as CliError, r as errorText } from "./errors-BTe6A15O.js";
2
2
  import { i as readStdin } from "./io-DH1kcmmP.js";
3
- import { m as parseMetadataDocument, u as MetadataRejectedError } from "./snapshot-DdN5GlhH.js";
4
- import { c as metaPaths, n as render } from "./render-DWRz-uPQ.js";
5
- import { i as generationNotices, n as runGen, o as fromMetadata, r as UNFORMATTED, t as refuseRowConditionedBuckets } from "./run-j54rk2w-.js";
3
+ import { m as parseMetadataDocument, u as MetadataRejectedError } from "./snapshot-DdAP7LWO.js";
4
+ import { c as metaPaths, n as render } from "./render-DUNJ4Pss.js";
5
+ import { i as generationNotices, n as runGen, o as fromMetadata, r as UNFORMATTED, t as refuseRowConditionedBuckets } from "./run-Cl9COGuy.js";
6
6
  import { basename, join, relative, resolve, sep } from "node:path";
7
7
  import { readFile } from "node:fs/promises";
8
8
  import { jsonSchema, standardSchema, valibot, zod } from "better-supabase/config";