db-migrations
Use for database rollout strategy, Drizzle migrations, online index creation, data backfills, migration regeneration, sequence conflicts after rebase, idempotent SQL review, or migration renames.
npx skills add lobehub/lobehub --skill db-migrations --agent claude-code
Same command for any agent — swap --agent for codex, cursor, copilot.
Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.
# Database Migrations Guide ## Choose the rollout strategy Classify every database change into one of these three rollout paths before generating or editing a migration. ### 1. Regular Drizzle migration Use the normal Drizzle workflow for schema changes that are safe to execute during deployment, such as creating a small table or adding a nullable column: 1. Update the Drizzle schema. 2. Run `bun run db:generate`. 3. Review and harden the generated artifacts using the steps below. Before listing a manual migration command as a release step, inspect the target repository's build and deployment scripts. If its deployment pipeline already applies migrations automatically, do not require a redundant manual run. ### 2. Online index creation Creating an index normally can block writes and queries on a large or frequently accessed table, and a long-running statement can also stall the deployment. In that case: 1. Before deploying the application, execute the index creation manually in the target database's SQL editor using `CONCURRENTLY`: ```sql CREATE INDEX CONCURRENTLY IF NOT EXISTS "table_column_idx" ON "table" USING btree ("column"); ``` 2. Keep an idempotent, non-`CONCURRENTLY` versi
- Choose the rollout strategy
- 1. Regular Drizzle migration
- 2. Online index creation
- 3. Data backfill
- Development-stage schema changes
- Rebase conflicts
- Step 1: Generate Migrations
- Custom Migrations (e.g. CREATE EXTENSION)
- Step 2: Optimize Migration SQL Filename
- Step 3: Use Idempotent Clauses (Defensive Programming)
- CREATE TABLE
- ALTER TABLE - Columns
- ALTER TABLE - Foreign Key Constraints
- DROP TABLE / INDEX
rm packages/database/migrations/0110_add_verify_tables_and_ai_infra_id.sql
rm packages/database/migrations/meta/0110_snapshot.json
packages/database/migrations/meta/_journal.json
bun run db:generate
rm packages/database/migrations/011{0,1,2}_*.sql
rm packages/database/migrations/meta/011{0,1,2}_snapshot.json
Fix the dev DB to match the new schema (simplest SQL wins)
set -a && source .env && set +a && bun -e '
import pg from "pg";
const client = new pg.Client({ connectionString: process.env.DATABASE_URL });What does the db-migrations skill do?
Use for database rollout strategy, Drizzle migrations, online index creation, data backfills, migration regeneration, sequence conflicts after rebase, idempotent SQL review, or migration renames.
How do I install it?
Run `npx skills add lobehub/lobehub --skill db-migrations --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.
Where does this skill come from?
From lobehub/lobehub, a repository with 81,252 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.
Is a popular skill a good skill?
Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.