fix(billing): ensure all tenants have valid Stripe customer IDs

This commit is contained in:
2026-04-11 17:28:58 +05:45
parent 2bdd4280d5
commit 3ae540e437
4 changed files with 180 additions and 44 deletions
@@ -0,0 +1,19 @@
CREATE UNIQUE INDEX IF NOT EXISTS tenant_stripe_customer_id_unique
ON tenant(stripe_customer_id)
WHERE stripe_customer_id <> '';
CREATE TRIGGER IF NOT EXISTS tenant_stripe_customer_id_not_empty_insert
BEFORE INSERT ON tenant
FOR EACH ROW
WHEN trim(NEW.stripe_customer_id) = ''
BEGIN
SELECT RAISE(ABORT, 'stripe_customer_id cannot be empty');
END;
CREATE TRIGGER IF NOT EXISTS tenant_stripe_customer_id_not_empty_update
BEFORE UPDATE OF stripe_customer_id ON tenant
FOR EACH ROW
WHEN trim(NEW.stripe_customer_id) = ''
BEGIN
SELECT RAISE(ABORT, 'stripe_customer_id cannot be empty');
END;