@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
@@ -62,12 +62,12 @@ const SELECT_PAYMENT_SQL = `
62
62
  lrm.sender_comment AS lnurl_sender_comment,
63
63
  lrm.payment_hash AS lnurl_payment_hash,
64
64
  pm.parent_payment_id
65
- FROM payments p
66
- LEFT JOIN payment_details_lightning l ON p.id = l.payment_id AND p.user_id = l.user_id
67
- LEFT JOIN payment_details_token t ON p.id = t.payment_id AND p.user_id = t.user_id
68
- LEFT JOIN payment_details_spark s ON p.id = s.payment_id AND p.user_id = s.user_id
69
- LEFT JOIN payment_metadata pm ON p.id = pm.payment_id AND p.user_id = pm.user_id
70
- LEFT JOIN lnurl_receive_metadata lrm ON l.payment_hash = lrm.payment_hash AND l.user_id = lrm.user_id`;
65
+ FROM brz_payments p
66
+ LEFT JOIN brz_payment_details_lightning l ON p.id = l.payment_id AND p.user_id = l.user_id
67
+ LEFT JOIN brz_payment_details_token t ON p.id = t.payment_id AND p.user_id = t.user_id
68
+ LEFT JOIN brz_payment_details_spark s ON p.id = s.payment_id AND p.user_id = s.user_id
69
+ LEFT JOIN brz_payment_metadata pm ON p.id = pm.payment_id AND p.user_id = pm.user_id
70
+ LEFT JOIN brz_lnurl_receive_metadata lrm ON l.payment_hash = lrm.payment_hash AND l.user_id = lrm.user_id`;
71
71
 
72
72
  class PostgresStorage {
73
73
  /**
@@ -77,13 +77,14 @@ class PostgresStorage {
77
77
  * so that multiple instances with distinct identities can share one DB.
78
78
  * @param {object} [logger]
79
79
  */
80
- constructor(pool, identity, logger = null) {
80
+ constructor(pool, identity, logger = null, runMigration = true) {
81
81
  if (!identity) {
82
82
  throw new StorageError("PostgresStorage requires a tenant identity");
83
83
  }
84
84
  this.pool = pool;
85
85
  this.identity = Buffer.from(identity);
86
86
  this.logger = logger;
87
+ this.runMigration = runMigration;
87
88
  }
88
89
 
89
90
  /**
@@ -91,8 +92,10 @@ class PostgresStorage {
91
92
  */
92
93
  async initialize() {
93
94
  try {
94
- const migrationManager = new PostgresMigrationManager(this.logger);
95
- await migrationManager.migrate(this.pool, this.identity);
95
+ if (this.runMigration) {
96
+ const migrationManager = new PostgresMigrationManager(this.logger);
97
+ await migrationManager.migrate(this.pool, this.identity);
98
+ }
96
99
  return this;
97
100
  } catch (error) {
98
101
  throw new StorageError(
@@ -138,7 +141,7 @@ class PostgresStorage {
138
141
  async getCachedItem(key) {
139
142
  try {
140
143
  const result = await this.pool.query(
141
- "SELECT value FROM settings WHERE user_id = $1 AND key = $2",
144
+ "SELECT value FROM brz_settings WHERE user_id = $1 AND key = $2",
142
145
  [this.identity, key]
143
146
  );
144
147
  return result.rows.length > 0 ? result.rows[0].value : null;
@@ -153,7 +156,7 @@ class PostgresStorage {
153
156
  async setCachedItem(key, value) {
154
157
  try {
155
158
  await this.pool.query(
156
- `INSERT INTO settings (user_id, key, value) VALUES ($1, $2, $3)
159
+ `INSERT INTO brz_settings (user_id, key, value) VALUES ($1, $2, $3)
157
160
  ON CONFLICT(user_id, key) DO UPDATE SET value = EXCLUDED.value`,
158
161
  [this.identity, key, value]
159
162
  );
@@ -168,7 +171,7 @@ class PostgresStorage {
168
171
  async deleteCachedItem(key) {
169
172
  try {
170
173
  await this.pool.query(
171
- "DELETE FROM settings WHERE user_id = $1 AND key = $2",
174
+ "DELETE FROM brz_settings WHERE user_id = $1 AND key = $2",
172
175
  [this.identity, key]
173
176
  );
174
177
  } catch (error) {
@@ -364,7 +367,7 @@ class PostgresStorage {
364
367
  const spark = payment.details?.type === "spark" ? true : null;
365
368
 
366
369
  await client.query(
367
- `INSERT INTO payments (user_id, id, payment_type, status, amount, fees, timestamp, method, withdraw_tx_id, deposit_tx_id, spark)
370
+ `INSERT INTO brz_payments (user_id, id, payment_type, status, amount, fees, timestamp, method, withdraw_tx_id, deposit_tx_id, spark)
368
371
  VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)
369
372
  ON CONFLICT(user_id, id) DO UPDATE SET
370
373
  payment_type=EXCLUDED.payment_type,
@@ -397,11 +400,11 @@ class PostgresStorage {
397
400
  payment.details.htlcDetails != null)
398
401
  ) {
399
402
  await client.query(
400
- `INSERT INTO payment_details_spark (user_id, payment_id, invoice_details, htlc_details)
403
+ `INSERT INTO brz_payment_details_spark (user_id, payment_id, invoice_details, htlc_details)
401
404
  VALUES ($1, $2, $3, $4)
402
405
  ON CONFLICT(user_id, payment_id) DO UPDATE SET
403
- invoice_details=COALESCE(EXCLUDED.invoice_details, payment_details_spark.invoice_details),
404
- htlc_details=COALESCE(EXCLUDED.htlc_details, payment_details_spark.htlc_details)`,
406
+ invoice_details=COALESCE(EXCLUDED.invoice_details, brz_payment_details_spark.invoice_details),
407
+ htlc_details=COALESCE(EXCLUDED.htlc_details, brz_payment_details_spark.htlc_details)`,
405
408
  [
406
409
  this.identity,
407
410
  payment.id,
@@ -417,7 +420,7 @@ class PostgresStorage {
417
420
 
418
421
  if (payment.details?.type === "lightning") {
419
422
  await client.query(
420
- `INSERT INTO payment_details_lightning
423
+ `INSERT INTO brz_payment_details_lightning
421
424
  (user_id, payment_id, invoice, payment_hash, destination_pubkey, description, preimage, htlc_status, htlc_expiry_time)
422
425
  VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
423
426
  ON CONFLICT(user_id, payment_id) DO UPDATE SET
@@ -425,9 +428,9 @@ class PostgresStorage {
425
428
  payment_hash=EXCLUDED.payment_hash,
426
429
  destination_pubkey=EXCLUDED.destination_pubkey,
427
430
  description=EXCLUDED.description,
428
- preimage=COALESCE(EXCLUDED.preimage, payment_details_lightning.preimage),
429
- htlc_status=COALESCE(EXCLUDED.htlc_status, payment_details_lightning.htlc_status),
430
- htlc_expiry_time=COALESCE(EXCLUDED.htlc_expiry_time, payment_details_lightning.htlc_expiry_time)`,
431
+ preimage=COALESCE(EXCLUDED.preimage, brz_payment_details_lightning.preimage),
432
+ htlc_status=COALESCE(EXCLUDED.htlc_status, brz_payment_details_lightning.htlc_status),
433
+ htlc_expiry_time=COALESCE(EXCLUDED.htlc_expiry_time, brz_payment_details_lightning.htlc_expiry_time)`,
431
434
  [
432
435
  this.identity,
433
436
  payment.id,
@@ -444,14 +447,14 @@ class PostgresStorage {
444
447
 
445
448
  if (payment.details?.type === "token") {
446
449
  await client.query(
447
- `INSERT INTO payment_details_token
450
+ `INSERT INTO brz_payment_details_token
448
451
  (user_id, payment_id, metadata, tx_hash, tx_type, invoice_details)
449
452
  VALUES ($1, $2, $3, $4, $5, $6)
450
453
  ON CONFLICT(user_id, payment_id) DO UPDATE SET
451
454
  metadata=EXCLUDED.metadata,
452
455
  tx_hash=EXCLUDED.tx_hash,
453
456
  tx_type=EXCLUDED.tx_type,
454
- invoice_details=COALESCE(EXCLUDED.invoice_details, payment_details_token.invoice_details)`,
457
+ invoice_details=COALESCE(EXCLUDED.invoice_details, brz_payment_details_token.invoice_details)`,
455
458
  [
456
459
  this.identity,
457
460
  payment.id,
@@ -532,7 +535,7 @@ class PostgresStorage {
532
535
 
533
536
  // Early exit if no related payments exist for this tenant
534
537
  const hasRelatedResult = await this.pool.query(
535
- "SELECT EXISTS(SELECT 1 FROM payment_metadata WHERE user_id = $1 AND parent_payment_id IS NOT NULL LIMIT 1)",
538
+ "SELECT EXISTS(SELECT 1 FROM brz_payment_metadata WHERE user_id = $1 AND parent_payment_id IS NOT NULL LIMIT 1)",
536
539
  [this.identity]
537
540
  );
538
541
  if (!hasRelatedResult.rows[0].exists) {
@@ -572,15 +575,15 @@ class PostgresStorage {
572
575
  async insertPaymentMetadata(paymentId, metadata) {
573
576
  try {
574
577
  await this.pool.query(
575
- `INSERT INTO payment_metadata (user_id, payment_id, parent_payment_id, lnurl_pay_info, lnurl_withdraw_info, lnurl_description, conversion_info, conversion_status)
578
+ `INSERT INTO brz_payment_metadata (user_id, payment_id, parent_payment_id, lnurl_pay_info, lnurl_withdraw_info, lnurl_description, conversion_info, conversion_status)
576
579
  VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
577
580
  ON CONFLICT(user_id, payment_id) DO UPDATE SET
578
- parent_payment_id = COALESCE(EXCLUDED.parent_payment_id, payment_metadata.parent_payment_id),
579
- lnurl_pay_info = COALESCE(EXCLUDED.lnurl_pay_info, payment_metadata.lnurl_pay_info),
580
- lnurl_withdraw_info = COALESCE(EXCLUDED.lnurl_withdraw_info, payment_metadata.lnurl_withdraw_info),
581
- lnurl_description = COALESCE(EXCLUDED.lnurl_description, payment_metadata.lnurl_description),
582
- conversion_info = COALESCE(EXCLUDED.conversion_info, payment_metadata.conversion_info),
583
- conversion_status = COALESCE(EXCLUDED.conversion_status, payment_metadata.conversion_status)`,
581
+ parent_payment_id = COALESCE(EXCLUDED.parent_payment_id, brz_payment_metadata.parent_payment_id),
582
+ lnurl_pay_info = COALESCE(EXCLUDED.lnurl_pay_info, brz_payment_metadata.lnurl_pay_info),
583
+ lnurl_withdraw_info = COALESCE(EXCLUDED.lnurl_withdraw_info, brz_payment_metadata.lnurl_withdraw_info),
584
+ lnurl_description = COALESCE(EXCLUDED.lnurl_description, brz_payment_metadata.lnurl_description),
585
+ conversion_info = COALESCE(EXCLUDED.conversion_info, brz_payment_metadata.conversion_info),
586
+ conversion_status = COALESCE(EXCLUDED.conversion_status, brz_payment_metadata.conversion_status)`,
584
587
  [
585
588
  this.identity,
586
589
  paymentId,
@@ -611,7 +614,7 @@ class PostgresStorage {
611
614
  async addDeposit(txid, vout, amountSats, isMature) {
612
615
  try {
613
616
  await this.pool.query(
614
- `INSERT INTO unclaimed_deposits (user_id, txid, vout, amount_sats, is_mature)
617
+ `INSERT INTO brz_unclaimed_deposits (user_id, txid, vout, amount_sats, is_mature)
615
618
  VALUES ($1, $2, $3, $4, $5)
616
619
  ON CONFLICT(user_id, txid, vout) DO UPDATE SET is_mature = EXCLUDED.is_mature, amount_sats = EXCLUDED.amount_sats`,
617
620
  [this.identity, txid, vout, amountSats, isMature]
@@ -627,7 +630,7 @@ class PostgresStorage {
627
630
  async deleteDeposit(txid, vout) {
628
631
  try {
629
632
  await this.pool.query(
630
- "DELETE FROM unclaimed_deposits WHERE user_id = $1 AND txid = $2 AND vout = $3",
633
+ "DELETE FROM brz_unclaimed_deposits WHERE user_id = $1 AND txid = $2 AND vout = $3",
631
634
  [this.identity, txid, vout]
632
635
  );
633
636
  } catch (error) {
@@ -641,7 +644,7 @@ class PostgresStorage {
641
644
  async listDeposits() {
642
645
  try {
643
646
  const result = await this.pool.query(
644
- "SELECT txid, vout, amount_sats, is_mature, claim_error, refund_tx, refund_tx_id FROM unclaimed_deposits WHERE user_id = $1",
647
+ "SELECT txid, vout, amount_sats, is_mature, claim_error, refund_tx, refund_tx_id FROM brz_unclaimed_deposits WHERE user_id = $1",
645
648
  [this.identity]
646
649
  );
647
650
 
@@ -666,14 +669,14 @@ class PostgresStorage {
666
669
  try {
667
670
  if (payload.type === "claimError") {
668
671
  await this.pool.query(
669
- `UPDATE unclaimed_deposits
672
+ `UPDATE brz_unclaimed_deposits
670
673
  SET claim_error = $1, refund_tx = NULL, refund_tx_id = NULL
671
674
  WHERE user_id = $2 AND txid = $3 AND vout = $4`,
672
675
  [JSON.stringify(payload.error), this.identity, txid, vout]
673
676
  );
674
677
  } else if (payload.type === "refund") {
675
678
  await this.pool.query(
676
- `UPDATE unclaimed_deposits
679
+ `UPDATE brz_unclaimed_deposits
677
680
  SET refund_tx = $1, refund_tx_id = $2, claim_error = NULL
678
681
  WHERE user_id = $3 AND txid = $4 AND vout = $5`,
679
682
  [payload.refundTx, payload.refundTxid, this.identity, txid, vout]
@@ -695,7 +698,7 @@ class PostgresStorage {
695
698
  await this._withTransaction(async (client) => {
696
699
  for (const item of metadata) {
697
700
  await client.query(
698
- `INSERT INTO lnurl_receive_metadata (user_id, payment_hash, nostr_zap_request, nostr_zap_receipt, sender_comment)
701
+ `INSERT INTO brz_lnurl_receive_metadata (user_id, payment_hash, nostr_zap_request, nostr_zap_receipt, sender_comment)
699
702
  VALUES ($1, $2, $3, $4, $5)
700
703
  ON CONFLICT(user_id, payment_hash) DO UPDATE SET
701
704
  nostr_zap_request = EXCLUDED.nostr_zap_request,
@@ -856,7 +859,7 @@ class PostgresStorage {
856
859
 
857
860
  const result = await this.pool.query(
858
861
  `SELECT id, name, payment_identifier, created_at, updated_at
859
- FROM contacts
862
+ FROM brz_contacts
860
863
  WHERE user_id = $1
861
864
  ORDER BY name ASC
862
865
  LIMIT $2 OFFSET $3`,
@@ -882,7 +885,7 @@ class PostgresStorage {
882
885
  try {
883
886
  const result = await this.pool.query(
884
887
  `SELECT id, name, payment_identifier, created_at, updated_at
885
- FROM contacts
888
+ FROM brz_contacts
886
889
  WHERE user_id = $1 AND id = $2`,
887
890
  [this.identity, id]
888
891
  );
@@ -910,7 +913,7 @@ class PostgresStorage {
910
913
  async insertContact(contact) {
911
914
  try {
912
915
  await this.pool.query(
913
- `INSERT INTO contacts (user_id, id, name, payment_identifier, created_at, updated_at)
916
+ `INSERT INTO brz_contacts (user_id, id, name, payment_identifier, created_at, updated_at)
914
917
  VALUES ($1, $2, $3, $4, $5, $6)
915
918
  ON CONFLICT(user_id, id) DO UPDATE SET
916
919
  name = EXCLUDED.name,
@@ -936,7 +939,7 @@ class PostgresStorage {
936
939
  async deleteContact(id) {
937
940
  try {
938
941
  await this.pool.query(
939
- "DELETE FROM contacts WHERE user_id = $1 AND id = $2",
942
+ "DELETE FROM brz_contacts WHERE user_id = $1 AND id = $2",
940
943
  [this.identity, id]
941
944
  );
942
945
  } catch (error) {
@@ -954,13 +957,13 @@ class PostgresStorage {
954
957
  return await this._withTransaction(async (client) => {
955
958
  // Local queue revision is per-tenant — two tenants don't share a queue.
956
959
  const revisionResult = await client.query(
957
- "SELECT COALESCE(MAX(revision), 0) + 1 AS revision FROM sync_outgoing WHERE user_id = $1",
960
+ "SELECT COALESCE(MAX(revision), 0) + 1 AS revision FROM brz_sync_outgoing WHERE user_id = $1",
958
961
  [this.identity]
959
962
  );
960
963
  const revision = BigInt(revisionResult.rows[0].revision);
961
964
 
962
965
  await client.query(
963
- `INSERT INTO sync_outgoing (
966
+ `INSERT INTO brz_sync_outgoing (
964
967
  user_id,
965
968
  record_type,
966
969
  data_id,
@@ -995,7 +998,7 @@ class PostgresStorage {
995
998
  try {
996
999
  await this._withTransaction(async (client) => {
997
1000
  const deleteResult = await client.query(
998
- "DELETE FROM sync_outgoing WHERE user_id = $1 AND record_type = $2 AND data_id = $3 AND revision = $4",
1001
+ "DELETE FROM brz_sync_outgoing WHERE user_id = $1 AND record_type = $2 AND data_id = $3 AND revision = $4",
999
1002
  [
1000
1003
  this.identity,
1001
1004
  record.id.type,
@@ -1005,7 +1008,7 @@ class PostgresStorage {
1005
1008
  );
1006
1009
 
1007
1010
  if (deleteResult.rowCount === 0) {
1008
- const msg = `complete_outgoing_sync: DELETE from sync_outgoing matched 0 rows (type=${record.id.type}, data_id=${record.id.dataId}, revision=${localRevision})`;
1011
+ const msg = `complete_outgoing_sync: DELETE from brz_sync_outgoing matched 0 rows (type=${record.id.type}, data_id=${record.id.dataId}, revision=${localRevision})`;
1009
1012
  if (this.logger && typeof this.logger.log === "function") {
1010
1013
  this.logger.log({ line: msg, level: "warn" });
1011
1014
  } else {
@@ -1014,7 +1017,7 @@ class PostgresStorage {
1014
1017
  }
1015
1018
 
1016
1019
  await client.query(
1017
- `INSERT INTO sync_state (
1020
+ `INSERT INTO brz_sync_state (
1018
1021
  user_id,
1019
1022
  record_type,
1020
1023
  data_id,
@@ -1041,8 +1044,8 @@ class PostgresStorage {
1041
1044
 
1042
1045
  // Upsert this tenant's revision row; fresh tenants without a row get one.
1043
1046
  await client.query(
1044
- `INSERT INTO sync_revision (user_id, revision) VALUES ($1, $2)
1045
- ON CONFLICT (user_id) DO UPDATE SET revision = GREATEST(sync_revision.revision, EXCLUDED.revision)`,
1047
+ `INSERT INTO brz_sync_revision (user_id, revision) VALUES ($1, $2)
1048
+ ON CONFLICT (user_id) DO UPDATE SET revision = GREATEST(brz_sync_revision.revision, EXCLUDED.revision)`,
1046
1049
  [this.identity, record.revision.toString()]
1047
1050
  );
1048
1051
  });
@@ -1069,8 +1072,8 @@ class PostgresStorage {
1069
1072
  e.commit_time as existing_commit_time,
1070
1073
  e.data as existing_data,
1071
1074
  e.revision as existing_revision
1072
- FROM sync_outgoing o
1073
- LEFT JOIN sync_state e ON
1075
+ FROM brz_sync_outgoing o
1076
+ LEFT JOIN brz_sync_state e ON
1074
1077
  o.record_type = e.record_type AND
1075
1078
  o.data_id = e.data_id AND
1076
1079
  o.user_id = e.user_id
@@ -1124,7 +1127,7 @@ class PostgresStorage {
1124
1127
  try {
1125
1128
  // A tenant that hasn't synced anything yet may have no row; treat as 0.
1126
1129
  const result = await this.pool.query(
1127
- "SELECT revision FROM sync_revision WHERE user_id = $1",
1130
+ "SELECT revision FROM brz_sync_revision WHERE user_id = $1",
1128
1131
  [this.identity]
1129
1132
  );
1130
1133
  return result.rows.length > 0
@@ -1147,7 +1150,7 @@ class PostgresStorage {
1147
1150
  await this._withTransaction(async (client) => {
1148
1151
  for (const record of records) {
1149
1152
  await client.query(
1150
- `INSERT INTO sync_incoming (
1153
+ `INSERT INTO brz_sync_incoming (
1151
1154
  user_id,
1152
1155
  record_type,
1153
1156
  data_id,
@@ -1184,7 +1187,7 @@ class PostgresStorage {
1184
1187
  async syncDeleteIncomingRecord(record) {
1185
1188
  try {
1186
1189
  await this.pool.query(
1187
- `DELETE FROM sync_incoming
1190
+ `DELETE FROM brz_sync_incoming
1188
1191
  WHERE user_id = $1
1189
1192
  AND record_type = $2
1190
1193
  AND data_id = $3
@@ -1211,8 +1214,8 @@ class PostgresStorage {
1211
1214
  e.commit_time AS existing_commit_time,
1212
1215
  e.data AS existing_data,
1213
1216
  e.revision AS existing_revision
1214
- FROM sync_incoming i
1215
- LEFT JOIN sync_state e ON i.record_type = e.record_type AND i.data_id = e.data_id AND i.user_id = e.user_id
1217
+ FROM brz_sync_incoming i
1218
+ LEFT JOIN brz_sync_state e ON i.record_type = e.record_type AND i.data_id = e.data_id AND i.user_id = e.user_id
1216
1219
  WHERE i.user_id = $1
1217
1220
  ORDER BY i.revision ASC
1218
1221
  LIMIT $2`,
@@ -1273,8 +1276,8 @@ class PostgresStorage {
1273
1276
  e.commit_time as existing_commit_time,
1274
1277
  e.data as existing_data,
1275
1278
  e.revision as existing_revision
1276
- FROM sync_outgoing o
1277
- LEFT JOIN sync_state e ON
1279
+ FROM brz_sync_outgoing o
1280
+ LEFT JOIN brz_sync_state e ON
1278
1281
  o.record_type = e.record_type AND
1279
1282
  o.data_id = e.data_id AND
1280
1283
  o.user_id = e.user_id
@@ -1332,7 +1335,7 @@ class PostgresStorage {
1332
1335
  try {
1333
1336
  await this._withTransaction(async (client) => {
1334
1337
  await client.query(
1335
- `INSERT INTO sync_state (
1338
+ `INSERT INTO brz_sync_state (
1336
1339
  user_id,
1337
1340
  record_type,
1338
1341
  data_id,
@@ -1358,8 +1361,8 @@ class PostgresStorage {
1358
1361
  );
1359
1362
 
1360
1363
  await client.query(
1361
- `INSERT INTO sync_revision (user_id, revision) VALUES ($1, $2)
1362
- ON CONFLICT (user_id) DO UPDATE SET revision = GREATEST(sync_revision.revision, EXCLUDED.revision)`,
1364
+ `INSERT INTO brz_sync_revision (user_id, revision) VALUES ($1, $2)
1365
+ ON CONFLICT (user_id) DO UPDATE SET revision = GREATEST(brz_sync_revision.revision, EXCLUDED.revision)`,
1363
1366
  [this.identity, record.revision.toString()]
1364
1367
  );
1365
1368
  });
@@ -1390,6 +1393,7 @@ function defaultPostgresStorageConfig(connectionString) {
1390
1393
  maxPoolSize: 10,
1391
1394
  createTimeoutSecs: 0,
1392
1395
  recycleTimeoutSecs: 10,
1396
+ runMigration: true,
1393
1397
  };
1394
1398
  }
1395
1399
 
@@ -1409,7 +1413,12 @@ function defaultPostgresStorageConfig(connectionString) {
1409
1413
  */
1410
1414
  async function createPostgresStorage(config, identity, logger = null) {
1411
1415
  const pool = createPostgresPool(config);
1412
- return createPostgresStorageWithPool(pool, identity, logger);
1416
+ return createPostgresStorageWithPool(
1417
+ pool,
1418
+ identity,
1419
+ logger,
1420
+ config.runMigration !== false
1421
+ );
1413
1422
  }
1414
1423
 
1415
1424
  /**
@@ -1436,8 +1445,18 @@ function createPostgresPool(config) {
1436
1445
  * @param {object} [logger] - Optional logger
1437
1446
  * @returns {Promise<PostgresStorage>}
1438
1447
  */
1439
- async function createPostgresStorageWithPool(pool, identity, logger = null) {
1440
- const storage = new PostgresStorage(pool, identity, logger);
1448
+ async function createPostgresStorageWithPool(
1449
+ pool,
1450
+ identity,
1451
+ logger = null,
1452
+ runMigration = true
1453
+ ) {
1454
+ const storage = new PostgresStorage(
1455
+ pool,
1456
+ identity,
1457
+ logger,
1458
+ runMigration
1459
+ );
1441
1460
  await storage.initialize();
1442
1461
  return storage;
1443
1462
  }