@breeztech/breez-sdk-spark 0.14.0 → 0.15.1

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 (37) hide show
  1. package/breez-sdk-spark.tgz +0 -0
  2. package/bundler/breez_sdk_spark_wasm.d.ts +114 -40
  3. package/bundler/breez_sdk_spark_wasm.js +1 -1
  4. package/bundler/breez_sdk_spark_wasm_bg.js +118 -104
  5. package/bundler/breez_sdk_spark_wasm_bg.wasm +0 -0
  6. package/bundler/breez_sdk_spark_wasm_bg.wasm.d.ts +12 -11
  7. package/deno/breez_sdk_spark_wasm.d.ts +114 -40
  8. package/deno/breez_sdk_spark_wasm.js +118 -104
  9. package/deno/breez_sdk_spark_wasm_bg.wasm +0 -0
  10. package/deno/breez_sdk_spark_wasm_bg.wasm.d.ts +12 -11
  11. package/nodejs/breez_sdk_spark_wasm.d.ts +114 -40
  12. package/nodejs/breez_sdk_spark_wasm.js +121 -106
  13. package/nodejs/breez_sdk_spark_wasm_bg.wasm +0 -0
  14. package/nodejs/breez_sdk_spark_wasm_bg.wasm.d.ts +12 -11
  15. package/nodejs/index.mjs +3 -2
  16. package/nodejs/mysql-session-manager/index.cjs +26 -8
  17. package/nodejs/mysql-session-manager/migrations.cjs +40 -3
  18. package/nodejs/mysql-storage/index.cjs +67 -48
  19. package/nodejs/mysql-storage/migrations.cjs +220 -85
  20. package/nodejs/mysql-token-store/index.cjs +133 -68
  21. package/nodejs/mysql-token-store/migrations.cjs +309 -80
  22. package/nodejs/mysql-tree-store/index.cjs +76 -41
  23. package/nodejs/mysql-tree-store/migrations.cjs +254 -71
  24. package/nodejs/postgres-session-manager/index.cjs +27 -9
  25. package/nodejs/postgres-session-manager/migrations.cjs +45 -6
  26. package/nodejs/postgres-storage/index.cjs +81 -62
  27. package/nodejs/postgres-storage/migrations.cjs +207 -79
  28. package/nodejs/postgres-token-store/index.cjs +111 -67
  29. package/nodejs/postgres-token-store/migrations.cjs +153 -61
  30. package/nodejs/postgres-tree-store/index.cjs +60 -42
  31. package/nodejs/postgres-tree-store/migrations.cjs +130 -46
  32. package/package.json +1 -1
  33. package/ssr/index.js +14 -9
  34. package/web/breez_sdk_spark_wasm.d.ts +126 -51
  35. package/web/breez_sdk_spark_wasm.js +118 -104
  36. package/web/breez_sdk_spark_wasm_bg.wasm +0 -0
  37. package/web/breez_sdk_spark_wasm_bg.wasm.d.ts +12 -11
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Database Migration Manager for Breez SDK PostgreSQL Storage
3
3
  *
4
- * Uses a schema_migrations table + pg_advisory_xact_lock to safely run
4
+ * Uses a brz_schema_migrations table + pg_advisory_xact_lock to safely run
5
5
  * migrations from concurrent processes.
6
6
  */
7
7
 
@@ -35,9 +35,11 @@ class PostgresMigrationManager {
35
35
  // Transaction-level advisory lock — automatically released on COMMIT/ROLLBACK
36
36
  await client.query(`SELECT pg_advisory_xact_lock(${MIGRATION_LOCK_ID})`);
37
37
 
38
+ await this._applySchemaRenames(client);
39
+
38
40
  // Create the migrations tracking table if needed
39
41
  await client.query(`
40
- CREATE TABLE IF NOT EXISTS schema_migrations (
42
+ CREATE TABLE IF NOT EXISTS brz_schema_migrations (
41
43
  version INTEGER PRIMARY KEY,
42
44
  applied_at TIMESTAMPTZ DEFAULT NOW()
43
45
  )
@@ -45,7 +47,7 @@ class PostgresMigrationManager {
45
47
 
46
48
  // Get current version
47
49
  const versionResult = await client.query(
48
- "SELECT COALESCE(MAX(version), 0) AS version FROM schema_migrations"
50
+ "SELECT COALESCE(MAX(version), 0) AS version FROM brz_schema_migrations"
49
51
  );
50
52
  const currentVersion = versionResult.rows[0].version;
51
53
 
@@ -72,7 +74,7 @@ class PostgresMigrationManager {
72
74
  }
73
75
 
74
76
  await client.query(
75
- "INSERT INTO schema_migrations (version) VALUES ($1)",
77
+ "INSERT INTO brz_schema_migrations (version) VALUES ($1)",
76
78
  [version]
77
79
  );
78
80
  }
@@ -90,6 +92,132 @@ class PostgresMigrationManager {
90
92
  }
91
93
  }
92
94
 
95
+ /**
96
+ * Pre-prefix rename. Canary-gated on the legacy `schema_migrations` table.
97
+ * @param {import('pg').PoolClient} client
98
+ */
99
+ async _applySchemaRenames(client) {
100
+ const canary = await client.query(
101
+ `SELECT EXISTS (
102
+ SELECT 1 FROM information_schema.tables
103
+ WHERE table_schema = current_schema()
104
+ AND table_name = 'schema_migrations'
105
+ ) AS exists`
106
+ );
107
+ if (!canary.rows[0].exists) {
108
+ return;
109
+ }
110
+
111
+ const tableRenames = [
112
+ ["payments", "brz_payments"],
113
+ ["settings", "brz_settings"],
114
+ ["unclaimed_deposits", "brz_unclaimed_deposits"],
115
+ ["payment_metadata", "brz_payment_metadata"],
116
+ ["payment_details_lightning", "brz_payment_details_lightning"],
117
+ ["payment_details_token", "brz_payment_details_token"],
118
+ ["payment_details_spark", "brz_payment_details_spark"],
119
+ ["lnurl_receive_metadata", "brz_lnurl_receive_metadata"],
120
+ ["sync_revision", "brz_sync_revision"],
121
+ ["sync_outgoing", "brz_sync_outgoing"],
122
+ ["sync_state", "brz_sync_state"],
123
+ ["sync_incoming", "brz_sync_incoming"],
124
+ ["contacts", "brz_contacts"],
125
+ ];
126
+ for (const [oldName, newName] of tableRenames) {
127
+ await client.query(`ALTER TABLE IF EXISTS ${oldName} RENAME TO ${newName}`);
128
+ }
129
+
130
+ const indexRenames = [
131
+ ["idx_payments_user_timestamp", "brz_idx_payments_user_timestamp"],
132
+ ["idx_payments_user_payment_type", "brz_idx_payments_user_payment_type"],
133
+ ["idx_payments_user_status", "brz_idx_payments_user_status"],
134
+ ["idx_payment_metadata_user_parent", "brz_idx_payment_metadata_user_parent"],
135
+ [
136
+ "idx_payment_details_lightning_user_invoice",
137
+ "brz_idx_payment_details_lightning_user_invoice",
138
+ ],
139
+ [
140
+ "idx_payment_details_lightning_user_payment_hash",
141
+ "brz_idx_payment_details_lightning_user_payment_hash",
142
+ ],
143
+ [
144
+ "idx_sync_outgoing_user_record_type_data_id",
145
+ "brz_idx_sync_outgoing_user_record_type_data_id",
146
+ ],
147
+ ["idx_sync_incoming_user_revision", "brz_idx_sync_incoming_user_revision"],
148
+ // Pre-multi-tenant indexes (still present on version < 16 DBs).
149
+ ["idx_payments_timestamp", "brz_idx_payments_timestamp"],
150
+ ["idx_payments_payment_type", "brz_idx_payments_payment_type"],
151
+ ["idx_payments_status", "brz_idx_payments_status"],
152
+ ["idx_payment_metadata_parent", "brz_idx_payment_metadata_parent"],
153
+ [
154
+ "idx_payment_details_lightning_invoice",
155
+ "brz_idx_payment_details_lightning_invoice",
156
+ ],
157
+ [
158
+ "idx_payment_details_lightning_payment_hash",
159
+ "brz_idx_payment_details_lightning_payment_hash",
160
+ ],
161
+ [
162
+ "idx_sync_outgoing_data_id_record_type",
163
+ "brz_idx_sync_outgoing_data_id_record_type",
164
+ ],
165
+ ["idx_sync_incoming_revision", "brz_idx_sync_incoming_revision"],
166
+ ];
167
+ for (const [oldName, newName] of indexRenames) {
168
+ await client.query(`ALTER INDEX IF EXISTS ${oldName} RENAME TO ${newName}`);
169
+ }
170
+
171
+ const constraintRenames = [
172
+ ["brz_payments", "payments_pkey", "brz_payments_pkey"],
173
+ ["brz_settings", "settings_pkey", "brz_settings_pkey"],
174
+ ["brz_unclaimed_deposits", "unclaimed_deposits_pkey", "brz_unclaimed_deposits_pkey"],
175
+ ["brz_payment_metadata", "payment_metadata_pkey", "brz_payment_metadata_pkey"],
176
+ [
177
+ "brz_payment_details_lightning",
178
+ "payment_details_lightning_pkey",
179
+ "brz_payment_details_lightning_pkey",
180
+ ],
181
+ [
182
+ "brz_payment_details_token",
183
+ "payment_details_token_pkey",
184
+ "brz_payment_details_token_pkey",
185
+ ],
186
+ [
187
+ "brz_payment_details_spark",
188
+ "payment_details_spark_pkey",
189
+ "brz_payment_details_spark_pkey",
190
+ ],
191
+ [
192
+ "brz_lnurl_receive_metadata",
193
+ "lnurl_receive_metadata_pkey",
194
+ "brz_lnurl_receive_metadata_pkey",
195
+ ],
196
+ ["brz_sync_revision", "sync_revision_pkey", "brz_sync_revision_pkey"],
197
+ ["brz_sync_state", "sync_state_pkey", "brz_sync_state_pkey"],
198
+ ["brz_sync_incoming", "sync_incoming_pkey", "brz_sync_incoming_pkey"],
199
+ ["brz_contacts", "contacts_pkey", "brz_contacts_pkey"],
200
+ ];
201
+ for (const [table, oldName, newName] of constraintRenames) {
202
+ await client.query(
203
+ `DO $$ BEGIN
204
+ IF EXISTS (
205
+ SELECT 1 FROM information_schema.table_constraints
206
+ WHERE table_schema = current_schema()
207
+ AND table_name = '${table}'
208
+ AND constraint_name = '${oldName}'
209
+ ) THEN
210
+ ALTER TABLE ${table} RENAME CONSTRAINT ${oldName} TO ${newName};
211
+ END IF;
212
+ END $$`
213
+ );
214
+ }
215
+
216
+ await client.query(
217
+ `ALTER TABLE IF EXISTS schema_migrations RENAME TO brz_schema_migrations`
218
+ );
219
+ }
220
+
93
221
  _log(level, message) {
94
222
  if (this.logger && typeof this.logger.log === "function") {
95
223
  this.logger.log({ line: message, level });
@@ -128,7 +256,7 @@ class PostgresMigrationManager {
128
256
  name: "Create all tables at final schema",
129
257
  sql: [
130
258
  // -- Core tables --
131
- `CREATE TABLE IF NOT EXISTS payments (
259
+ `CREATE TABLE IF NOT EXISTS brz_payments (
132
260
  id TEXT PRIMARY KEY,
133
261
  payment_type TEXT NOT NULL,
134
262
  status TEXT NOT NULL,
@@ -141,12 +269,12 @@ class PostgresMigrationManager {
141
269
  spark BOOLEAN
142
270
  )`,
143
271
 
144
- `CREATE TABLE IF NOT EXISTS settings (
272
+ `CREATE TABLE IF NOT EXISTS brz_settings (
145
273
  key TEXT PRIMARY KEY,
146
274
  value TEXT NOT NULL
147
275
  )`,
148
276
 
149
- `CREATE TABLE IF NOT EXISTS unclaimed_deposits (
277
+ `CREATE TABLE IF NOT EXISTS brz_unclaimed_deposits (
150
278
  txid TEXT NOT NULL,
151
279
  vout INTEGER NOT NULL,
152
280
  amount_sats BIGINT,
@@ -156,7 +284,7 @@ class PostgresMigrationManager {
156
284
  PRIMARY KEY (txid, vout)
157
285
  )`,
158
286
 
159
- `CREATE TABLE IF NOT EXISTS payment_metadata (
287
+ `CREATE TABLE IF NOT EXISTS brz_payment_metadata (
160
288
  payment_id TEXT PRIMARY KEY,
161
289
  parent_payment_id TEXT,
162
290
  lnurl_pay_info JSONB,
@@ -165,7 +293,7 @@ class PostgresMigrationManager {
165
293
  conversion_info JSONB
166
294
  )`,
167
295
 
168
- `CREATE TABLE IF NOT EXISTS payment_details_lightning (
296
+ `CREATE TABLE IF NOT EXISTS brz_payment_details_lightning (
169
297
  payment_id TEXT PRIMARY KEY,
170
298
  invoice TEXT NOT NULL,
171
299
  payment_hash TEXT NOT NULL,
@@ -176,7 +304,7 @@ class PostgresMigrationManager {
176
304
  htlc_expiry_time BIGINT NOT NULL
177
305
  )`,
178
306
 
179
- `CREATE TABLE IF NOT EXISTS payment_details_token (
307
+ `CREATE TABLE IF NOT EXISTS brz_payment_details_token (
180
308
  payment_id TEXT PRIMARY KEY,
181
309
  metadata JSONB NOT NULL,
182
310
  tx_hash TEXT NOT NULL,
@@ -184,13 +312,13 @@ class PostgresMigrationManager {
184
312
  invoice_details JSONB
185
313
  )`,
186
314
 
187
- `CREATE TABLE IF NOT EXISTS payment_details_spark (
315
+ `CREATE TABLE IF NOT EXISTS brz_payment_details_spark (
188
316
  payment_id TEXT PRIMARY KEY,
189
317
  invoice_details JSONB,
190
318
  htlc_details JSONB
191
319
  )`,
192
320
 
193
- `CREATE TABLE IF NOT EXISTS lnurl_receive_metadata (
321
+ `CREATE TABLE IF NOT EXISTS brz_lnurl_receive_metadata (
194
322
  payment_hash TEXT PRIMARY KEY,
195
323
  nostr_zap_request TEXT,
196
324
  nostr_zap_receipt TEXT,
@@ -199,14 +327,14 @@ class PostgresMigrationManager {
199
327
  )`,
200
328
 
201
329
  // -- Sync tables --
202
- `CREATE TABLE IF NOT EXISTS sync_revision (
330
+ `CREATE TABLE IF NOT EXISTS brz_sync_revision (
203
331
  id INTEGER PRIMARY KEY DEFAULT 1,
204
332
  revision BIGINT NOT NULL DEFAULT 0,
205
333
  CHECK (id = 1)
206
334
  )`,
207
- `INSERT INTO sync_revision (id, revision) VALUES (1, 0) ON CONFLICT (id) DO NOTHING`,
335
+ `INSERT INTO brz_sync_revision (id, revision) VALUES (1, 0) ON CONFLICT (id) DO NOTHING`,
208
336
 
209
- `CREATE TABLE IF NOT EXISTS sync_outgoing (
337
+ `CREATE TABLE IF NOT EXISTS brz_sync_outgoing (
210
338
  record_type TEXT NOT NULL,
211
339
  data_id TEXT NOT NULL,
212
340
  schema_version TEXT NOT NULL,
@@ -215,7 +343,7 @@ class PostgresMigrationManager {
215
343
  revision BIGINT NOT NULL
216
344
  )`,
217
345
 
218
- `CREATE TABLE IF NOT EXISTS sync_state (
346
+ `CREATE TABLE IF NOT EXISTS brz_sync_state (
219
347
  record_type TEXT NOT NULL,
220
348
  data_id TEXT NOT NULL,
221
349
  schema_version TEXT NOT NULL,
@@ -225,7 +353,7 @@ class PostgresMigrationManager {
225
353
  PRIMARY KEY (record_type, data_id)
226
354
  )`,
227
355
 
228
- `CREATE TABLE IF NOT EXISTS sync_incoming (
356
+ `CREATE TABLE IF NOT EXISTS brz_sync_incoming (
229
357
  record_type TEXT NOT NULL,
230
358
  data_id TEXT NOT NULL,
231
359
  schema_version TEXT NOT NULL,
@@ -236,20 +364,20 @@ class PostgresMigrationManager {
236
364
  )`,
237
365
 
238
366
  // -- Indexes --
239
- `CREATE INDEX IF NOT EXISTS idx_payments_timestamp ON payments(timestamp)`,
240
- `CREATE INDEX IF NOT EXISTS idx_payments_payment_type ON payments(payment_type)`,
241
- `CREATE INDEX IF NOT EXISTS idx_payments_status ON payments(status)`,
242
- `CREATE INDEX IF NOT EXISTS idx_payment_details_lightning_invoice ON payment_details_lightning(invoice)`,
243
- `CREATE INDEX IF NOT EXISTS idx_payment_details_lightning_payment_hash ON payment_details_lightning(payment_hash)`,
244
- `CREATE INDEX IF NOT EXISTS idx_payment_metadata_parent ON payment_metadata(parent_payment_id)`,
245
- `CREATE INDEX IF NOT EXISTS idx_sync_outgoing_data_id_record_type ON sync_outgoing(record_type, data_id)`,
246
- `CREATE INDEX IF NOT EXISTS idx_sync_incoming_revision ON sync_incoming(revision)`,
367
+ `CREATE INDEX IF NOT EXISTS brz_idx_payments_timestamp ON brz_payments(timestamp)`,
368
+ `CREATE INDEX IF NOT EXISTS brz_idx_payments_payment_type ON brz_payments(payment_type)`,
369
+ `CREATE INDEX IF NOT EXISTS brz_idx_payments_status ON brz_payments(status)`,
370
+ `CREATE INDEX IF NOT EXISTS brz_idx_payment_details_lightning_invoice ON brz_payment_details_lightning(invoice)`,
371
+ `CREATE INDEX IF NOT EXISTS brz_idx_payment_details_lightning_payment_hash ON brz_payment_details_lightning(payment_hash)`,
372
+ `CREATE INDEX IF NOT EXISTS brz_idx_payment_metadata_parent ON brz_payment_metadata(parent_payment_id)`,
373
+ `CREATE INDEX IF NOT EXISTS brz_idx_sync_outgoing_data_id_record_type ON brz_sync_outgoing(record_type, data_id)`,
374
+ `CREATE INDEX IF NOT EXISTS brz_idx_sync_incoming_revision ON brz_sync_incoming(revision)`,
247
375
  ],
248
376
  },
249
377
  {
250
- name: "Create contacts table",
378
+ name: "Create brz_contacts table",
251
379
  sql: [
252
- `CREATE TABLE IF NOT EXISTS contacts (
380
+ `CREATE TABLE IF NOT EXISTS brz_contacts (
253
381
  id TEXT PRIMARY KEY,
254
382
  name TEXT NOT NULL,
255
383
  payment_identifier TEXT NOT NULL,
@@ -259,84 +387,84 @@ class PostgresMigrationManager {
259
387
  ],
260
388
  },
261
389
  {
262
- name: "Drop preimage column from lnurl_receive_metadata",
390
+ name: "Drop preimage column from brz_lnurl_receive_metadata",
263
391
  sql: [
264
- `ALTER TABLE lnurl_receive_metadata DROP COLUMN IF EXISTS preimage`,
392
+ `ALTER TABLE brz_lnurl_receive_metadata DROP COLUMN IF EXISTS preimage`,
265
393
  ],
266
394
  },
267
395
  {
268
396
  name: "Clear cached lightning address for CachedLightningAddress format change",
269
397
  sql: [
270
- `DELETE FROM settings WHERE key = 'lightning_address'`,
398
+ `DELETE FROM brz_settings WHERE key = 'lightning_address'`,
271
399
  ],
272
400
  },
273
401
  {
274
- name: "Add is_mature to unclaimed_deposits",
402
+ name: "Add is_mature to brz_unclaimed_deposits",
275
403
  sql: [
276
- `ALTER TABLE unclaimed_deposits ADD COLUMN is_mature BOOLEAN NOT NULL DEFAULT TRUE`,
404
+ `ALTER TABLE brz_unclaimed_deposits ADD COLUMN is_mature BOOLEAN NOT NULL DEFAULT TRUE`,
277
405
  ],
278
406
  },
279
407
  {
280
- name: "Add conversion_status to payment_metadata",
408
+ name: "Add conversion_status to brz_payment_metadata",
281
409
  sql: [
282
- `ALTER TABLE payment_metadata ADD COLUMN IF NOT EXISTS conversion_status TEXT`,
410
+ `ALTER TABLE brz_payment_metadata ADD COLUMN IF NOT EXISTS conversion_status TEXT`,
283
411
  ],
284
412
  },
285
413
  {
286
414
  name: "Multi-tenant scoping: add user_id and rewrite primary keys",
287
415
  sql: [
288
416
  // Per-user tables
289
- ...scopeTable("payments", "id"),
290
- `DROP INDEX IF EXISTS idx_payments_timestamp`,
291
- `DROP INDEX IF EXISTS idx_payments_payment_type`,
292
- `DROP INDEX IF EXISTS idx_payments_status`,
293
- `CREATE INDEX idx_payments_user_timestamp ON payments(user_id, timestamp)`,
294
- `CREATE INDEX idx_payments_user_payment_type ON payments(user_id, payment_type)`,
295
- `CREATE INDEX idx_payments_user_status ON payments(user_id, status)`,
296
-
297
- ...scopeTable("payment_metadata", "payment_id"),
298
- `DROP INDEX IF EXISTS idx_payment_metadata_parent`,
299
- `CREATE INDEX idx_payment_metadata_user_parent
300
- ON payment_metadata(user_id, parent_payment_id)`,
301
-
302
- ...scopeTable("payment_details_lightning", "payment_id"),
303
- `DROP INDEX IF EXISTS idx_payment_details_lightning_invoice`,
304
- `DROP INDEX IF EXISTS idx_payment_details_lightning_payment_hash`,
305
- `CREATE INDEX idx_payment_details_lightning_user_invoice
306
- ON payment_details_lightning(user_id, invoice)`,
307
- `CREATE INDEX idx_payment_details_lightning_user_payment_hash
308
- ON payment_details_lightning(user_id, payment_hash)`,
309
-
310
- ...scopeTable("payment_details_token", "payment_id"),
311
- ...scopeTable("payment_details_spark", "payment_id"),
312
- ...scopeTable("lnurl_receive_metadata", "payment_hash"),
313
- ...scopeTable("unclaimed_deposits", "txid, vout"),
314
- ...scopeTable("contacts", "id"),
315
- ...scopeTable("settings", "key"),
316
-
317
- // sync_revision: drop the singleton id (CASCADE removes PK + CHECK),
417
+ ...scopeTable("brz_payments", "id"),
418
+ `DROP INDEX IF EXISTS brz_idx_payments_timestamp`,
419
+ `DROP INDEX IF EXISTS brz_idx_payments_payment_type`,
420
+ `DROP INDEX IF EXISTS brz_idx_payments_status`,
421
+ `CREATE INDEX brz_idx_payments_user_timestamp ON brz_payments(user_id, timestamp)`,
422
+ `CREATE INDEX brz_idx_payments_user_payment_type ON brz_payments(user_id, payment_type)`,
423
+ `CREATE INDEX brz_idx_payments_user_status ON brz_payments(user_id, status)`,
424
+
425
+ ...scopeTable("brz_payment_metadata", "payment_id"),
426
+ `DROP INDEX IF EXISTS brz_idx_payment_metadata_parent`,
427
+ `CREATE INDEX brz_idx_payment_metadata_user_parent
428
+ ON brz_payment_metadata(user_id, parent_payment_id)`,
429
+
430
+ ...scopeTable("brz_payment_details_lightning", "payment_id"),
431
+ `DROP INDEX IF EXISTS brz_idx_payment_details_lightning_invoice`,
432
+ `DROP INDEX IF EXISTS brz_idx_payment_details_lightning_payment_hash`,
433
+ `CREATE INDEX brz_idx_payment_details_lightning_user_invoice
434
+ ON brz_payment_details_lightning(user_id, invoice)`,
435
+ `CREATE INDEX brz_idx_payment_details_lightning_user_payment_hash
436
+ ON brz_payment_details_lightning(user_id, payment_hash)`,
437
+
438
+ ...scopeTable("brz_payment_details_token", "payment_id"),
439
+ ...scopeTable("brz_payment_details_spark", "payment_id"),
440
+ ...scopeTable("brz_lnurl_receive_metadata", "payment_hash"),
441
+ ...scopeTable("brz_unclaimed_deposits", "txid, vout"),
442
+ ...scopeTable("brz_contacts", "id"),
443
+ ...scopeTable("brz_settings", "key"),
444
+
445
+ // brz_sync_revision: drop the singleton id (CASCADE removes PK + CHECK),
318
446
  // then re-key by user_id so each tenant has its own revision row.
319
- `ALTER TABLE sync_revision DROP COLUMN id CASCADE`,
320
- `ALTER TABLE sync_revision ADD COLUMN user_id BYTEA`,
321
- `UPDATE sync_revision SET user_id = ${idLit}`,
322
- `ALTER TABLE sync_revision
447
+ `ALTER TABLE brz_sync_revision DROP COLUMN id CASCADE`,
448
+ `ALTER TABLE brz_sync_revision ADD COLUMN user_id BYTEA`,
449
+ `UPDATE brz_sync_revision SET user_id = ${idLit}`,
450
+ `ALTER TABLE brz_sync_revision
323
451
  ALTER COLUMN user_id SET NOT NULL,
324
452
  ADD PRIMARY KEY (user_id)`,
325
453
 
326
- // sync_outgoing has no PK, only an index — just add user_id and rewrite the index.
327
- `ALTER TABLE sync_outgoing ADD COLUMN user_id BYTEA`,
328
- `UPDATE sync_outgoing SET user_id = ${idLit}`,
329
- `ALTER TABLE sync_outgoing ALTER COLUMN user_id SET NOT NULL`,
330
- `DROP INDEX IF EXISTS idx_sync_outgoing_data_id_record_type`,
331
- `CREATE INDEX idx_sync_outgoing_user_record_type_data_id
332
- ON sync_outgoing(user_id, record_type, data_id)`,
454
+ // brz_sync_outgoing has no PK, only an index — just add user_id and rewrite the index.
455
+ `ALTER TABLE brz_sync_outgoing ADD COLUMN user_id BYTEA`,
456
+ `UPDATE brz_sync_outgoing SET user_id = ${idLit}`,
457
+ `ALTER TABLE brz_sync_outgoing ALTER COLUMN user_id SET NOT NULL`,
458
+ `DROP INDEX IF EXISTS brz_idx_sync_outgoing_data_id_record_type`,
459
+ `CREATE INDEX brz_idx_sync_outgoing_user_record_type_data_id
460
+ ON brz_sync_outgoing(user_id, record_type, data_id)`,
333
461
 
334
- ...scopeTable("sync_state", "record_type, data_id"),
462
+ ...scopeTable("brz_sync_state", "record_type, data_id"),
335
463
 
336
- ...scopeTable("sync_incoming", "record_type, data_id, revision"),
337
- `DROP INDEX IF EXISTS idx_sync_incoming_revision`,
338
- `CREATE INDEX idx_sync_incoming_user_revision
339
- ON sync_incoming(user_id, revision)`,
464
+ ...scopeTable("brz_sync_incoming", "record_type, data_id, revision"),
465
+ `DROP INDEX IF EXISTS brz_idx_sync_incoming_revision`,
466
+ `CREATE INDEX brz_idx_sync_incoming_user_revision
467
+ ON brz_sync_incoming(user_id, revision)`,
340
468
  ],
341
469
  },
342
470
  ];