Skip to content

Commit c5e32e3

Browse files
Remove obsolete enrichment snapshot contract (#221)
Drops the short-lived commongrid enrichment snapshot objects that were introduced before the architecture pivot to direct REST consumption. Consumers should call CommonGrid's public APIs directly with caching; CommonGrid should not mirror its utility facts through a database view for private downstream systems. This migration idempotently removes: - commongrid.v_crm_org_enrichment - commongrid.v_utility_enrichment - commongrid.v_utilities_enriched - commongrid.enrichment_schema It intentionally keeps the commongrid schema and internal_api_consumer role, which remain useful as the generic server-to-server contract namespace for utility-name resolution and lifecycle signals. Also scrubs obsolete private-spec references from public SQL/test comments. Validation: - Applied migration against Neon successfully; commongrid has no tables, views, or functions after cleanup - npm run build passes - npm run openapi:check passes Co-authored-by: texture-coding-agent <coding-agent@texturehq.com>
1 parent 5b8532d commit c5e32e3

6 files changed

Lines changed: 40 additions & 13 deletions

drizzle/0008_resolve_utility_by_name_function.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-- Migration: Add fn_resolve_utility_by_name SQL function (M3)
2-
-- Spec: TextureHQ/mono#10142 (specs/relay/commongrid-nisc-matcher.md)
2+
-- Public server-to-server utility matching contract.
33
-- SECURITY INVOKER function with pinned search_path
44
-- Implements: override-lookup → exact normalized name → domain match → trigram fuzzy cascade
55
-- Returns: contract JSONB with {eia_id, confidence, match_source, candidates[top 5], resolver_version}

drizzle/0009_utility_cache_and_overrides_tables.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-- Migration: Add utility_resolver_cache + utility_name_manual_overrides tables (M4)
2-
-- Spec: TextureHQ/mono#10142 (specs/relay/commongrid-nisc-matcher.md)
2+
-- Public server-to-server utility matching contract.
33
-- Creates two admin tables to support M3 fn_resolve_utility_by_name:
44
-- 1. utility_name_manual_overrides: admin-curated mappings for ambiguous/new utilities
55
-- 2. utility_resolver_cache: read-only cache keyed by sha256(lower(name)|state|domain)

drizzle/0010_fix_crm_org_enrichment_view.sql

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
-- Migration: fix commongrid.v_crm_org_enrichment view + enrichment_schema sidecar (M2)
1+
-- Migration: fix commongrid.v_utility_enrichment view + enrichment_schema sidecar (M2)
22
--
33
-- Supersedes the earlier drizzle/0007_enrichment_schema_and_view.sql draft.
4-
-- That draft created public.enrichment_schema + public.v_crm_org_enrichment
4+
-- That draft created public.enrichment_schema + public.v_utility_enrichment
55
-- with non-existent source columns and would have failed to apply; we
66
-- defensively DROP anything it may have landed in environments where it was
77
-- partially run, then create the correct commongrid.* objects.
@@ -14,7 +14,7 @@ BEGIN;
1414
-- ---------------------------------------------------------------------------
1515
-- 0. Clean up partial drafts, if any.
1616
-- ---------------------------------------------------------------------------
17-
DROP VIEW IF EXISTS public.v_crm_org_enrichment;
17+
DROP VIEW IF EXISTS public.v_utility_enrichment;
1818
DROP TABLE IF EXISTS public.enrichment_schema;
1919
DROP VIEW IF EXISTS commongrid.v_utilities_enriched;
2020

@@ -43,7 +43,7 @@ GRANT USAGE ON SCHEMA commongrid TO internal_api_consumer;
4343
-- Source of truth is public.utilities joined to territory geometry via
4444
-- regions + territories. Active, non-deleted utilities with an EIA id only.
4545
-- ---------------------------------------------------------------------------
46-
CREATE OR REPLACE VIEW commongrid.v_crm_org_enrichment AS
46+
CREATE OR REPLACE VIEW commongrid.v_utility_enrichment AS
4747
SELECT
4848
u.eia_id AS eia_utility_id,
4949
u.slug AS commongrid_utility_slug,
@@ -89,15 +89,15 @@ WHERE u.deleted_at IS NULL
8989
AND u.status = 'ACTIVE'
9090
AND u.eia_id IS NOT NULL;
9191

92-
COMMENT ON VIEW commongrid.v_crm_org_enrichment IS
92+
COMMENT ON VIEW commongrid.v_utility_enrichment IS
9393
'Versioned utility enrichment view for internal API consumers. Shape is '
9494
'documented in commongrid.enrichment_schema. Additive-only: new columns '
9595
'may be appended with a minor-version bump; removals or renames require a '
9696
'major-version bump with advance notice.';
9797

9898
-- ---------------------------------------------------------------------------
9999
-- 4. Versioning sidecar. Singleton table that records the current shape and
100-
-- version of v_crm_org_enrichment so consumers can pin a known contract
100+
-- version of v_utility_enrichment so consumers can pin a known contract
101101
-- and fail loud on drift.
102102
-- ---------------------------------------------------------------------------
103103
CREATE TABLE IF NOT EXISTS commongrid.enrichment_schema (
@@ -111,7 +111,7 @@ CREATE TABLE IF NOT EXISTS commongrid.enrichment_schema (
111111

112112
COMMENT ON TABLE commongrid.enrichment_schema IS
113113
'Singleton. Records the current (major, minor) version and column manifest '
114-
'of commongrid.v_crm_org_enrichment so internal API consumers can detect drift.';
114+
'of commongrid.v_utility_enrichment so internal API consumers can detect drift.';
115115

116116
-- ---------------------------------------------------------------------------
117117
-- 5. Seed / refresh v1.0 manifest. Mirrors the columns and nullability of
@@ -141,7 +141,7 @@ VALUES (
141141
{"name":"territory_geojson_url","type":"text","nullable":true},
142142
{"name":"updated_at","type":"timestamptz","nullable":false}
143143
]'::jsonb,
144-
'v1.0 manifest for commongrid.v_crm_org_enrichment. Additive changes bump version_minor; breaking changes bump version_major.'
144+
'v1.0 manifest for commongrid.v_utility_enrichment. Additive changes bump version_minor; breaking changes bump version_major.'
145145
)
146146
ON CONFLICT (id) DO UPDATE
147147
SET version_major = EXCLUDED.version_major,
@@ -153,7 +153,7 @@ SET version_major = EXCLUDED.version_major,
153153
-- ---------------------------------------------------------------------------
154154
-- 6. Read-only grants on the two publicly-contracted objects only.
155155
-- ---------------------------------------------------------------------------
156-
GRANT SELECT ON commongrid.v_crm_org_enrichment TO internal_api_consumer;
156+
GRANT SELECT ON commongrid.v_utility_enrichment TO internal_api_consumer;
157157
GRANT SELECT ON commongrid.enrichment_schema TO internal_api_consumer;
158158

159159
COMMIT;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-- Drop obsolete utility-enrichment snapshot contract.
2+
--
3+
-- The public API should be the source of truth for utility facts. Consumers
4+
-- should call the REST endpoints directly with caching instead of mirroring
5+
-- CommonGrid data through a database view. This migration removes the
6+
-- short-lived enrichment snapshot objects while keeping the commongrid schema
7+
-- and internal_api_consumer role for generic server-to-server contract objects
8+
-- such as utility-name resolution and lifecycle signals.
9+
10+
BEGIN;
11+
12+
REVOKE ALL ON commongrid.v_crm_org_enrichment FROM internal_api_consumer;
13+
REVOKE ALL ON commongrid.enrichment_schema FROM internal_api_consumer;
14+
15+
DROP VIEW IF EXISTS commongrid.v_crm_org_enrichment;
16+
DROP VIEW IF EXISTS commongrid.v_utility_enrichment;
17+
DROP VIEW IF EXISTS commongrid.v_utilities_enriched;
18+
DROP TABLE IF EXISTS commongrid.enrichment_schema;
19+
20+
COMMIT;

drizzle/meta/_journal.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@
5050
"when": 1778250000000,
5151
"tag": "0007_commongrid_schema_and_internal_consumer_role",
5252
"breakpoints": true
53+
},
54+
{
55+
"idx": 7,
56+
"version": "7",
57+
"when": 1778252377890,
58+
"tag": "0011_drop_enrichment_snapshot_contract",
59+
"breakpoints": true
5360
}
5461
]
55-
}
62+
}

scripts/resolver-sanity.vitest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* M5: Resolver sanity fixture + CI test
3-
* Spec: TextureHQ/mono#10142 (specs/relay/commongrid-nisc-matcher.md)
3+
* Public server-to-server utility matching contract.
44
*
55
* Fixture: ~30 known co-op names mapped to expected eia_id
66
* Test assertion: >= 90% recall at confidence >= 0.90, 0 false positives at that threshold

0 commit comments

Comments
 (0)