Database operations - seed, reset, prepare, and more
Execute Rails database operations like seed, reset, and prepare with environment-specific safety checks and confirmations for destructive actions.
/plugin marketplace add betamatt/claude-plugins/plugin install ruby-on-rails@betamatt-claude-plugins<seed|reset|prepare|schema:load|schema:dump>Execute common database operations with appropriate safeguards.
/rails:db <action>
Run database seeds.
bin/rails db:seed
Drop, create, migrate, and seed the database.
bin/rails db:reset
WARNING: This destroys all data. Only use in development.
Prepare database for the current environment (creates if needed, runs migrations).
bin/rails db:prepare
Safe for all environments.
Load schema from db/schema.rb (faster than running all migrations).
bin/rails db:schema:load
Dump current database schema to db/schema.rb.
bin/rails db:schema:dump
Create database, load schema, and seed.
bin/rails db:setup
Create the database.
bin/rails db:create
Drop the database.
bin/rails db:drop
WARNING: Destructive operation.
All operations allowed with standard warnings for destructive actions.
Restricted operations:
reset - BLOCKED (never reset production)drop - BLOCKED (manual intervention required)schema:load - WARNING (destroys existing data)seed - WARNING (may duplicate data)prepare - ALLOWED (safe idempotent operation)Recommend idempotent seeds:
# db/seeds.rb
# Use find_or_create_by for idempotency
User.find_or_create_by(email: "admin@example.com") do |user|
user.name = "Admin"
user.admin = true
end
# Or use upsert for bulk data
Product.upsert_all([
{ sku: "WIDGET-001", name: "Widget", price: 9.99 },
{ sku: "GADGET-001", name: "Gadget", price: 19.99 }
], unique_by: :sku)
Action: db:prepare
Environment: development
Database: myapp_development
Checking database status...
Database exists: ✓
Pending migrations: 2
Running db:prepare...
Running migrations...
== 20231203140000 AddOrdersTable: migrating ===
== 20231203140000 AddOrdersTable: migrated (0.0123s) ===
✓ Database prepared successfully
Schema version: 20231203140000
Tables: 8