Skip to content

Runtime metadata table (_pgconsole)#2

Merged
NFUChen merged 27 commits into
mainfrom
feat/dynamic-schema-migration
May 19, 2026
Merged

Runtime metadata table (_pgconsole)#2
NFUChen merged 27 commits into
mainfrom
feat/dynamic-schema-migration

Conversation

@NFUChen

@NFUChen NFUChen commented May 19, 2026

Copy link
Copy Markdown
Owner

Runtime metadata table (_pgconsole)

Summary

Replace the static schema_source config in pgconsole.toml with a runtime _pgconsole metadata table stored directly in the target PostgreSQL database. This enables runtime CRUD of migration settings without config changes or restarts.

Motivation

The [connections.schema_source] block in pgconsole.toml was static — changing it required editing the config file and restarting pgconsole. Since pgconsole already connects to the target database, storing this metadata in the DB itself is simpler and enables runtime management.

Changes

New: MetadataService (general-purpose KV store)

  • proto/metadata.proto — New MetadataService with 5 RPCs: InitMetadataTable, GetMetadata, SetMetadata, DeleteMetadata, ListMetadata
  • server/services/metadata-service.ts — Service implementation. Creates a _pgconsole table (key TEXT PK, value JSONB, updated_at TIMESTAMPTZ). Permission gating: admin for init, read for get/list, write for set/delete
  • server/connect.ts — Registered MetadataService route with logging interceptor
  • server/index.ts — Added /metadata.v1. to SPA fallback skip list

Changed: Migration service reads from DB

  • server/services/migration-service.tsplanMigration and getSchemaSourceStatus now read schema_source from the _pgconsole table instead of config. Added getSchemaSource() helper that queries the DB
  • server/lib/config.ts — Removed SchemaSourceConfig interface and schema_source from ConnectionConfig. Removed config parsing logic for schema_source
  • server/lib/pgschema.ts — Added repoDir parameter to runPgSchemaPlan and runPgSchemaApply. Writes .pgschemaignore to exclude _pgconsole table from schema plans

Frontend: Init + configure flow in Migration panel

  • src/lib/connect-client.ts — Added metadataClient
  • src/hooks/useMigration.ts — Added useMetadataTableStatus, useInitMetadataTable, useSetSchemaSource hooks
  • src/components/sql-editor/schema/MigrationPanel.tsx — Replaced static "not configured" message with interactive SchemaSourceSetup component:
    • Detects if _pgconsole table exists
    • Shows confirmation dialog before creating the table (requires admin permission)
    • Provides form for repo URL, branch, schema file path, and target schema
    • Saves config via SetMetadata and reloads into the migration plan flow
  • vite.config.ts — Added /metadata.v1.MetadataService proxy entry

Cleanup

  • docker-compose.yml — Removed schema_source block (contained leaked credentials)
  • pgconsole.example.toml — Removed schema_source example
  • tests/config-schema-source.test.ts — Removed (no longer relevant)
  • Dockerfile — Fixed pgschema binary extraction to handle versioned filenames; removed hardcoded TARGETARCH=amd64 default so BuildKit auto-detects platform

Schema

CREATE TABLE IF NOT EXISTS _pgconsole (
  key         TEXT NOT NULL PRIMARY KEY,
  value       JSONB NOT NULL,
  updated_at  TIMESTAMPTZ NOT NULL DEFAULT now()
);

Table is created explicitly by the user via InitMetadataTable RPC (opt-in, never auto-created).

William-W-Chen and others added 27 commits May 17, 2026 13:53
Covers pgschema CLI integration, git-based schema source config,
MigrationService RPC design, and frontend Schema Diff View.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Define PlanMigration, ApplyMigration (streaming), and
GetSchemaSourceStatus RPCs for the schema migration feature.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
PlanMigration syncs git, runs pgschema plan, stores result.
ApplyMigration streams progress and executes pgschema apply.
GetSchemaSourceStatus returns schema_source config for a connection.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Shows schema diffs from git source, supports DDL preview,
and gated apply with confirmation dialog (requires ddl permission).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Show migration panel when no object is selected and the
connection has a schema_source configured.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@NFUChen NFUChen merged commit a36d319 into main May 19, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants