bug double subscription

This commit is contained in:
Alessio
2026-06-02 21:30:09 +02:00
parent 93be8add4e
commit 938e19c84f
16 changed files with 317 additions and 21 deletions

View File

@@ -57,6 +57,8 @@ CREATE TABLE subscription_payments (
user_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE,
subscription_id uuid NOT NULL REFERENCES subscriptions(id) ON DELETE CASCADE,
renewal_date text NOT NULL,
title text NOT NULL,
amount double precision NOT NULL CHECK (amount > 0),
status text NOT NULL,
payment_date text,
linked_payment_id uuid,

View File

@@ -0,0 +1,22 @@
ALTER TABLE subscription_payments
ADD COLUMN IF NOT EXISTS title text,
ADD COLUMN IF NOT EXISTS amount double precision;
UPDATE subscription_payments AS payment
SET
title = subscription.title,
amount = subscription.amount
FROM subscriptions AS subscription
WHERE
subscription.id = payment.subscription_id
AND (payment.title IS NULL OR payment.amount IS NULL);
ALTER TABLE subscription_payments
ALTER COLUMN title SET NOT NULL,
ALTER COLUMN amount SET NOT NULL;
ALTER TABLE subscription_payments
DROP CONSTRAINT IF EXISTS subscription_payments_amount_positive;
ALTER TABLE subscription_payments
ADD CONSTRAINT subscription_payments_amount_positive CHECK (amount > 0);