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:
@@ -707,17 +707,19 @@ func clearMonitoringData(ctx context.Context, tx pgx.Tx, state *seedState) error
|
||||
singles := []string{
|
||||
`DELETE FROM monitoring_platform_access_snapshots WHERE tenant_id = $1`,
|
||||
`DELETE FROM monitoring_article_url_aliases WHERE tenant_id = $1`,
|
||||
`DELETE FROM site_domain_mappings WHERE tenant_id = $1`,
|
||||
}
|
||||
for _, query := range singles {
|
||||
if _, err := tx.Exec(ctx, query, state.TenantID); err != nil {
|
||||
return wrapSeedErr("clear monitoring data", err)
|
||||
}
|
||||
}
|
||||
if _, err := tx.Exec(ctx, `DELETE FROM site_domain_mappings`); err != nil {
|
||||
return wrapSeedErr("clear site mappings", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func insertSiteMappings(ctx context.Context, tx pgx.Tx, tenantID int64) error {
|
||||
func insertSiteMappings(ctx context.Context, tx pgx.Tx, _ int64) error {
|
||||
mappings := []struct {
|
||||
domain string
|
||||
siteKey string
|
||||
@@ -729,9 +731,14 @@ func insertSiteMappings(ctx context.Context, tx pgx.Tx, tenantID int64) error {
|
||||
}
|
||||
for _, item := range mappings {
|
||||
if _, err := tx.Exec(ctx, `
|
||||
INSERT INTO site_domain_mappings (tenant_id, registrable_domain, site_key, site_name, is_active)
|
||||
VALUES ($1, $2, $3, $4, TRUE)
|
||||
`, tenantID, item.domain, item.siteKey, item.siteName); err != nil {
|
||||
INSERT INTO site_domain_mappings (registrable_domain, site_key, site_name, is_active)
|
||||
VALUES ($1, $2, $3, TRUE)
|
||||
ON CONFLICT (registrable_domain) DO UPDATE
|
||||
SET site_key = EXCLUDED.site_key,
|
||||
site_name = EXCLUDED.site_name,
|
||||
is_active = EXCLUDED.is_active,
|
||||
updated_at = NOW()
|
||||
`, item.domain, item.siteKey, item.siteName); err != nil {
|
||||
return wrapSeedErr("insert site mapping", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user