@juho0719/cckit 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/agents/architect.md +211 -0
- package/assets/agents/build-error-resolver.md +114 -0
- package/assets/agents/ccwin-code-reviewer.md +224 -0
- package/assets/agents/database-reviewer.md +91 -0
- package/assets/agents/doc-updater.md +107 -0
- package/assets/agents/e2e-runner.md +107 -0
- package/assets/agents/planner.md +212 -0
- package/assets/agents/python-reviewer.md +98 -0
- package/assets/agents/refactor-cleaner.md +85 -0
- package/assets/agents/security-reviewer.md +108 -0
- package/assets/agents/superpower-code-reviewer.md +48 -0
- package/assets/agents/tdd-guide.md +80 -0
- package/assets/commands/build-fix.md +62 -0
- package/assets/commands/checkpoint.md +74 -0
- package/assets/commands/code-review.md +40 -0
- package/assets/commands/e2e.md +362 -0
- package/assets/commands/eval.md +120 -0
- package/assets/commands/orchestrate.md +172 -0
- package/assets/commands/plan.md +113 -0
- package/assets/commands/python-review.md +297 -0
- package/assets/commands/refactor-clean.md +80 -0
- package/assets/commands/sessions.md +305 -0
- package/assets/commands/tdd.md +326 -0
- package/assets/commands/test-coverage.md +69 -0
- package/assets/commands/update-codemaps.md +72 -0
- package/assets/commands/update-docs.md +84 -0
- package/assets/commands/verify.md +59 -0
- package/assets/hooks/post-edit-format.js +49 -0
- package/assets/hooks/post-edit-typecheck.js +96 -0
- package/assets/mcps/mcp-servers.json +92 -0
- package/assets/rules/common/agents.md +49 -0
- package/assets/rules/common/coding-style.md +48 -0
- package/assets/rules/common/git-workflow.md +45 -0
- package/assets/rules/common/hooks.md +30 -0
- package/assets/rules/common/patterns.md +31 -0
- package/assets/rules/common/performance.md +55 -0
- package/assets/rules/common/security.md +29 -0
- package/assets/rules/common/testing.md +29 -0
- package/assets/rules/python/coding-style.md +42 -0
- package/assets/rules/python/hooks.md +19 -0
- package/assets/rules/python/patterns.md +39 -0
- package/assets/rules/python/security.md +30 -0
- package/assets/rules/python/testing.md +38 -0
- package/assets/rules/typescript/coding-style.md +18 -0
- package/assets/rules/typescript/hooks.md +19 -0
- package/assets/rules/typescript/patterns.md +39 -0
- package/assets/rules/typescript/security.md +30 -0
- package/assets/rules/typescript/testing.md +38 -0
- package/assets/skills/api-design/SKILL.md +522 -0
- package/assets/skills/backend-patterns/SKILL.md +597 -0
- package/assets/skills/brainstorming/SKILL.md +96 -0
- package/assets/skills/coding-standards/SKILL.md +529 -0
- package/assets/skills/database-migrations/SKILL.md +334 -0
- package/assets/skills/deployment-patterns/SKILL.md +426 -0
- package/assets/skills/dispatching-parallel-agents/SKILL.md +180 -0
- package/assets/skills/docker-patterns/SKILL.md +363 -0
- package/assets/skills/e2e-testing/SKILL.md +325 -0
- package/assets/skills/eval-harness/SKILL.md +235 -0
- package/assets/skills/executing-plans/SKILL.md +84 -0
- package/assets/skills/finishing-a-development-branch/SKILL.md +200 -0
- package/assets/skills/frontend-patterns/SKILL.md +641 -0
- package/assets/skills/iterative-retrieval/SKILL.md +210 -0
- package/assets/skills/postgres-patterns/SKILL.md +145 -0
- package/assets/skills/python-patterns/SKILL.md +749 -0
- package/assets/skills/python-testing/SKILL.md +815 -0
- package/assets/skills/receiving-code-review/SKILL.md +213 -0
- package/assets/skills/requesting-code-review/SKILL.md +105 -0
- package/assets/skills/requesting-code-review/code-reviewer-template.md +146 -0
- package/assets/skills/subagent-driven-development/SKILL.md +242 -0
- package/assets/skills/subagent-driven-development/code-quality-reviewer-prompt.md +20 -0
- package/assets/skills/subagent-driven-development/implementer-prompt.md +78 -0
- package/assets/skills/subagent-driven-development/spec-reviewer-prompt.md +61 -0
- package/assets/skills/systematic-debugging/CREATION-LOG.md +114 -0
- package/assets/skills/systematic-debugging/SKILL.md +296 -0
- package/assets/skills/systematic-debugging/condition-based-waiting-example.ts +158 -0
- package/assets/skills/systematic-debugging/condition-based-waiting.md +115 -0
- package/assets/skills/systematic-debugging/defense-in-depth.md +122 -0
- package/assets/skills/systematic-debugging/root-cause-tracing.md +169 -0
- package/assets/skills/systematic-debugging/scripts/find-polluter.sh +63 -0
- package/assets/skills/systematic-debugging/test-academic.md +14 -0
- package/assets/skills/systematic-debugging/test-pressure-1.md +58 -0
- package/assets/skills/systematic-debugging/test-pressure-2.md +68 -0
- package/assets/skills/systematic-debugging/test-pressure-3.md +69 -0
- package/assets/skills/tdd-workflow/SKILL.md +409 -0
- package/assets/skills/test-driven-development/SKILL.md +371 -0
- package/assets/skills/test-driven-development/testing-anti-patterns.md +299 -0
- package/assets/skills/using-git-worktrees/SKILL.md +218 -0
- package/assets/skills/verification-before-completion/SKILL.md +139 -0
- package/assets/skills/verification-loop/SKILL.md +125 -0
- package/assets/skills/writing-plans/SKILL.md +116 -0
- package/dist/agents-AEKT67A6.js +9 -0
- package/dist/chunk-3GUKEMND.js +28 -0
- package/dist/chunk-3UNN3IBE.js +54 -0
- package/dist/chunk-3Y26YU4R.js +27 -0
- package/dist/chunk-5XOKKPAA.js +21 -0
- package/dist/chunk-6B46AIFM.js +136 -0
- package/dist/chunk-EYY2IZ7N.js +27 -0
- package/dist/chunk-K25UZZVG.js +17 -0
- package/dist/chunk-KEENFBLL.js +24 -0
- package/dist/chunk-RMUKD7CW.js +44 -0
- package/dist/chunk-W63UKEIT.js +50 -0
- package/dist/cli-VZRGF733.js +238 -0
- package/dist/commands-P5LILVZ5.js +9 -0
- package/dist/hooks-IIG2XK4I.js +9 -0
- package/dist/index.js +131 -0
- package/dist/mcps-67Q7TBGW.js +6 -0
- package/dist/paths-FT6KBIRD.js +10 -0
- package/dist/registry-EGXWYWWK.js +17 -0
- package/dist/rules-2CPBVNNJ.js +7 -0
- package/dist/skills-ULMW3UCM.js +8 -0
- package/package.json +36 -0
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: database-migrations
|
|
3
|
+
description: Database migration best practices for schema changes, data migrations, rollbacks, and zero-downtime deployments across PostgreSQL, MySQL, and common ORMs (Prisma, Drizzle, Django, TypeORM, golang-migrate).
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Database Migration Patterns
|
|
7
|
+
|
|
8
|
+
Safe, reversible database schema changes for production systems.
|
|
9
|
+
|
|
10
|
+
## When to Activate
|
|
11
|
+
|
|
12
|
+
- Creating or altering database tables
|
|
13
|
+
- Adding/removing columns or indexes
|
|
14
|
+
- Running data migrations (backfill, transform)
|
|
15
|
+
- Planning zero-downtime schema changes
|
|
16
|
+
- Setting up migration tooling for a new project
|
|
17
|
+
|
|
18
|
+
## Core Principles
|
|
19
|
+
|
|
20
|
+
1. **Every change is a migration** — never alter production databases manually
|
|
21
|
+
2. **Migrations are forward-only in production** — rollbacks use new forward migrations
|
|
22
|
+
3. **Schema and data migrations are separate** — never mix DDL and DML in one migration
|
|
23
|
+
4. **Test migrations against production-sized data** — a migration that works on 100 rows may lock on 10M
|
|
24
|
+
5. **Migrations are immutable once deployed** — never edit a migration that has run in production
|
|
25
|
+
|
|
26
|
+
## Migration Safety Checklist
|
|
27
|
+
|
|
28
|
+
Before applying any migration:
|
|
29
|
+
|
|
30
|
+
- [ ] Migration has both UP and DOWN (or is explicitly marked irreversible)
|
|
31
|
+
- [ ] No full table locks on large tables (use concurrent operations)
|
|
32
|
+
- [ ] New columns have defaults or are nullable (never add NOT NULL without default)
|
|
33
|
+
- [ ] Indexes created concurrently (not inline with CREATE TABLE for existing tables)
|
|
34
|
+
- [ ] Data backfill is a separate migration from schema change
|
|
35
|
+
- [ ] Tested against a copy of production data
|
|
36
|
+
- [ ] Rollback plan documented
|
|
37
|
+
|
|
38
|
+
## PostgreSQL Patterns
|
|
39
|
+
|
|
40
|
+
### Adding a Column Safely
|
|
41
|
+
|
|
42
|
+
```sql
|
|
43
|
+
-- GOOD: Nullable column, no lock
|
|
44
|
+
ALTER TABLE users ADD COLUMN avatar_url TEXT;
|
|
45
|
+
|
|
46
|
+
-- GOOD: Column with default (Postgres 11+ is instant, no rewrite)
|
|
47
|
+
ALTER TABLE users ADD COLUMN is_active BOOLEAN NOT NULL DEFAULT true;
|
|
48
|
+
|
|
49
|
+
-- BAD: NOT NULL without default on existing table (requires full rewrite)
|
|
50
|
+
ALTER TABLE users ADD COLUMN role TEXT NOT NULL;
|
|
51
|
+
-- This locks the table and rewrites every row
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Adding an Index Without Downtime
|
|
55
|
+
|
|
56
|
+
```sql
|
|
57
|
+
-- BAD: Blocks writes on large tables
|
|
58
|
+
CREATE INDEX idx_users_email ON users (email);
|
|
59
|
+
|
|
60
|
+
-- GOOD: Non-blocking, allows concurrent writes
|
|
61
|
+
CREATE INDEX CONCURRENTLY idx_users_email ON users (email);
|
|
62
|
+
|
|
63
|
+
-- Note: CONCURRENTLY cannot run inside a transaction block
|
|
64
|
+
-- Most migration tools need special handling for this
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Renaming a Column (Zero-Downtime)
|
|
68
|
+
|
|
69
|
+
Never rename directly in production. Use the expand-contract pattern:
|
|
70
|
+
|
|
71
|
+
```sql
|
|
72
|
+
-- Step 1: Add new column (migration 001)
|
|
73
|
+
ALTER TABLE users ADD COLUMN display_name TEXT;
|
|
74
|
+
|
|
75
|
+
-- Step 2: Backfill data (migration 002, data migration)
|
|
76
|
+
UPDATE users SET display_name = username WHERE display_name IS NULL;
|
|
77
|
+
|
|
78
|
+
-- Step 3: Update application code to read/write both columns
|
|
79
|
+
-- Deploy application changes
|
|
80
|
+
|
|
81
|
+
-- Step 4: Stop writing to old column, drop it (migration 003)
|
|
82
|
+
ALTER TABLE users DROP COLUMN username;
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Removing a Column Safely
|
|
86
|
+
|
|
87
|
+
```sql
|
|
88
|
+
-- Step 1: Remove all application references to the column
|
|
89
|
+
-- Step 2: Deploy application without the column reference
|
|
90
|
+
-- Step 3: Drop column in next migration
|
|
91
|
+
ALTER TABLE orders DROP COLUMN legacy_status;
|
|
92
|
+
|
|
93
|
+
-- For Django: use SeparateDatabaseAndState to remove from model
|
|
94
|
+
-- without generating DROP COLUMN (then drop in next migration)
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Large Data Migrations
|
|
98
|
+
|
|
99
|
+
```sql
|
|
100
|
+
-- BAD: Updates all rows in one transaction (locks table)
|
|
101
|
+
UPDATE users SET normalized_email = LOWER(email);
|
|
102
|
+
|
|
103
|
+
-- GOOD: Batch update with progress
|
|
104
|
+
DO $$
|
|
105
|
+
DECLARE
|
|
106
|
+
batch_size INT := 10000;
|
|
107
|
+
rows_updated INT;
|
|
108
|
+
BEGIN
|
|
109
|
+
LOOP
|
|
110
|
+
UPDATE users
|
|
111
|
+
SET normalized_email = LOWER(email)
|
|
112
|
+
WHERE id IN (
|
|
113
|
+
SELECT id FROM users
|
|
114
|
+
WHERE normalized_email IS NULL
|
|
115
|
+
LIMIT batch_size
|
|
116
|
+
FOR UPDATE SKIP LOCKED
|
|
117
|
+
);
|
|
118
|
+
GET DIAGNOSTICS rows_updated = ROW_COUNT;
|
|
119
|
+
RAISE NOTICE 'Updated % rows', rows_updated;
|
|
120
|
+
EXIT WHEN rows_updated = 0;
|
|
121
|
+
COMMIT;
|
|
122
|
+
END LOOP;
|
|
123
|
+
END $$;
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Prisma (TypeScript/Node.js)
|
|
127
|
+
|
|
128
|
+
### Workflow
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
# Create migration from schema changes
|
|
132
|
+
npx prisma migrate dev --name add_user_avatar
|
|
133
|
+
|
|
134
|
+
# Apply pending migrations in production
|
|
135
|
+
npx prisma migrate deploy
|
|
136
|
+
|
|
137
|
+
# Reset database (dev only)
|
|
138
|
+
npx prisma migrate reset
|
|
139
|
+
|
|
140
|
+
# Generate client after schema changes
|
|
141
|
+
npx prisma generate
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Schema Example
|
|
145
|
+
|
|
146
|
+
```prisma
|
|
147
|
+
model User {
|
|
148
|
+
id String @id @default(cuid())
|
|
149
|
+
email String @unique
|
|
150
|
+
name String?
|
|
151
|
+
avatarUrl String? @map("avatar_url")
|
|
152
|
+
createdAt DateTime @default(now()) @map("created_at")
|
|
153
|
+
updatedAt DateTime @updatedAt @map("updated_at")
|
|
154
|
+
orders Order[]
|
|
155
|
+
|
|
156
|
+
@@map("users")
|
|
157
|
+
@@index([email])
|
|
158
|
+
}
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### Custom SQL Migration
|
|
162
|
+
|
|
163
|
+
For operations Prisma cannot express (concurrent indexes, data backfills):
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
# Create empty migration, then edit the SQL manually
|
|
167
|
+
npx prisma migrate dev --create-only --name add_email_index
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
```sql
|
|
171
|
+
-- migrations/20240115_add_email_index/migration.sql
|
|
172
|
+
-- Prisma cannot generate CONCURRENTLY, so we write it manually
|
|
173
|
+
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_users_email ON users (email);
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## Drizzle (TypeScript/Node.js)
|
|
177
|
+
|
|
178
|
+
### Workflow
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
# Generate migration from schema changes
|
|
182
|
+
npx drizzle-kit generate
|
|
183
|
+
|
|
184
|
+
# Apply migrations
|
|
185
|
+
npx drizzle-kit migrate
|
|
186
|
+
|
|
187
|
+
# Push schema directly (dev only, no migration file)
|
|
188
|
+
npx drizzle-kit push
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### Schema Example
|
|
192
|
+
|
|
193
|
+
```typescript
|
|
194
|
+
import { pgTable, text, timestamp, uuid, boolean } from "drizzle-orm/pg-core";
|
|
195
|
+
|
|
196
|
+
export const users = pgTable("users", {
|
|
197
|
+
id: uuid("id").primaryKey().defaultRandom(),
|
|
198
|
+
email: text("email").notNull().unique(),
|
|
199
|
+
name: text("name"),
|
|
200
|
+
isActive: boolean("is_active").notNull().default(true),
|
|
201
|
+
createdAt: timestamp("created_at").notNull().defaultNow(),
|
|
202
|
+
updatedAt: timestamp("updated_at").notNull().defaultNow(),
|
|
203
|
+
});
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## Django (Python)
|
|
207
|
+
|
|
208
|
+
### Workflow
|
|
209
|
+
|
|
210
|
+
```bash
|
|
211
|
+
# Generate migration from model changes
|
|
212
|
+
python manage.py makemigrations
|
|
213
|
+
|
|
214
|
+
# Apply migrations
|
|
215
|
+
python manage.py migrate
|
|
216
|
+
|
|
217
|
+
# Show migration status
|
|
218
|
+
python manage.py showmigrations
|
|
219
|
+
|
|
220
|
+
# Generate empty migration for custom SQL
|
|
221
|
+
python manage.py makemigrations --empty app_name -n description
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
### Data Migration
|
|
225
|
+
|
|
226
|
+
```python
|
|
227
|
+
from django.db import migrations
|
|
228
|
+
|
|
229
|
+
def backfill_display_names(apps, schema_editor):
|
|
230
|
+
User = apps.get_model("accounts", "User")
|
|
231
|
+
batch_size = 5000
|
|
232
|
+
users = User.objects.filter(display_name="")
|
|
233
|
+
while users.exists():
|
|
234
|
+
batch = list(users[:batch_size])
|
|
235
|
+
for user in batch:
|
|
236
|
+
user.display_name = user.username
|
|
237
|
+
User.objects.bulk_update(batch, ["display_name"], batch_size=batch_size)
|
|
238
|
+
|
|
239
|
+
def reverse_backfill(apps, schema_editor):
|
|
240
|
+
pass # Data migration, no reverse needed
|
|
241
|
+
|
|
242
|
+
class Migration(migrations.Migration):
|
|
243
|
+
dependencies = [("accounts", "0015_add_display_name")]
|
|
244
|
+
|
|
245
|
+
operations = [
|
|
246
|
+
migrations.RunPython(backfill_display_names, reverse_backfill),
|
|
247
|
+
]
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
### SeparateDatabaseAndState
|
|
251
|
+
|
|
252
|
+
Remove a column from the Django model without dropping it from the database immediately:
|
|
253
|
+
|
|
254
|
+
```python
|
|
255
|
+
class Migration(migrations.Migration):
|
|
256
|
+
operations = [
|
|
257
|
+
migrations.SeparateDatabaseAndState(
|
|
258
|
+
state_operations=[
|
|
259
|
+
migrations.RemoveField(model_name="user", name="legacy_field"),
|
|
260
|
+
],
|
|
261
|
+
database_operations=[], # Don't touch the DB yet
|
|
262
|
+
),
|
|
263
|
+
]
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
## golang-migrate (Go)
|
|
267
|
+
|
|
268
|
+
### Workflow
|
|
269
|
+
|
|
270
|
+
```bash
|
|
271
|
+
# Create migration pair
|
|
272
|
+
migrate create -ext sql -dir migrations -seq add_user_avatar
|
|
273
|
+
|
|
274
|
+
# Apply all pending migrations
|
|
275
|
+
migrate -path migrations -database "$DATABASE_URL" up
|
|
276
|
+
|
|
277
|
+
# Rollback last migration
|
|
278
|
+
migrate -path migrations -database "$DATABASE_URL" down 1
|
|
279
|
+
|
|
280
|
+
# Force version (fix dirty state)
|
|
281
|
+
migrate -path migrations -database "$DATABASE_URL" force VERSION
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
### Migration Files
|
|
285
|
+
|
|
286
|
+
```sql
|
|
287
|
+
-- migrations/000003_add_user_avatar.up.sql
|
|
288
|
+
ALTER TABLE users ADD COLUMN avatar_url TEXT;
|
|
289
|
+
CREATE INDEX CONCURRENTLY idx_users_avatar ON users (avatar_url) WHERE avatar_url IS NOT NULL;
|
|
290
|
+
|
|
291
|
+
-- migrations/000003_add_user_avatar.down.sql
|
|
292
|
+
DROP INDEX IF EXISTS idx_users_avatar;
|
|
293
|
+
ALTER TABLE users DROP COLUMN IF EXISTS avatar_url;
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
## Zero-Downtime Migration Strategy
|
|
297
|
+
|
|
298
|
+
For critical production changes, follow the expand-contract pattern:
|
|
299
|
+
|
|
300
|
+
```
|
|
301
|
+
Phase 1: EXPAND
|
|
302
|
+
- Add new column/table (nullable or with default)
|
|
303
|
+
- Deploy: app writes to BOTH old and new
|
|
304
|
+
- Backfill existing data
|
|
305
|
+
|
|
306
|
+
Phase 2: MIGRATE
|
|
307
|
+
- Deploy: app reads from NEW, writes to BOTH
|
|
308
|
+
- Verify data consistency
|
|
309
|
+
|
|
310
|
+
Phase 3: CONTRACT
|
|
311
|
+
- Deploy: app only uses NEW
|
|
312
|
+
- Drop old column/table in separate migration
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
### Timeline Example
|
|
316
|
+
|
|
317
|
+
```
|
|
318
|
+
Day 1: Migration adds new_status column (nullable)
|
|
319
|
+
Day 1: Deploy app v2 — writes to both status and new_status
|
|
320
|
+
Day 2: Run backfill migration for existing rows
|
|
321
|
+
Day 3: Deploy app v3 — reads from new_status only
|
|
322
|
+
Day 7: Migration drops old status column
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
## Anti-Patterns
|
|
326
|
+
|
|
327
|
+
| Anti-Pattern | Why It Fails | Better Approach |
|
|
328
|
+
|-------------|-------------|-----------------|
|
|
329
|
+
| Manual SQL in production | No audit trail, unrepeatable | Always use migration files |
|
|
330
|
+
| Editing deployed migrations | Causes drift between environments | Create new migration instead |
|
|
331
|
+
| NOT NULL without default | Locks table, rewrites all rows | Add nullable, backfill, then add constraint |
|
|
332
|
+
| Inline index on large table | Blocks writes during build | CREATE INDEX CONCURRENTLY |
|
|
333
|
+
| Schema + data in one migration | Hard to rollback, long transactions | Separate migrations |
|
|
334
|
+
| Dropping column before removing code | Application errors on missing column | Remove code first, drop column next deploy |
|