AI & ToolsApr 1, 20267 min read

Using Cursor + ER Flow: The Ultimate AI Database Design Workflow

Cursor has fundamentally changed how developers write code. But there's been a blind spot: your database schema. ER Flow's MCP Server eliminates this blind spot β€” giving your AI assistant full read and write access to your database schema.

Cursor has fundamentally changed how developers write code. You describe what you need, and Cursor writes it β€” with full context of your codebase. But there's been a blind spot: your database schema. Cursor can see your code files, but it can't see your database structure. It generates migrations for tables that don't exist, creates queries against columns with wrong names, and suggests relationships that conflict with your actual schema.

ER Flow's MCP Server eliminates this blind spot. By connecting Cursor to your ER Flow workspace, your AI assistant gains full read and write access to your database schema. Here's how to set up the workflow and get the most out of it.

Setting Up the Connection

The setup takes about 5 minutes. In your ER Flow workspace, go to settings and find the MCP Server configuration. You'll see a connection URL and configuration snippet. In Cursor, open settings and navigate to the MCP section. Add ER Flow as a new MCP server using the provided configuration.

Once connected, Cursor discovers 25+ tools it can use to interact with your schema: reading tables and columns, creating new entities, establishing relationships, modifying structures, and triggering migration generation. You don't need to learn these tools β€” Cursor uses them automatically based on your natural language instructions.

The Workflow in Practice

Starting a new project

Instead of creating tables one by one in either the diagram or migration files, describe your entire domain to Cursor: "I'm building a SaaS project management tool. I need organizations with members and roles, projects within organizations, tasks with assignees and priorities, time tracking on tasks, and a commenting system."

Cursor reads your current (empty) ER Flow workspace, understands the domain, and creates the entire schema: organizations, users, organization_members (junction table with roles), projects, tasks with proper foreign keys, time_entries, comments with threading support. All tables appear on your ER Flow canvas in real-time, with relationships drawn and data types set appropriately for your chosen database.

What would take 30-60 minutes of manual design happens in under 2 minutes.

Adding features to existing schemas

This is where the workflow truly shines. You have 25 tables in your schema, and you need to add a notification system. Without MCP, Cursor would guess at your existing table names and structures. With MCP, it reads your actual schema first.

Tell Cursor: "Add a notification system. Users should get notifications for task assignments, comment mentions, and due date reminders. Include notification preferences so users can control what they receive."

Cursor examines your existing users, tasks, and comments tables. It creates a notifications table with foreign keys to your existing tables, a notification_preferences table linked to users, and an enum for notification types that references the actual events in your system. Because it can see that your tasks table has an assignee_id column, it knows the exact relationship to use for task assignment notifications.

Reviewing and refining

After the AI creates tables, review them on the ER Flow canvas. You might notice that the AI created a text column where you'd prefer an enum, or that a relationship should cascade on delete instead of restricting. Make these adjustments visually in ER Flow β€” the mix of AI speed and human judgment gives you the best of both worlds.

You can also ask Cursor to review: "Look at the notification system you just created. Are there any missing indexes for common query patterns?" Cursor reads the schema through MCP and suggests adding indexes on notifications.user_id (fetching a user's notifications), notifications.created_at (sorting by recency), and a composite index on notification_preferences(user_id, notification_type) for preference lookups.

Generating code that matches your schema

Once your schema is updated, Cursor can generate application code that exactly matches your database structure. Ask it to write Eloquent models, API controllers, or TypeScript types β€” and because it can read your actual schema through MCP, the generated code uses the correct table names, column names, data types, and relationships.

No more fixing AI-generated code that references a post_author_id column when your schema calls it user_id.

Advanced Patterns

Schema-aware code generation

"Generate TypeScript interfaces for all tables in my schema" β€” Cursor reads every table through MCP and produces type-safe interfaces that match your database exactly. Column types map to TypeScript types (integer β†’ number, varchar β†’ string, jsonb β†’ Record<string, unknown>), and relationships are represented as optional nested types.

Cross-cutting schema changes

"Add created_by and updated_by columns to all tables that don't already have them, referencing the users table" β€” Cursor reads all tables, identifies which ones are missing these columns, and adds them with proper foreign keys. A task that would require manually editing 15+ migration files happens in one prompt.

Schema refactoring

"The profiles table should be merged into users. Move all profile columns into users and update the relationships" β€” Cursor reads both tables, understands the columns and existing foreign keys, merges the structure, and updates references. You can then generate a migration that handles the data move.

Documentation from schema

"Generate a markdown document describing my entire database schema, organized by domain (auth, projects, billing). Include all relationships and explain the purpose of each table" β€” Cursor reads the full schema through MCP and produces comprehensive documentation that stays accurate because it's generated from the actual structure.

Tips for Getting the Most Out of This Workflow

Be specific about business rules. "Add a payments table" is okay, but "Add a payments table for Stripe integration β€” orders can have multiple payment attempts, and we need to track the Stripe payment intent ID, status transitions, and webhook events" gives the AI much better context for the schema design.

Use checkpoints before major AI changes. Create an ER Flow checkpoint before asking Cursor to make significant schema modifications. If the AI's changes aren't what you wanted, you can revert to the checkpoint and try a different prompt.

Iterate in small steps for complex schemas. Instead of describing 30 tables in one prompt, build your schema in domain-level chunks: "First, let's create the authentication and user management tables." Then: "Now add the project and task management tables." This gives you review points between each chunk.

Ask the AI to explain its decisions. After creating a schema, ask "Why did you choose this structure for the notifications system? What alternatives did you consider?" Cursor will explain its reasoning, and you might discover a better approach through the discussion.

Combine with ER Flow's visual tools. Use AI for the initial structure and bulk changes. Use ER Flow's visual canvas for fine-tuning: rearranging table positions, adjusting color groups, and tweaking individual columns. The hybrid workflow is faster than either approach alone.

Why This Matters for Teams

For solo developers, this workflow is a productivity boost. For teams, it's transformative. Instead of one developer designing the schema and explaining it to the team through migration files, the entire schema is visible on the ER Flow canvas. AI changes are visible to everyone in real-time through ER Flow's collaboration features.

Schema design conversations shift from "read this migration file and imagine the table" to "look at the canvas β€” here's what the AI created, and here's what I'd adjust." Pull request reviews can reference specific visual diffs between ER Flow checkpoints rather than raw SQL.

The combination of AI speed, visual design, and real-time collaboration creates a database design workflow that's faster, more collaborative, and more reliable than any previous approach.