From 24743f99868f48dc9125c60180e1bfc24141bbd4 Mon Sep 17 00:00:00 2001 From: Rotimi Best Date: Wed, 5 Aug 2026 14:45:11 +0100 Subject: [PATCH] chore(db): add enterprise upgrade SQL script --- .../sql/upgrade-udemy-test-to-enterprise.sql | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 packages/db/scripts/sql/upgrade-udemy-test-to-enterprise.sql diff --git a/packages/db/scripts/sql/upgrade-udemy-test-to-enterprise.sql b/packages/db/scripts/sql/upgrade-udemy-test-to-enterprise.sql new file mode 100644 index 00000000..634304f5 --- /dev/null +++ b/packages/db/scripts/sql/upgrade-udemy-test-to-enterprise.sql @@ -0,0 +1,51 @@ +-- Replace 'udemy-test' with the siteName of the org. + +WITH target_org AS ( + SELECT COALESCE(parent_organization_id, id) AS id + FROM organization + WHERE "siteName" = 'udemy-test' +), +deactivated_plans AS ( + UPDATE organization_plan + SET + is_active = false, + deactivated_at = now(), + updated_at = now() + WHERE org_id = (SELECT id FROM target_org) + AND is_active IS TRUE + AND subscription_id IS DISTINCT FROM 'manual-enterprise:udemy-test' +) +INSERT INTO organization_plan ( + org_id, + plan_name, + is_active, + triggered_by, + provider, + subscription_id +) +SELECT + target_org.id, + 'ENTERPRISE', + true, + ( + SELECT id + FROM organizationmember + WHERE organization_id = target_org.id + AND role_id = 1 + ORDER BY verified DESC, id + LIMIT 1 + ), + 'manual', + 'manual-enterprise:udemy-test' +FROM target_org +ON CONFLICT (subscription_id) DO UPDATE +SET + org_id = EXCLUDED.org_id, + plan_name = 'ENTERPRISE', + is_active = true, + activated_at = now(), + deactivated_at = NULL, + updated_at = now(), + triggered_by = EXCLUDED.triggered_by, + provider = 'manual' +RETURNING *;