Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: migrate internal and keysend columns to be non null #442

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions db/migrations/20231030140000_invoice_internal.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
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;
9 changes: 9 additions & 0 deletions db/migrations/20231030140000_invoice_keysend.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if a default is set, do we then still need a NOT NULL constraint?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes because I've seen the db values go from false to NULL while running integration_tests for some reason

4 changes: 2 additions & 2 deletions db/models/invoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,default:false"`
Keysend bool `json:"keysend" bun:",notnull,default:false"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they still use nullzero:
https://bun.uptrace.dev/guide/models.html#default

nullzero,notnull,default:false ?

I think if "" (blank) is set then bun converts it to NULL which then uses the default of false.

State string `json:"state" bun:",default:'initialized'"`
ErrorMessage string `json:"error_message,omitempty" bun:",nullzero"`
AddIndex uint64 `json:"-" bun:",nullzero"`
Expand Down
Loading