diff --git a/apps/simplex-store-service/src/StoreService/Store/Postgres/Migrations.hs b/apps/simplex-store-service/src/StoreService/Store/Postgres/Migrations.hs index de89797bc0..74014fc6a4 100644 --- a/apps/simplex-store-service/src/StoreService/Store/Postgres/Migrations.hs +++ b/apps/simplex-store-service/src/StoreService/Store/Postgres/Migrations.hs @@ -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; diff --git a/apps/simplex-store-service/src/StoreService/Store/SQLite/Migrations.hs b/apps/simplex-store-service/src/StoreService/Store/SQLite/Migrations.hs index 3c678e93a7..922fec7431 100644 --- a/apps/simplex-store-service/src/StoreService/Store/SQLite/Migrations.hs +++ b/apps/simplex-store-service/src/StoreService/Store/SQLite/Migrations.hs @@ -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;