CORE-WP-0005-T02 done: Inter-Hub exporter + staging import (28 records, idempotent)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-02 19:21:13 +02:00
parent eec76cbb9b
commit 4dc4ab4c8b
3 changed files with 59 additions and 1 deletions

View File

@@ -0,0 +1,27 @@
# Inter-Hub → Core Hub migration export
`inter_hub_export.sql` is a read-only query against the legacy Inter-Hub
Postgres database (`interhub` on net-kingdom-pg) that emits a
`core-hub.migration.v1` bundle covering hubs, hubCapabilityManifests,
apiConsumers, apiKeys (prefix + hash only, no plaintext), widgets, and
interactionEvents. Field names are aliased from Inter-Hub's snake_case columns
to the bundle's camelCase contract.
## Run
```bash
kubectl exec -i -n databases net-kingdom-pg-1 -- \
psql -U postgres -d interhub -tA < scripts/migration/inter_hub_export.sql \
> interhub-bundle.json
# validate (no DB needed)
PYTHONPATH=src uv run python scripts/core_hub_cli.py migration validate interhub-bundle.json
# import into a target (CORE_HUB_DATABASE_URL); run in-cluster for staging
python scripts/core_hub_cli.py migration import --dry-run interhub-bundle.json
python scripts/core_hub_cli.py migration import interhub-bundle.json
```
The importer is idempotent (upsert by id): re-running updates in place, never
duplicates. `api_keys` carry only `keyPrefix` + `keyHash`, so no secret material
transits the bundle.

View File

@@ -0,0 +1,13 @@
SELECT json_build_object(
'schemaVersion','core-hub.migration.v1',
'source','inter-hub-production',
'exportedAt', now(),
'records', json_build_object(
'hubs', COALESCE((SELECT json_agg(json_build_object('id',id,'slug',slug,'name',name,'domain',domain,'hubKind',hub_kind,'hubFamily',hub_family,'vsmFunction',vsm_function,'vsmSystem',vsm_system,'status','active')) FROM hubs), '[]'::json),
'hubCapabilityManifests', COALESCE((SELECT json_agg(json_build_object('id',id,'hubId',hub_id,'manifestVersion',manifest_version,'declaredWidgetTypes',declared_widget_types,'declaredEventTypes',declared_event_types,'declaredAnnotationCategories',declared_annotation_categories,'declaredPolicyScopes',declared_policy_scopes,'status',status,'capabilityDescription',capability_description,'contact',contact,'activatedAt',activated_at)) FROM hub_capability_manifests), '[]'::json),
'apiConsumers', COALESCE((SELECT json_agg(json_build_object('id',id,'name',name,'description',description,'hubCapabilityManifestId',hub_capability_manifest_id,'rateLimitPerMinute',rate_limit_per_minute,'quotaPerDay',quota_per_day,'isActive',is_active)) FROM api_consumers), '[]'::json),
'apiKeys', COALESCE((SELECT json_agg(json_build_object('id',id,'apiConsumerId',api_consumer_id,'keyPrefix',key_prefix,'keyHash',key_hash,'scopes',scopes,'tokenType',token_type,'expiresAt',expires_at,'revokedAt',revoked_at)) FROM api_keys), '[]'::json),
'widgets', COALESCE((SELECT json_agg(json_build_object('id',id,'hubId',hub_id,'name',name,'widgetType',widget_type,'capabilityRef',capability_ref,'viewContext',view_context,'policyScope',policy_scope,'status',status,'version',version,'isArchived',is_archived)) FROM widgets), '[]'::json),
'interactionEvents', COALESCE((SELECT json_agg(json_build_object('id',id,'widgetId',widget_id,'eventType',event_type,'viewContext',view_context_ref,'actorId',actor_id,'actorType',actor_type,'metadata',metadata,'occurredAt',occurred_at)) FROM interaction_events), '[]'::json)
)
);