Move custom domains onto trust centers
Custom domains previously hung off the organization. Attach them to the trust center instead, adding default and custom domain references plus a managed flag, and backfill existing rows. Domains now belong to a compliance page rather than the whole organization. Signed-off-by: Bryan Frimin <bryan@probo.com>
This commit is contained in:
33
pkg/coredata/migrations/20260706T132923Z.sql
Normal file
33
pkg/coredata/migrations/20260706T132923Z.sql
Normal file
@@ -0,0 +1,33 @@
|
||||
-- Copyright (c) 2026 Probo Inc <hello@probo.com>.
|
||||
--
|
||||
-- Permission to use, copy, modify, and/or distribute this software for any
|
||||
-- purpose with or without fee is hereby granted, provided that the above
|
||||
-- copyright notice and this permission notice appear in all copies.
|
||||
--
|
||||
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
-- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
-- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
-- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
-- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
-- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
-- PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
ALTER TABLE custom_domains ADD COLUMN managed BOOLEAN NOT NULL DEFAULT FALSE;
|
||||
ALTER TABLE custom_domains ALTER COLUMN managed DROP DEFAULT;
|
||||
|
||||
ALTER TABLE trust_centers ADD COLUMN default_domain_id TEXT REFERENCES custom_domains(id) ON DELETE SET NULL;
|
||||
ALTER TABLE trust_centers ADD COLUMN custom_domain_id TEXT REFERENCES custom_domains(id) ON DELETE SET NULL;
|
||||
|
||||
UPDATE trust_centers tc
|
||||
SET custom_domain_id = o.custom_domain_id
|
||||
FROM organizations o
|
||||
WHERE o.id = tc.organization_id AND o.custom_domain_id IS NOT NULL;
|
||||
|
||||
DELETE FROM custom_domains cd
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1 FROM trust_centers tc
|
||||
WHERE tc.custom_domain_id = cd.id OR tc.default_domain_id = cd.id
|
||||
);
|
||||
|
||||
DROP INDEX IF EXISTS idx_organizations_custom_domain;
|
||||
ALTER TABLE organizations DROP COLUMN custom_domain_id;
|
||||
Reference in New Issue
Block a user