Skip to content

Commit a8d3c1a

Browse files
committed
db/sqlc: only use named UNIQUE indices
Replace any named UNIQUE indices in the accounts tables and replace with named ones. This is for a future where we want to be able to edit these indices without having to drop the table. It is fine for us to just edit these tables since these are not available in "prod" yet.
1 parent f082579 commit a8d3c1a

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

db/sqlc/migrations/000001_accounts.down.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
DROP INDEX IF EXISTS account_invoices_unique;
2+
DROP INDEX IF EXISTS account_payments_unique;
13
DROP TABLE IF EXISTS account_payments;
24
DROP TABLE IF EXISTS account_invoices;
35
DROP TABLE IF EXISTS account_indices;

db/sqlc/migrations/000001_accounts.up.sql

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@ CREATE TABLE IF NOT EXISTS account_payments (
4242

4343
-- The total amount of the payment in millisatoshis.
4444
-- This includes the payment amount and estimated routing fee.
45-
full_amount_msat BIGINT NOT NULL,
45+
full_amount_msat BIGINT NOT NULL
46+
);
4647

47-
UNIQUE(account_id, hash)
48+
CREATE UNIQUE INDEX account_payments_unique ON account_payments (
49+
account_id, hash
4850
);
4951

5052
-- The account_invoices table stores all the invoice payment hashes that
@@ -55,9 +57,11 @@ CREATE TABLE IF NOT EXISTS account_invoices (
5557
account_id BIGINT NOT NULL REFERENCES accounts(id) ON DELETE CASCADE,
5658

5759
-- The payment hash of the invoice.
58-
hash BLOB NOT NULL,
60+
hash BLOB NOT NULL
61+
);
5962

60-
UNIQUE(account_id, hash)
63+
CREATE UNIQUE INDEX account_invoices_unique ON account_invoices (
64+
account_id, hash
6165
);
6266

6367
-- The account_indices table stores any string-to-integer mappings that are

0 commit comments

Comments
 (0)