feat(monitoring/site-mappings): globalize site_domain_mappings
Drop tenant scoping on site_domain_mappings now that the citation query resolves mappings without tenant filtering. Add a unique index on registrable_domain plus an updated_at column, and switch the dev-seed upsert to use ON CONFLICT (registrable_domain). Adds a SiteDomainMapping type to ops/domain for the upcoming console management UI.
This commit is contained in:
@@ -152,16 +152,22 @@ CREATE INDEX idx_citation_facts_run
|
||||
|
||||
CREATE TABLE site_domain_mappings (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
tenant_id BIGINT,
|
||||
registrable_domain VARCHAR(255) NOT NULL,
|
||||
site_key VARCHAR(255) NOT NULL,
|
||||
site_name VARCHAR(255) NOT NULL,
|
||||
is_active BOOLEAN NOT NULL DEFAULT true,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
CREATE INDEX idx_site_domain_mappings_lookup
|
||||
ON site_domain_mappings(tenant_id, registrable_domain, is_active);
|
||||
CREATE UNIQUE INDEX uk_site_domain_mappings_domain
|
||||
ON site_domain_mappings(registrable_domain);
|
||||
|
||||
CREATE INDEX idx_site_domain_mappings_active_domain
|
||||
ON site_domain_mappings(registrable_domain) WHERE is_active = TRUE;
|
||||
|
||||
CREATE INDEX idx_site_domain_mappings_created
|
||||
ON site_domain_mappings(created_at DESC, id DESC);
|
||||
|
||||
CREATE TABLE monitoring_article_url_aliases (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
DROP INDEX IF EXISTS idx_site_domain_mappings_created;
|
||||
DROP INDEX IF EXISTS idx_site_domain_mappings_active_domain;
|
||||
DROP INDEX IF EXISTS uk_site_domain_mappings_domain;
|
||||
|
||||
ALTER TABLE site_domain_mappings
|
||||
ADD COLUMN IF NOT EXISTS tenant_id BIGINT,
|
||||
DROP COLUMN IF EXISTS updated_at;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_site_domain_mappings_lookup
|
||||
ON site_domain_mappings(tenant_id, registrable_domain, is_active);
|
||||
@@ -0,0 +1,24 @@
|
||||
UPDATE site_domain_mappings
|
||||
SET registrable_domain = LOWER(TRIM(registrable_domain)),
|
||||
site_key = LOWER(TRIM(site_key)),
|
||||
site_name = TRIM(site_name);
|
||||
|
||||
DELETE FROM site_domain_mappings older
|
||||
USING site_domain_mappings newer
|
||||
WHERE older.registrable_domain = newer.registrable_domain
|
||||
AND older.id < newer.id;
|
||||
|
||||
DROP INDEX IF EXISTS idx_site_domain_mappings_lookup;
|
||||
|
||||
ALTER TABLE site_domain_mappings
|
||||
DROP COLUMN IF EXISTS tenant_id,
|
||||
ADD COLUMN IF NOT EXISTS updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW();
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS uk_site_domain_mappings_domain
|
||||
ON site_domain_mappings(registrable_domain);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_site_domain_mappings_active_domain
|
||||
ON site_domain_mappings(registrable_domain) WHERE is_active = TRUE;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_site_domain_mappings_created
|
||||
ON site_domain_mappings(created_at DESC, id DESC);
|
||||
Reference in New Issue
Block a user