From afaf6fd104b88df3794153d9482c22952955e4de Mon Sep 17 00:00:00 2001 From: im-adithya Date: Mon, 30 Oct 2023 17:43:57 +0530 Subject: [PATCH 1/2] chore: migrate internal and keysend columns to be non null --- db/migrations/20231030140000_invoice_internal.up.sql | 6 ++++++ db/migrations/20231030140000_invoice_keysend.up.sql | 6 ++++++ db/models/invoice.go | 4 ++-- 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 db/migrations/20231030140000_invoice_internal.up.sql create mode 100644 db/migrations/20231030140000_invoice_keysend.up.sql diff --git a/db/migrations/20231030140000_invoice_internal.up.sql b/db/migrations/20231030140000_invoice_internal.up.sql new file mode 100644 index 00000000..fe5fef2e --- /dev/null +++ b/db/migrations/20231030140000_invoice_internal.up.sql @@ -0,0 +1,6 @@ +UPDATE invoices +SET internal = false +WHERE internal IS NULL; + +ALTER TABLE invoices +ALTER COLUMN internal SET NOT NULL; \ No newline at end of file diff --git a/db/migrations/20231030140000_invoice_keysend.up.sql b/db/migrations/20231030140000_invoice_keysend.up.sql new file mode 100644 index 00000000..1f76e4b3 --- /dev/null +++ b/db/migrations/20231030140000_invoice_keysend.up.sql @@ -0,0 +1,6 @@ +UPDATE invoices +SET keysend = false +WHERE keysend IS NULL; + +ALTER TABLE invoices +ALTER COLUMN keysend SET NOT NULL; \ No newline at end of file diff --git a/db/models/invoice.go b/db/models/invoice.go index ba03e5fc..c9a84f6a 100644 --- a/db/models/invoice.go +++ b/db/models/invoice.go @@ -22,8 +22,8 @@ type Invoice struct { DestinationCustomRecords map[uint64][]byte `json:"custom_records,omitempty"` RHash string `json:"r_hash"` Preimage string `json:"preimage" bun:",nullzero"` - Internal bool `json:"-" bun:",nullzero"` - Keysend bool `json:"keysend" bun:",nullzero"` + Internal bool `json:"-" bun:",notnull"` + Keysend bool `json:"keysend" bun:",notnull"` State string `json:"state" bun:",default:'initialized'"` ErrorMessage string `json:"error_message,omitempty" bun:",nullzero"` AddIndex uint64 `json:"-" bun:",nullzero"` From b0af45c168b964ec6f398cfc2368d910a41775a1 Mon Sep 17 00:00:00 2001 From: im-adithya Date: Tue, 31 Oct 2023 16:41:54 +0530 Subject: [PATCH 2/2] chore: add default false to internal, keysend columns --- db/migrations/20231030140000_invoice_internal.up.sql | 3 +++ db/migrations/20231030140000_invoice_keysend.up.sql | 3 +++ db/models/invoice.go | 4 ++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/db/migrations/20231030140000_invoice_internal.up.sql b/db/migrations/20231030140000_invoice_internal.up.sql index fe5fef2e..5e64478a 100644 --- a/db/migrations/20231030140000_invoice_internal.up.sql +++ b/db/migrations/20231030140000_invoice_internal.up.sql @@ -2,5 +2,8 @@ UPDATE invoices SET internal = false WHERE internal IS NULL; +ALTER TABLE invoices +ALTER COLUMN internal SET DEFAULT false; + ALTER TABLE invoices ALTER COLUMN internal SET NOT NULL; \ No newline at end of file diff --git a/db/migrations/20231030140000_invoice_keysend.up.sql b/db/migrations/20231030140000_invoice_keysend.up.sql index 1f76e4b3..9409e9c5 100644 --- a/db/migrations/20231030140000_invoice_keysend.up.sql +++ b/db/migrations/20231030140000_invoice_keysend.up.sql @@ -2,5 +2,8 @@ UPDATE invoices SET keysend = false WHERE keysend IS NULL; +ALTER TABLE invoices +ALTER COLUMN keysend SET DEFAULT false; + ALTER TABLE invoices ALTER COLUMN keysend SET NOT NULL; \ No newline at end of file diff --git a/db/models/invoice.go b/db/models/invoice.go index c9a84f6a..ea005a5c 100644 --- a/db/models/invoice.go +++ b/db/models/invoice.go @@ -22,8 +22,8 @@ type Invoice struct { DestinationCustomRecords map[uint64][]byte `json:"custom_records,omitempty"` RHash string `json:"r_hash"` Preimage string `json:"preimage" bun:",nullzero"` - Internal bool `json:"-" bun:",notnull"` - Keysend bool `json:"keysend" bun:",notnull"` + Internal bool `json:"-" bun:",notnull,default:false"` + Keysend bool `json:"keysend" bun:",notnull,default:false"` State string `json:"state" bun:",default:'initialized'"` ErrorMessage string `json:"error_message,omitempty" bun:",nullzero"` AddIndex uint64 `json:"-" bun:",nullzero"`