store: add the invoiced units migration

This commit is contained in:
sh-agents committed 2026-11-02 06:58:36 +00:00
1 parent 15f631c901
commit 71c31706e8
2 files changed
+48 -2

No files matched your search

@@ -25,7 +25,8 @@ schemaMigrations =
("20261022_drop_taken_codes", m20261022_drop_taken_codes, Just down_m20261022_drop_taken_codes),
("20261022_name_balances", m20261022_name_balances, Just down_m20261022_name_balances),
("20261022_name_late_wait", m20261022_name_late_wait, Just down_m20261022_name_late_wait),
("20261023_name_terms", m20261023_name_terms, Just down_m20261023_name_terms)
("20261023_name_terms", m20261023_name_terms, Just down_m20261023_name_terms),
("20261027_name_invoiced_units", m20261027_name_invoiced_units, Just down_m20261027_name_invoiced_units)
]
-- | The client tables share this database, so the service tables are the same names behind a prefix.
@@ -597,6 +598,28 @@ down_m20261023_name_terms =
ALTER TABLE @name_registrations DROP COLUMN agreed_terms;
|]
-- The crypto a payment's invoice asks in atomic units, network fee included, which late and overpaid crypto is a price share of.
-- The partial index holds the overpaid payments, which the poller's credit pass reads on every pass.
m20261027_name_invoiced_units :: Text
m20261027_name_invoiced_units =
withPrefix
servicePrefix
[r|
ALTER TABLE @payments ADD COLUMN invoiced_units BIGINT;
CREATE INDEX @idx_payments_overpaid ON @payments(invoice_id) WHERE received_units > invoiced_units;
|]
down_m20261027_name_invoiced_units :: Text
down_m20261027_name_invoiced_units =
withPrefix
servicePrefix
[r|
DROP INDEX @idx_payments_overpaid;
ALTER TABLE @payments DROP COLUMN invoiced_units;
|]
{- TODO [badges] deferred with the draft in M20260915_user_badges, service only.
ALTER TABLE @payments ADD COLUMN receipt_hash BYTEA;
@@ -26,7 +26,8 @@ schemaMigrations =
("20261022_drop_taken_codes", m20261022_drop_taken_codes, Just down_m20261022_drop_taken_codes),
("20261022_name_balances", m20261022_name_balances, Just down_m20261022_name_balances),
("20261022_name_late_wait", m20261022_name_late_wait, Just down_m20261022_name_late_wait),
("20261023_name_terms", m20261023_name_terms, Just down_m20261023_name_terms)
("20261023_name_terms", m20261023_name_terms, Just down_m20261023_name_terms),
("20261027_name_invoiced_units", m20261027_name_invoiced_units, Just down_m20261027_name_invoiced_units)
]
-- | The client tables share this database, so the service tables are the same names behind a prefix.
@@ -599,6 +600,28 @@ down_m20261023_name_terms =
ALTER TABLE @name_registrations DROP COLUMN agreed_terms;
|]
-- The crypto a payment's invoice asks in atomic units, network fee included, which late and overpaid crypto is a price share of.
-- The partial index holds the overpaid payments, which the poller's credit pass reads on every pass.
m20261027_name_invoiced_units :: Query
m20261027_name_invoiced_units =
withPrefix
servicePrefix
[sql|
ALTER TABLE @payments ADD COLUMN invoiced_units INTEGER;
CREATE INDEX @idx_payments_overpaid ON @payments(invoice_id) WHERE received_units > invoiced_units;
|]
down_m20261027_name_invoiced_units :: Query
down_m20261027_name_invoiced_units =
withPrefix
servicePrefix
[sql|
DROP INDEX @idx_payments_overpaid;
ALTER TABLE @payments DROP COLUMN invoiced_units;
|]
{- TODO [badges] deferred with the draft in M20260915_user_badges, service only.
ALTER TABLE @payments ADD COLUMN receipt_hash BLOB;