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);