Claude-skill-registry laravel-migrations

Laravel 12 database migrations - Schema Builder, columns, indexes, foreign keys, seeders. Use when designing database schema or managing migrations.

install
source · Clone the upstream repo
git clone https://github.com/majiayu000/claude-skill-registry
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/majiayu000/claude-skill-registry "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/data/laravel-migrations" ~/.claude/skills/majiayu000-claude-skill-registry-laravel-migrations && rm -rf "$T"
manifest: skills/data/laravel-migrations/SKILL.md
source content

Laravel Migrations

Agent Workflow (MANDATORY)

Before ANY implementation, launch in parallel:

  1. fuse-ai-pilot:explore-codebase - Check existing migrations
  2. fuse-ai-pilot:research-expert - Verify Laravel 12 patterns via Context7
  3. mcp__context7__query-docs - Check specific Schema Builder features

After implementation, run fuse-ai-pilot:sniper for validation.


Overview

FeatureDescription
Schema BuilderCreate, modify, drop tables
Columns50+ column types with modifiers
IndexesPrimary, unique, fulltext, spatial
Foreign KeysConstraints with cascade options
SeedersPopulate tables with data

Critical Rules

  1. Always define down() - Reversible migrations
  2. Use foreignId()->constrained() - Not raw unsignedBigInteger
  3. Add indexes on foreign keys - Performance critical
  4. Test rollback before deploy - Validate down() works
  5. Never modify deployed migrations - Create new ones

Decision Guide

Migration Type

Need schema change?
├── New table → make:migration create_X_table
├── Add column → make:migration add_X_to_Y_table
├── Modify column → make:migration modify_X_in_Y_table
├── Add index → make:migration add_index_to_Y_table
└── Seed data → make:seeder XSeeder

Column Type Selection

Use CaseTypeExample
Primary Key
id()
Auto-increment BIGINT
Foreign Key
foreignId()->constrained()
References parent
UUID Primary
uuid()->primary()
UUIDs
Boolean
boolean()
is_active
Enum
enum('status', [...])
order_status
JSON
json()
preferences
Money
decimal('price', 10, 2)
99999999.99
Timestamps
timestamps()
created_at, updated_at
Soft Delete
softDeletes()
deleted_at

Foreign Key Cascade

ScenarioonDeleteUse Case
Strict integrity
restrictOnDelete()
Financial records
Auto-cleanup
cascadeOnDelete()
Post → Comments
Preserve with null
nullOnDelete()
Optional relations
No action
noActionOnDelete()
Audit logs

Reference Guide

Core Concepts

TopicReferenceWhen to Consult
Schemaschema.mdTable operations
Columnscolumns.mdColumn types
Indexesindexes.mdPerformance indexes
Foreign Keysforeign-keys.mdConstraints
Commandscommands.mdArtisan commands
Seedingseeding.mdPopulate data

Advanced Topics

TopicReferenceWhen to Consult
Testingtesting.mdTest migrations
Productionproduction.mdDeploy safely
Troubleshootingtroubleshooting.mdFix errors

Templates

TemplateWhen to Use
CreateTableMigration.php.mdNew table
ModifyTableMigration.php.mdAlter table
PivotTableMigration.php.mdMany-to-many
Seeder.php.mdSeed patterns
MigrationTest.php.mdTest migrations

Quick Reference

Create Table

Schema::create('posts', function (Blueprint $table) {
    $table->id();
    $table->foreignId('user_id')->constrained()->cascadeOnDelete();
    $table->string('title');
    $table->text('content');
    $table->enum('status', ['draft', 'published'])->default('draft');
    $table->timestamps();
    $table->softDeletes();

    $table->index(['user_id', 'status']);
});

Modify Table

Schema::table('posts', function (Blueprint $table) {
    $table->string('slug')->after('title')->unique();
    $table->boolean('featured')->default(false);
});

Commands

php artisan make:migration create_posts_table
php artisan migrate
php artisan migrate:rollback --step=1
php artisan migrate:fresh --seed

Best Practices

DO

  • Use
    foreignId()->constrained()
    for foreign keys
  • Add composite indexes for common queries
  • Test down() method before deploying
  • Use
    --pretend
    to preview SQL

DON'T

  • Modify already-deployed migrations
  • Forget down() method
  • Use raw SQL without Schema Builder
  • Skip indexes on foreign keys