forked from coracle/caravel
fix(billing): ensure all tenants have valid Stripe customer IDs
This commit is contained in:
@@ -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;
|
||||
Reference in New Issue
Block a user