Skip to content

The Deska blog

Migrations Written by Agent, Reviewed by You

Learn how migrations written by agent workflows improve database reliability and how tools like Deska facilitate human review to prevent data loss.

10 min read

Managing database schema changes remains one of the most high risk activities in software engineering. While application code can often be rolled back with minimal side effects, a failed migration can lead to data corruption or prolonged downtime. The rise of LLMs has introduced a new paradigm where migrations written by agent workflows allow developers to focus on architectural intent rather than syntax. However, the critical piece of this transition is ensuring that the human developer remains the final authority through a rigorous review process.

The Evolution of Schema Management

Traditionally, developers wrote SQL migrations by hand or relied on Object Relational Mapping (ORM) tools to generate them. Manual writing is precise but slow and prone to typos. ORM auto generation is convenient but often produces inefficient queries or misses edge cases like index creation on large tables.

Using an agent to draft these files bridges the gap. An agent can ingest the current schema and the desired state, then produce the necessary DDL (Data Definition Language) statements. The value is not just in speed, but in the agent's ability to cross reference documentation for specific database engines like PostgreSQL or MySQL to ensure syntax compatibility.

Risks of Fully Automated Migrations

Despite the efficiency, trusting an agent to execute changes directly on a production database is dangerous. There are several categories of risk that require human intervention.

  • Destructive Operations: An agent might suggest dropping a column to rename it, which results in total data loss for that field. A human knows to use a multi step approach involving adding a new column, migrating data, and then dropping the old one.
  • Locking Issues: Adding a NOT NULL constraint to a table with millions of rows can lock the table for minutes. Humans understand the operational context that an agent might ignore.
  • Performance Regressions: A new index might seem beneficial in isolation but could slow down write operations significantly in a high throughput system.

To mitigate these, the workflow must transition from "Agent Defined" to "Agent Proposed, Human Verified."

Integrating Deska into the Migration Workflow

Deska provides a specialized environment for this exact collaboration. Because it is a free desktop app available for Mac, Windows and Linux, it serves as a neutral ground where AI agents and developers coexist. The infinite canvas workspace allows you to arrange the components of a migration task visually.

When working on migrations, you can place a code editor panel next to multiple terminal panels. You might run an agent like Claude Code or Codex CLI in one terminal to generate the SQL file. Simultaneously, you can have a separate terminal open to run a local instance of your database for testing. This side by side arrangement in panels ensures you never lose sight of the generated code while checking the logs of the migration runner.

Deska operates as a local-first tool. This is vital for database work because your schema definitions and sensitive connection strings stay on your machine. The code and files do not leave your environment unless you explicitly push them to a remote repository.

Reviewing Agent Output with Ask Deska

The Ask Deska feature acts as a workspace coordinator. You can use voice or chat to ask the assistant to open specific terminals or find the migration file the agent just created. Once the agent has drafted a migration, your review process should follow a checklist:

  1. Verification of Intent: Does the SQL actually reflect the business requirement?
  2. Safety Check: Are there any DROP or TRUNCATE commands that were unexpected?
  3. Execution Plan: Use the EXPLAIN command in a database panel to see how the migration affects performance.
  4. Rollback Logic: Ensure the agent also wrote a corresponding "down" migration to revert changes if needed.

If you are away from your desk, the mobile app allows you to monitor long running migration scripts. The secure relay allows you to check the status of your workspaces from your phone without exposing ports, ensuring you can stop a failing migration even if you are not at your computer.

Comparing Agentic Workflows and Traditional Tools

Traditional migration tools differ in approach when compared to agentic workflows. Tools like Flyway or Liquibase focus on versioning and execution order. They are excellent at maintaining the history of a database. Agentic workflows, however, focus on the creation phase.

FeatureManual/ORMAgentic Workflow (Deska)
Creation SpeedSlow to ModerateVery Fast
Syntactic AccuracyHigh (Manual) / Mixed (ORM)High
Safety OversightHuman DependentHuman Reviewed
Context AwarenessHighVariable (Requires Prompting)

Using agents within Deska does not replace these versioning tools. Instead, the agent writes the migration files that Flyway or Liquibase will eventually execute. The infinite canvas makes it easy to keep the documentation, the migration script, and the database logs visible at the same time.

Security and Privacy in AI Driven Migrations

A primary concern when using AI for database tasks is data privacy. Because Deska is local-first, the interaction with the workspace is private. When using the coding agents, you have the choice of using your own API keys via the BYOK model or using managed inference.

This flexibility is crucial for enterprise environments where schema information might be sensitive. By keeping the files local, you ensure that the agent only sees what is necessary to perform the task. You can read more about how your data is handled in the privacy section.

FAQ

How to use migrations written by agent safely?

The safest way is to use a staging environment that mirrors production data. Let the agent generate the SQL in a Deska panel, then run the migration against the staging clone. Only after the human developer verifies the data integrity and performance should the script be committed to the main branch.

Can Claude Code generate SQL migrations?

Yes, Claude Code can be run as a panel within Deska. It can analyze your existing DDL files and generate new migration scripts based on your instructions. It is particularly good at identifying constraints and relationships between tables, though you should always review the output for potential table locks.

What are the benefits of a local first workspace for SQL?

A local first workspace ensures that your database credentials and schema structure are not stored on a third party cloud. Since Deska runs on your machine, the agent threads interact with your local file system, allowing for a faster and more secure development cycle compared to web based IDEs.

Get Started with Deska

Automating the tedious parts of database management allows you to spend more time on high level system design. By using agents to draft your SQL, you reduce the boilerplate work while maintaining full control over the execution. You can explore the full range of features and download the app for your preferred platform today.