CtrlK
BlogDocsLog inGet started
Tessl Logo
PluginPublic

g14wxz/commerce-database-architect

Database architecture skills, docs, and rules for high-demand multi-tenant commerce platforms (PostgreSQL source of truth, Neo4j as derived GraphRAG projection, transactional outbox, RLS-based tenant isolation). Includes live schema introspection workflow via explicit Supabase MCP/read-only schema sources.

Quality

96%

Does it follow best practices?

Run evals on this skill

Adds up to 20 points to the overall score

View guide
SecuritybySnyk

Passed

No findings from the security scan

Overview
Quality
Evals
Security
Files

SKILL.mdskills/postgres-schema-introspection/

name:
postgres-schema-introspection
description:
Use when the agent needs to inspect the actual current state of a PostgreSQL database before answering a schema question — including before adding columns, before reviewing diagrams, before proposing migrations, or whenever the snapshot in .specify/memory/current-schema-state.md is stale. Connects via the configured Supabase MCP/read-only schema source, queries catalog metadata through list_tables or SELECT-only catalog SQL, and refreshes the snapshot file. Triggered by any "let me check what's already there", "what columns does X have", "what indexes exist on Y", "what does the schema look like", or by the snapshot being older than 24 hours.
license:
MIT

Postgres Schema Introspection

You are inspecting a live PostgreSQL database via Supabase MCP or another read-only schema MCP server.

When to use this skill

  • Snapshot is stale (> 24h) or user asks to "check the database"
  • User asks what's in the schema for a given table or wants a Mermaid diagram reviewed against actual state
  • Suspected drift between code and database, or after a migration was mentioned
  • User wants performance diagnostics from pg_stat_statements

Pre-flight

Confirm the expected schema MCP tool is loaded. For this repo, /speckit.dbsync local|dev|prod expects mcp__local-storestorm-tenant__*, mcp__dev-storestorm-tenant__*, or mcp__prod-storestorm-tenant__* respectively. For non-Supabase targets, a restricted/read-only Postgres MCP may be used. If none, point the user at mcp-configuration.md. Then run one combined check:

SELECT current_user,
       current_setting('default_transaction_read_only') AS read_only,
       pg_is_in_recovery()                              AS on_replica;

Halt and report a § XV violation if the selected MCP source is not read-only, if a hosted Supabase MCP URL omits read_only=true, or if the project URL/ref does not match the requested dbsync source. For direct production Postgres connections, prefer a replica and require SELECT-only posture.

What to introspect

Full per-table query set lives in introspection-queries.md (columns, constraints, indexes, RLS, triggers, FKs in/out, size, JSONB sampling, pg_stat_statements). Two most-used inline:

-- Columns + nullability + defaults
SELECT column_name, data_type, is_nullable, column_default
FROM information_schema.columns
WHERE table_schema = $1 AND table_name = $2
ORDER BY ordinal_position;

-- Indexes with predicates
SELECT indexname, indexdef
FROM pg_indexes
WHERE schemaname = $1 AND tablename = $2;

For multi-table batches across the whole schema, use the project's /speckit.dbsync workflow — never one query per table.

Project-specific guardrails

  • No tenant PII into the LLM context — project columns, never SELECT * (§ XV)
  • No unbounded query on tables > 10 k rows — TABLESAMPLE SYSTEM (1) or LIMIT n
  • No side-effect functions (pg_terminate_backend, dblink_*, pg_read_file) — read-only invariant
  • Halt on privilege escalation — report violation, do not introspect (§ XV)
  • Every recommended index cites a query pattern or constraint (§ XI)

After introspection

Write the results into .specify/memory/current-schema-state.md between the <!-- BEGIN AUTO-GENERATED --> and <!-- END AUTO-GENERATED --> markers. Never touch the hand-edited sections. Snapshot shape:

| field | value |
|-------|-------|
| Last sync | 2026-05-04T10:31:08Z |
| Migration head | 20260503_140012_add_pricing_rules_target_price |
| Snapshot version | 42 |

<!-- BEGIN AUTO-GENERATED -->
### catalog_products  (module: catalog, ~5,012,418 rows)
- Columns: id (bigint PK), tenant_id (bigint NOT NULL), sku (text), …
- Constraints: PK(id), UQ(tenant_id, sku), FK(brand_id → catalog_brands.id)
- Indexes: idx_catalog_products_tenant_sku (tenant_id, sku) — UQ
- RLS: tenant_isolation USING (tenant_id = current_setting('app.tenant_id')::bigint)
<!-- END AUTO-GENERATED -->

If new tables appeared since the last sync, add them to Open Schema Questions asking the user to assign module ownership. Diff against the previous version with git diff .specify/memory/current-schema-state.md and report drift.

Examples

  • "Add a wholesale price to products." — inspect catalog_products columns + sample metadata JSONB keys. Surface duplicates (existing price, cost, compare_at_price) and informal JSONB usage. Hand off to schema-evolution-workflow.

  • "Why is product listing slow?" — pull the slow-query block from introspection-queries.md, then surface missing tenant-first composite indexes, sequential scans, and JSONB GIN opportunities. Every recommended index cites a query pattern (§ XI) and uses CREATE INDEX CONCURRENTLY.

skills

tile.json