Describe Schema Changes in English and Let Claude Write the Migration
Database migrations are tedious to write by hand — especially when they involve multiple tables, foreign keys, and indexes. Describe what you want in English and Claude handles the schema.
"Add a tagging system — posts should be able to have multiple tags, and tags should be reusable across posts"
Claude reads your existing models and schema, then generates everything needed — migration files, model updates, relationships, and indexes:
// Claude creates the migration
Schema::create('tags', function (Blueprint $table) {
$table->id();
$table->string('name')->unique();
$table->string('slug')->unique();
$table->timestamps();
});
Schema::create('post_tag', function (Blueprint $table) {
$table->foreignId('post_id')->constrained()->cascadeOnDelete();
$table->foreignId('tag_id')->constrained()->cascadeOnDelete();
$table->primary(['post_id', 'tag_id']);
});
This works for any complexity:
# Simple column additions
"Add a phone number and date of birth to the users table"
# Relationships
"Users should be able to belong to multiple teams, with a role in each team"
# Complex changes
"Add a polymorphic comments system — users can comment on posts, products, and orders"
# Modifications
"Change the price column from integer cents to a decimal with 2 decimal places,
and add a currency column that defaults to USD"
# With constraints
"Add a unique constraint on email per organization — different orgs can have
the same email but not within the same org"
Claude also handles the tricky parts:
- Rollback safety — writes proper
down()methods so migrations are reversible - Data preservation — when modifying existing columns, handles the transformation without losing data
- Index strategy — adds indexes for foreign keys and commonly queried columns
- Framework conventions — follows your ORM's naming conventions for tables, columns, and pivots
After writing the migration, ask Claude to update the models too:
"Now update the Post and Tag models with the relationships and any scopes"
Schema changes start as ideas in your head — describe them in words, let Claude write the SQL.
via Claude Code
Log in to leave a comment.
Set up Claude Code as an automated reviewer in your CI pipeline — on every pull request, it reads the diff, checks for bugs, security issues, missing tests, and convention violations, then posts its findings as a PR comment. Your human reviewers get a head start because the obvious issues are already flagged before they look.
Before deploying, tell Claude to read your project — migrations, environment variables, queue workers, scheduled tasks, caching, third-party integrations — and generate a deployment checklist that's specific to your app. Not a generic "did you run migrations?" list, but one that knows YOUR infrastructure and catches the things YOUR deploy can break.
Instead of writing a README from memory or copying a template, tell Claude to read your project and generate one that's actually accurate — real setup instructions from your config, real architecture from your directory structure, real API examples from your routes, and real prerequisites from your dependency files.