Works with the AI Agents you already use
Schema Foreign Key Repair Planner AI
Inventory orphan references and plan non-destructive repairs. Built for database engineers and platform teams, with
$9.99
Schema Foreign Key Repair Planner AI
Example session with this skill installed
Analyze these orphan records in the 'orders' table (parent 'customers' is missing IDs 502, 588) for PostgreSQL 15. Plan a non-destructive repair and provide the evidence ledger.
- Read your context and instructions
- Compiled the schema foreign key
Illustrative example using synthetic inputs.
The analysis of the 'orders' table orphan references is complete. I have identified the necessary transitions and constructed a repair sequence based on PostgreSQL 15 semantics.
Evidence and Status Ledger
| Item ID | Current State | Source | Status | Owner | Next Checkpoint |
|---|---|---|---|---|---|
| ORD-502 | Orphaned (Parent 502 missing) | orders_dump_v1.sql | Planned | DB_Eng | Verify synthetic parent |
| ORD-588 | Orphaned (Parent 588 missing) | orders_dump_v1.sql | Planned | DB_Eng | Verify synthetic parent |
| FK_CUST_ID | Violated | schema_v2.sql | Review Required | Platform_Lead | Lock impact analysis |
Proposed Repair Sequence (Non-Destructive)
-- Step 1: Create a staging table for orphans to prevent data loss
CREATE TABLE orders_orphans_backup AS
SELECT * FROM orders WHERE customer_id IN (502, 588);
-- Step 2: Insert synthetic parent records to satisfy constraint temporarily
INSERT INTO customers (id, name, status)
VALUES (502, 'Placeholder_Orphan_502', 'inactive'),
(588, 'Placeholder_Orphan_588', 'inactive')
ON CONFLICT DO NOTHING;
-- Step 3: Validate constraint readiness (NOT VALID mode for Postgres)
ALTER TABLE orders ADD CONSTRAINT fk_orders_customer
FOREIGN KEY (customer_id) REFERENCES customers(id) NOT VALID;
-- Step 4: Final validation
ALTER TABLE orders VALIDATE CONSTRAINT fk_orders_customer;
Validation Summary
- Observed: Identified specific orphan IDs (502, 588) from provided source dump.
- Planned: Synthetic parent insertion and
NOT VALIDconstraint application. - Not Run: Actual execution on production; lock duration monitoring.
Next steps
- Review the synthetic parent record attributes to ensure they meet application-level validation.
- Execute the staging table backup in a staging environment to confirm row counts.
- Obtain Platform Lead approval for the
ALTER TABLElock window.
Connects securely to your tools. The creator never sees your data.
About this skill
Schema migrations and foreign key constraints are high-risk operations that often fail due to unexpected orphan records or locking issues. This skill provides a structured framework for database engineers to inventory broken references and design non-destructive repair plans. It replaces guesswork with an evidence-based ledger that links every repair action to specific source data.
What it does
- Inventory orphan references by identifying records that violate referential integrity without a valid parent.
- Generate repair plans using non-destructive sequences that prioritize data safety and uptime.
- Track evidence status through a ledger that connects every proposed change to observed source records.
- Analyze lock impacts by evaluating how schema changes will affect transaction and replication traces.
- Define rollback criteria for every material recommendation to ensure a safe exit path.
How it works
- Provide the affected schema items, current/target states, and a representative source record or query plan.
- The skill normalizes identifiers and establishes transaction semantics based on your database engine and version.
- It generates an evidence and status ledger, marking items as observed, derived, or conflicted.
- It performs a boundary check to identify missing evidence or potential edge cases in the migration sequence.
Frameworks & tools
Built for database platform teams working with SQL-based systems. It supports analysis for specific engine versions by referencing official documentation and SQL standard guidance when public URLs are provided.
Why this beats prompting it yourself
Generic prompts often suggest destructive DELETE or TRUNCATE operations that ignore replication lag or application logic. This skill enforces a strict evidence-based methodology that requires transaction impact analysis and explicit rollback conditions for every proposed change.
Use cases
- Planning the introduction of a new foreign key constraint on a legacy table with dirty data.
- Identifying and documenting orphan records across microservice database boundaries.
- Preparing a reviewable migration plan for a high-traffic production schema change.
- Creating reproducible SQL fixtures for testing schema repairs in disposable environments.
Known limitations
Does not execute mutating SQL or perform live database writes. It cannot verify query timings or backup integrity unless that data is explicitly supplied in the context.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before buying a skill.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Money-back guarantee
Doesn't do what its page promises? You get your money back.
Trust & safety
Security scan
Security scan passed 7 days ago
Permissions
What's inside
Frequently Asked Questions
Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse All Claude Skills.