C

Create Database Rapid

Powerful command for create, manage, database, migrations. Includes structured workflows, validation checks, and reusable patterns for setup.

CommandClipticssetupv1.0.0MIT
0 views0 copies

Create Database Rapid

Generate timestamped database migration files with up/down methods, schema changes, data transformations, and rollback strategies for your detected ORM framework.

When to Use This Command

Run this command when...

  • You need to create a new database migration for table creation, column additions, or schema alterations
  • You want properly timestamped migration files with both up and down methods for safe rollbacks
  • You need to perform data migrations or backfills alongside schema changes with transactional safety
  • You are working with Prisma, Sequelize, Alembic, Knex, or other ORM migration frameworks
  • You want migration files that follow your framework's conventions with proper indexing and constraints

Quick Start

# .claude/commands/create-database-rapid.yaml name: Create Database Rapid description: Generate database migrations with rollback support inputs: - name: description description: "What this migration does" - name: type description: "create-table, add-column, alter-table, data-migration" default: "create-table"
# Create a new users table claude "create-database-rapid 'create users table' --type create-table" # Add a column to an existing table claude "create-database-rapid 'add email_verified to users' --type add-column" # Data migration with backfill claude "create-database-rapid 'backfill user display names' --type data-migration"
Output:
  [detect] ORM: Prisma (prisma/schema.prisma found)
  [generate] Migration: 20260315_create_users_table
  [create] prisma/migrations/20260315_create_users_table/migration.sql
  [schema] Updated prisma/schema.prisma with User model
  [validate] Migration syntax verified
  [preview] Tables: users (id, email, name, created_at, updated_at)
  Done. Run 'npx prisma migrate dev' to apply.

Core Concepts

ConceptDescription
ORM DetectionAuto-detects migration framework from Prisma, Sequelize, Knex, Alembic, TypeORM, or Django
Timestamped FilesMigration files include ISO timestamps for ordering and conflict-free merges
Up/Down MethodsEvery migration includes both forward (up) and rollback (down) implementations
Data SafetyData migrations use transactions and batch processing to prevent data loss on failure
Index StrategyAutomatically suggests indexes based on column types, foreign keys, and query patterns
Migration Lifecycle:
  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚ Generate │───>β”‚ Validate │───>β”‚  Apply   β”‚
  β”‚ Migrationβ”‚    β”‚  Syntax  β”‚    β”‚ (Dev DB) β”‚
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜
                                      β”‚
                                 β”Œβ”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”
                                 β”‚  Test &  β”‚
                                 β”‚  Verify  β”‚
                                 β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜
                                      β”‚
                       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
                       β–Ό              β–Ό
                  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                  β”‚ Promote β”‚   β”‚ Rollback  β”‚
                  β”‚ to Prod β”‚   β”‚   (Down)  β”‚
                  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Configuration

ParameterTypeDefaultDescription
descriptionstringrequiredHuman-readable description of what the migration does
typestring"create-table"Migration type: create-table, add-column, alter-table, data-migration, drop-table
tablestringinferredTarget table name; inferred from description if not specified
columnsstring""Column definitions: "name:string, age:integer, email:string:unique"
dry_runbooleanfalsePreview generated migration without writing files

Best Practices

  1. One change per migration -- Keep each migration focused on a single schema change. This makes rollbacks predictable and debugging easier when a migration fails.
  2. Always write the down method -- Skipping rollback logic saves time now but creates pain later. Test the down method on your development database before promoting to staging.
  3. Use transactions for data migrations -- Wrap data transformations in transactions so that partial failures do not leave the database in an inconsistent state.
  4. Add indexes deliberately -- Foreign keys and frequently queried columns should have indexes. Let the command suggest them, then review whether they match your actual query patterns.
  5. Test migrations on a copy of production data -- Schema changes that work on empty tables may fail or be slow on tables with millions of rows. Test with realistic data volumes.

Common Issues

  1. ORM not detected -- The command looks for framework-specific files like prisma/schema.prisma or alembic.ini. If your ORM config is in a non-standard location, specify the framework explicitly.
  2. Migration conflicts with teammates -- Two developers creating migrations simultaneously can produce conflicting timestamps. Coordinate migration creation or use your ORM's conflict resolution tools.
  3. Rollback fails on data migration -- Data backfills cannot always be reversed (e.g., hashing a column). Document irreversible migrations clearly and consider backup strategies.
Community

Reviews

Write a review

No reviews yet. Be the first to review this template!

Similar Templates