# Postgres Migration Dependency Resolver MCP for AI Agents MCP

> Postgres Migration Dependency Resolver prevents broken database deployments by calculating the exact order SQL migrations need to run. It finds circular dependencies and checks if all required migration IDs exist before you push to production.

## Overview
- **Category:** automation
- **Price:** Free
- **Endpoint:** https://edge.vinkius.com/vk_preview_Of07hhysJMWasAT5dA3EQF46V3k8VeJyikCh4Sf9/mcp
- **Tags:** postgres, migrations, sql, dependency-resolver, deployment, graph-theory

## Description

Managing SQL migrations is a headache when dependencies start overlapping. One wrong move and your deployment fails halfway through, leaving the database in a broken state. This MCP handles the heavy lifting of mapping out exactly which migrations must run first. It looks at your migration IDs and builds a clear path for execution, making sure nothing breaks because a prerequisite was missed. You can use it to see how a single change might ripple through your entire schema or to catch ghost dependencies that don't actually exist in your files. By connecting this to your AI client via Vinkius, you get an automated way to audit your deployment plan without manually tracing every SQL file. It's about moving from "I hope this works" to knowing exactly what the execution sequence looks like before a single line of code hits your production environment.

## Tools

### resolve_migration_order
Calculates the exact, deterministic sequence for executing your SQL migrations. Use this to get a safe deployment path.

### validate_dependency_integrity
Scans your migration list to ensure every referenced dependency actually exists. It catches missing links before they cause deployment failures.

### analyze_downstream_impact
Shows how changing one migration affects all subsequent dependent scripts. It helps you understand the blast radius of your database changes.

## Prompt Examples

**Prompt:** 
```
Can you check if my migrations are safe to run?
```

**Response:** 
```
I have analyzed your migration list. The sequence is valid and contains no circular dependencies.

**Execution Order:**
1. `init_users`
2. `add_email_to_users`
3. `create_profiles`
4. `link_profiles_to_users`
```

**Prompt:** 
```
What happens if I change the 'users' migration?
```

**Response:** 
```
Changing the `users` migration will impact **3** downstream migrations:

* `add_email_to_users` (Direct dependency)
* `create_profiles` (Indirect dependency)
* `link_profiles_to_users` (Indirect dependency)
```

**Prompt:** 
```
Are there any broken links in my dependency list?
```

**Response:** 
```
**Integrity Check Failed.**

I found a missing dependency:
* **Migration ID:** `v2_update_schema` requires `v1_base_setup`, but `v1_base_setup` was not found in your provided list.
```

## Capabilities

### Calculate migration sequences
Determines the precise order for running SQL scripts.

### Detect circular dependencies
Finds loops in your migration logic that would block deployments.

### Audit dependency existence
Checks if every required migration ID is actually present.

### Predict schema changes
Shows how modifying one migration affects others downstream.

## Use Cases

### Broken deployment recovery
A developer realizes a new migration depends on a non-existent ID. They ask their agent to check the integrity, and it flags the missing link immediately.

### undefined
An engineer needs to update a core table. They use the impact analysis tool to see which other migrations will be affected by the change.

### Automating migration sequencing
A DevOps lead has hundreds of SQL files. The agent generates a perfect, sorted list for the deployment script automatically.

## Benefits

- Eliminate deployment failures by catching circular references before they reach production.
- Verify all migration dependencies exist to prevent broken links.
- Understand the full impact of schema changes on your database.
- Get a guaranteed, error-free execution order for your database changes.
- Stop ghost dependencies from breaking your CI/CD pipelines.

## How It Works

The bottom line is you get a guaranteed, error-free execution order for your database changes.

1. Provide your list of migrations and their dependencies to the MCP.
2. The algorithm processes the graph to find a valid execution path or identifies errors.
3. You receive a deterministic, sorted list of migration IDs ready for deployment.

## Frequently Asked Questions

**How does Postgres Migration Dependency Resolver prevent deployment errors?**
It calculates a deterministic execution order and identifies circular references that would otherwise cause a deployment to fail halfway through.

**Can I use Postgres Migration Dependency Resolver to find missing migrations?**
Yes. It scans your migration list to ensure every referenced dependency actually exists in your files, preventing 'ghost dependency' errors.

**Will Postgres Migration Dependency Resolver work with any SQL migration tool?**
It works with any system where you can provide a list of migration IDs and their respective dependencies, making it highly flexible for PostgreSQL workflows.

**How do I know if a change will break my database using Postgres Migration Dependency Resolver?**
You can ask your agent to analyze the downstream impact. It will list every migration that relies on the one you are changing.

**Can Postgres Migration Dependency Resolver detect circular dependencies?**
Yes, it specifically uses graph theory algorithms to find loops where migrations depend on each other in a way that prevents execution.

**How does the tool detect circular dependencies?**
The `resolve_migration_order` tool uses Kahn's algorithm to track in-degrees. If migrations remain with non-zero in-degrees after the process, they are identified as part of a cycle.

**What happens if I reference a migration ID that doesn't exist?**
You should use the `validate_dependency_integrity` tool. It will return `isValid: false` and provide a list of all missing migration IDs found in your requirements.

**Can I see which migrations are affected if a specific migration fails?**
Yes, the `analyze_downstream_impact` tool performs a reverse lookup to find all migrations that transitively depend on your target ID.