-- Copyright (c) 2026 Probo Inc . -- -- 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; INSERT INTO trust_centers ( id, organization_id, tenant_id, active, slug, search_engine_indexing, created_at, updated_at ) SELECT generate_gid(decode_base64_unpadded(o.tenant_id), 22), o.id, o.tenant_id, false, LOWER( REGEXP_REPLACE( REGEXP_REPLACE( unaccent(o.name), '[^a-zA-Z0-9\s]', '', 'g' ), '\s+', '-', 'g' ) ), 'NOT_INDEXABLE', NOW(), NOW() FROM organizations o WHERE o.custom_domain_id IS NOT NULL AND NOT EXISTS ( SELECT 1 FROM trust_centers tc WHERE tc.organization_id = o.id ); 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;