mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-13 09:15:22 +02:00
sqldb: make migration 1 and 3 idempotent
This commit is contained in:
@@ -1,12 +1,14 @@
|
|||||||
-- sequences contains all sequences used for invoices.
|
-- sequences contains all sequences used for invoices.
|
||||||
CREATE TABLE invoice_sequences (
|
CREATE TABLE IF NOT EXISTS invoice_sequences (
|
||||||
name TEXT PRIMARY KEY,
|
name TEXT PRIMARY KEY,
|
||||||
current_value BIGINT NOT NULL
|
current_value BIGINT NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
-- Initialize a sequence for the settled index used to track invoice settlement
|
-- Initialize a sequence for the settled index used to track invoice settlement
|
||||||
-- to remain compatible with the legacy channeldb implementation.
|
-- to remain compatible with the legacy channeldb implementation.
|
||||||
INSERT INTO invoice_sequences(name, current_value) VALUES ('settle_index', 0);
|
INSERT INTO invoice_sequences (name, current_value)
|
||||||
|
VALUES ('settle_index', 0)
|
||||||
|
ON CONFLICT (name) DO NOTHING;
|
||||||
|
|
||||||
-- invoices table contains all the information shared by all the invoice types.
|
-- invoices table contains all the information shared by all the invoice types.
|
||||||
CREATE TABLE IF NOT EXISTS invoices (
|
CREATE TABLE IF NOT EXISTS invoices (
|
||||||
|
@@ -5,26 +5,31 @@ CREATE TABLE IF NOT EXISTS invoice_event_types(
|
|||||||
description TEXT NOT NULL
|
description TEXT NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
-- invoice_event_types defines the different types of invoice events.
|
-- invoice_event_types defines the different types of invoice events.
|
||||||
|
-- Insert events explicitly, checking their existence first.
|
||||||
INSERT INTO invoice_event_types (id, description)
|
INSERT INTO invoice_event_types (id, description)
|
||||||
VALUES
|
SELECT id, description FROM (
|
||||||
-- invoice_created is the event type used when an invoice is created.
|
-- invoice_created is the event type used when an invoice is created.
|
||||||
(0, 'invoice_created'),
|
SELECT 0 AS id, 'invoice_created' AS description UNION ALL
|
||||||
-- invoice_canceled is the event type used when an invoice is canceled.
|
-- invoice_canceled is the event type used when an invoice is canceled.
|
||||||
(1, 'invoice_canceled'),
|
SELECT 1, 'invoice_canceled' UNION ALL
|
||||||
-- invoice_settled is the event type used when an invoice is settled.
|
-- invoice_settled is the event type used when an invoice is settled.
|
||||||
(2, 'invoice_settled'),
|
SELECT 2, 'invoice_settled' UNION ALL
|
||||||
-- setid_created is the event type used when an AMP sub invoice
|
-- setid_created is the event type used when an AMP sub invoice
|
||||||
-- corresponding to the set_id is created.
|
-- corresponding to the set_id is created.
|
||||||
(3, 'setid_created'),
|
SELECT 3, 'setid_created' UNION ALL
|
||||||
-- setid_canceled is the event type used when an AMP sub invoice
|
-- setid_canceled is the event type used when an AMP sub invoice
|
||||||
-- corresponding to the set_id is canceled.
|
-- corresponding to the set_id is canceled.
|
||||||
(4, 'setid_canceled'),
|
SELECT 4, 'setid_canceled' UNION ALL
|
||||||
-- setid_settled is the event type used when an AMP sub invoice
|
-- setid_settled is the event type used when an AMP sub invoice
|
||||||
-- corresponding to the set_id is settled.
|
-- corresponding to the set_id is settled.
|
||||||
(5, 'setid_settled');
|
SELECT 5, 'setid_settled'
|
||||||
|
) AS new_values
|
||||||
|
WHERE NOT EXISTS (
|
||||||
|
SELECT 1 FROM invoice_event_types
|
||||||
|
WHERE invoice_event_types.id = new_values.id
|
||||||
|
);
|
||||||
-- invoice_events stores all major events related to the node's invoices and
|
-- invoice_events stores all major events related to the node's invoices and
|
||||||
-- AMP sub invoices. This table can be used to create a historical view of what
|
-- AMP sub invoices. This table can be used to create a historical view of what
|
||||||
-- happened to the node's invoices.
|
-- happened to the node's invoices.
|
||||||
|
Reference in New Issue
Block a user