@baselane/packs 0.1.3 → 0.1.5

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.
Files changed (91) hide show
  1. package/dist/aliases.js +1 -0
  2. package/package.json +2 -2
  3. package/packs/database-review/pack.json +75 -9
  4. package/packs/database-review/rendered/.claude/agents/database-reviewer.md +75 -2
  5. package/packs/database-review/rendered/.claude/commands/migration-review.md +6 -0
  6. package/packs/database-review/rendered/.claude/settings.json +11 -0
  7. package/packs/database-review/rendered/.claude/skills/database-migrations/SKILL.md +431 -0
  8. package/packs/database-review/rendered/.claude/skills/mysql-patterns/SKILL.md +414 -0
  9. package/packs/database-review/rendered/.claude/skills/postgres-patterns/SKILL.md +149 -0
  10. package/packs/database-review/rendered/.github/copilot-instructions.md +1096 -14
  11. package/packs/database-review/rendered/AGENTS.md +45 -16
  12. package/packs/database-review/rendered/CLAUDE.md +4 -0
  13. package/packs/database-review/rendered/GEMINI.md +987 -0
  14. package/packs/go-rules/pack.json +65 -9
  15. package/packs/go-rules/rendered/.claude/agents/go-build-resolver.md +90 -0
  16. package/packs/go-rules/rendered/.claude/agents/go-reviewer.md +72 -2
  17. package/packs/go-rules/rendered/.claude/commands/go-build.md +6 -0
  18. package/packs/go-rules/rendered/.claude/commands/go-review.md +1 -1
  19. package/packs/go-rules/rendered/.claude/commands/go-test.md +6 -0
  20. package/packs/go-rules/rendered/.claude/settings.json +9 -0
  21. package/packs/go-rules/rendered/.claude/skills/golang-patterns/SKILL.md +673 -0
  22. package/packs/go-rules/rendered/.claude/skills/golang-testing/SKILL.md +719 -0
  23. package/packs/go-rules/rendered/.github/copilot-instructions.md +1783 -7
  24. package/packs/go-rules/rendered/AGENTS.md +244 -8
  25. package/packs/go-rules/rendered/CLAUDE.md +5 -0
  26. package/packs/go-rules/rendered/GEMINI.md +1394 -0
  27. package/packs/python-rules/pack.json +87 -10
  28. package/packs/python-rules/rendered/.claude/agents/django-reviewer.md +159 -0
  29. package/packs/python-rules/rendered/.claude/agents/fastapi-reviewer.md +70 -0
  30. package/packs/python-rules/rendered/.claude/agents/python-reviewer.md +92 -2
  31. package/packs/python-rules/rendered/.claude/commands/django-review.md +6 -0
  32. package/packs/python-rules/rendered/.claude/commands/fastapi-review.md +6 -0
  33. package/packs/python-rules/rendered/.claude/commands/python-review.md +1 -1
  34. package/packs/python-rules/rendered/.claude/settings.json +1 -1
  35. package/packs/python-rules/rendered/.claude/skills/django-security/SKILL.md +642 -0
  36. package/packs/python-rules/rendered/.claude/skills/django-tdd/SKILL.md +728 -0
  37. package/packs/python-rules/rendered/.claude/skills/fastapi-patterns/SKILL.md +512 -0
  38. package/packs/python-rules/rendered/.claude/skills/python-patterns/SKILL.md +749 -0
  39. package/packs/python-rules/rendered/.claude/skills/python-testing/SKILL.md +815 -0
  40. package/packs/python-rules/rendered/.github/copilot-instructions.md +3815 -12
  41. package/packs/python-rules/rendered/AGENTS.md +73 -13
  42. package/packs/python-rules/rendered/CLAUDE.md +9 -0
  43. package/packs/python-rules/rendered/GEMINI.md +3448 -0
  44. package/packs/security-review/pack.json +51 -7
  45. package/packs/security-review/rendered/.claude/agents/security-reviewer.md +29 -2
  46. package/packs/security-review/rendered/.claude/settings.json +11 -0
  47. package/packs/security-review/rendered/.claude/skills/security-review/SKILL.md +302 -0
  48. package/packs/security-review/rendered/.claude/skills/security-review/cloud-infrastructure-security.md +171 -0
  49. package/packs/security-review/rendered/.claude/skills/security-scan-config/SKILL.md +56 -0
  50. package/packs/security-review/rendered/.github/copilot-instructions.md +658 -15
  51. package/packs/security-review/rendered/AGENTS.md +283 -17
  52. package/packs/security-review/rendered/CLAUDE.md +2 -0
  53. package/packs/security-review/rendered/GEMINI.md +352 -0
  54. package/packs/software-engineer-harness/pack.json +249 -13
  55. package/packs/software-engineer-harness/rendered/.claude/agents/build-error-resolver.md +15 -0
  56. package/packs/software-engineer-harness/rendered/.claude/agents/code-explorer.md +67 -0
  57. package/packs/software-engineer-harness/rendered/.claude/agents/performance-optimizer.md +444 -0
  58. package/packs/software-engineer-harness/rendered/.claude/agents/pr-test-analyzer.md +43 -0
  59. package/packs/software-engineer-harness/rendered/.claude/agents/refactor-cleaner.md +12 -0
  60. package/packs/software-engineer-harness/rendered/.claude/agents/silent-failure-hunter.md +16 -0
  61. package/packs/software-engineer-harness/rendered/.claude/agents/tdd-guide.md +16 -0
  62. package/packs/software-engineer-harness/rendered/.claude/commands/feature-dev.md +6 -0
  63. package/packs/software-engineer-harness/rendered/.claude/commands/fix-build.md +6 -0
  64. package/packs/software-engineer-harness/rendered/.claude/commands/hunt-silent-failures.md +6 -0
  65. package/packs/software-engineer-harness/rendered/.claude/commands/tdd.md +6 -0
  66. package/packs/software-engineer-harness/rendered/.claude/settings.json +29 -0
  67. package/packs/software-engineer-harness/rendered/.claude/skills/api-design/SKILL.md +522 -0
  68. package/packs/software-engineer-harness/rendered/.claude/skills/architecture-decision-records/SKILL.md +178 -0
  69. package/packs/software-engineer-harness/rendered/.claude/skills/backend-patterns/SKILL.md +560 -0
  70. package/packs/software-engineer-harness/rendered/.claude/skills/codebase-onboarding/SKILL.md +232 -0
  71. package/packs/software-engineer-harness/rendered/.claude/skills/deployment-patterns/SKILL.md +426 -0
  72. package/packs/software-engineer-harness/rendered/.claude/skills/docker-patterns/SKILL.md +363 -0
  73. package/packs/software-engineer-harness/rendered/.claude/skills/e2e-testing/SKILL.md +325 -0
  74. package/packs/software-engineer-harness/rendered/.claude/skills/tdd-red-green-refactor/SKILL.md +20 -0
  75. package/packs/software-engineer-harness/rendered/.claude/skills/tdd-workflow/SKILL.md +580 -0
  76. package/packs/software-engineer-harness/rendered/.github/copilot-instructions.md +3948 -2
  77. package/packs/software-engineer-harness/rendered/AGENTS.md +194 -4
  78. package/packs/software-engineer-harness/rendered/CLAUDE.md +20 -0
  79. package/packs/software-engineer-harness/rendered/GEMINI.md +3208 -0
  80. package/packs/typescript-rules/pack.json +68 -5
  81. package/packs/typescript-rules/rendered/.claude/agents/react-reviewer.md +165 -0
  82. package/packs/typescript-rules/rendered/.claude/agents/type-design-analyzer.md +48 -0
  83. package/packs/typescript-rules/rendered/.claude/commands/react-review.md +6 -0
  84. package/packs/typescript-rules/rendered/.claude/settings.json +9 -0
  85. package/packs/typescript-rules/rendered/.claude/skills/react-patterns/SKILL.md +340 -0
  86. package/packs/typescript-rules/rendered/.claude/skills/react-performance/SKILL.md +573 -0
  87. package/packs/typescript-rules/rendered/.claude/skills/react-testing/SKILL.md +422 -0
  88. package/packs/typescript-rules/rendered/.github/copilot-instructions.md +2459 -53
  89. package/packs/typescript-rules/rendered/AGENTS.md +893 -17
  90. package/packs/typescript-rules/rendered/CLAUDE.md +6 -0
  91. package/packs/typescript-rules/rendered/GEMINI.md +1335 -0
@@ -0,0 +1,431 @@
1
+ ---
2
+ name: database-migrations
3
+ description: Safe, reversible database schema-change patterns across PostgreSQL, MySQL, and common ORMs (Prisma, Drizzle, Kysely, Django, golang-migrate). Use when creating or altering tables, adding/removing columns or indexes, running data migrations, or planning zero-downtime schema changes.
4
+ license: MIT
5
+ ---
6
+
7
+ <!-- adapted from affaan-m/ECC (Everything Claude Code) (MIT) — https://github.com/affaan-m/ECC -->
8
+
9
+ # Database Migration Patterns
10
+
11
+ Safe, reversible database schema changes for production systems.
12
+
13
+ ## When to Activate
14
+
15
+ - Creating or altering database tables
16
+ - Adding/removing columns or indexes
17
+ - Running data migrations (backfill, transform)
18
+ - Planning zero-downtime schema changes
19
+ - Setting up migration tooling for a new project
20
+
21
+ ## Core Principles
22
+
23
+ 1. **Every change is a migration** — never alter production databases manually
24
+ 2. **Migrations are forward-only in production** — rollbacks use new forward migrations
25
+ 3. **Schema and data migrations are separate** — never mix DDL and DML in one migration
26
+ 4. **Test migrations against production-sized data** — a migration that works on 100 rows may lock on 10M
27
+ 5. **Migrations are immutable once deployed** — never edit a migration that has run in production
28
+
29
+ ## Migration Safety Checklist
30
+
31
+ Before applying any migration:
32
+
33
+ - [ ] Migration has both UP and DOWN (or is explicitly marked irreversible)
34
+ - [ ] No full table locks on large tables (use concurrent operations)
35
+ - [ ] New columns have defaults or are nullable (never add NOT NULL without default)
36
+ - [ ] Indexes created concurrently (not inline with CREATE TABLE for existing tables)
37
+ - [ ] Data backfill is a separate migration from schema change
38
+ - [ ] Tested against a copy of production data
39
+ - [ ] Rollback plan documented
40
+
41
+ ## PostgreSQL Patterns
42
+
43
+ ### Adding a Column Safely
44
+
45
+ ```sql
46
+ -- GOOD: Nullable column, no lock
47
+ ALTER TABLE users ADD COLUMN avatar_url TEXT;
48
+
49
+ -- GOOD: Column with default (Postgres 11+ is instant, no rewrite)
50
+ ALTER TABLE users ADD COLUMN is_active BOOLEAN NOT NULL DEFAULT true;
51
+
52
+ -- BAD: NOT NULL without default on existing table (requires full rewrite)
53
+ ALTER TABLE users ADD COLUMN role TEXT NOT NULL;
54
+ -- This locks the table and rewrites every row
55
+ ```
56
+
57
+ ### Adding an Index Without Downtime
58
+
59
+ ```sql
60
+ -- BAD: Blocks writes on large tables
61
+ CREATE INDEX idx_users_email ON users (email);
62
+
63
+ -- GOOD: Non-blocking, allows concurrent writes
64
+ CREATE INDEX CONCURRENTLY idx_users_email ON users (email);
65
+
66
+ -- Note: CONCURRENTLY cannot run inside a transaction block
67
+ -- Most migration tools need special handling for this
68
+ ```
69
+
70
+ ### Renaming a Column (Zero-Downtime)
71
+
72
+ Never rename directly in production. Use the expand-contract pattern:
73
+
74
+ ```sql
75
+ -- Step 1: Add new column (migration 001)
76
+ ALTER TABLE users ADD COLUMN display_name TEXT;
77
+
78
+ -- Step 2: Backfill data (migration 002, data migration)
79
+ UPDATE users SET display_name = username WHERE display_name IS NULL;
80
+
81
+ -- Step 3: Update application code to read/write both columns
82
+ -- Deploy application changes
83
+
84
+ -- Step 4: Stop writing to old column, drop it (migration 003)
85
+ ALTER TABLE users DROP COLUMN username;
86
+ ```
87
+
88
+ ### Removing a Column Safely
89
+
90
+ ```sql
91
+ -- Step 1: Remove all application references to the column
92
+ -- Step 2: Deploy application without the column reference
93
+ -- Step 3: Drop column in next migration
94
+ ALTER TABLE orders DROP COLUMN legacy_status;
95
+
96
+ -- For Django: use SeparateDatabaseAndState to remove from model
97
+ -- without generating DROP COLUMN (then drop in next migration)
98
+ ```
99
+
100
+ ### Large Data Migrations
101
+
102
+ ```sql
103
+ -- BAD: Updates all rows in one transaction (locks table)
104
+ UPDATE users SET normalized_email = LOWER(email);
105
+
106
+ -- GOOD: Batch update with progress
107
+ DO $$
108
+ DECLARE
109
+ batch_size INT := 10000;
110
+ rows_updated INT;
111
+ BEGIN
112
+ LOOP
113
+ UPDATE users
114
+ SET normalized_email = LOWER(email)
115
+ WHERE id IN (
116
+ SELECT id FROM users
117
+ WHERE normalized_email IS NULL
118
+ LIMIT batch_size
119
+ FOR UPDATE SKIP LOCKED
120
+ );
121
+ GET DIAGNOSTICS rows_updated = ROW_COUNT;
122
+ RAISE NOTICE 'Updated % rows', rows_updated;
123
+ EXIT WHEN rows_updated = 0;
124
+ COMMIT;
125
+ END LOOP;
126
+ END $$;
127
+ ```
128
+
129
+ ## Prisma (TypeScript/Node.js)
130
+
131
+ ### Workflow
132
+
133
+ ```bash
134
+ # Create migration from schema changes
135
+ npx prisma migrate dev --name add_user_avatar
136
+
137
+ # Apply pending migrations in production
138
+ npx prisma migrate deploy
139
+
140
+ # Reset database (dev only)
141
+ npx prisma migrate reset
142
+
143
+ # Generate client after schema changes
144
+ npx prisma generate
145
+ ```
146
+
147
+ ### Schema Example
148
+
149
+ ```prisma
150
+ model User {
151
+ id String @id @default(cuid())
152
+ email String @unique
153
+ name String?
154
+ avatarUrl String? @map("avatar_url")
155
+ createdAt DateTime @default(now()) @map("created_at")
156
+ updatedAt DateTime @updatedAt @map("updated_at")
157
+ orders Order[]
158
+
159
+ @@map("users")
160
+ @@index([email])
161
+ }
162
+ ```
163
+
164
+ ### Custom SQL Migration
165
+
166
+ For operations Prisma cannot express (concurrent indexes, data backfills):
167
+
168
+ ```bash
169
+ # Create empty migration, then edit the SQL manually
170
+ npx prisma migrate dev --create-only --name add_email_index
171
+ ```
172
+
173
+ ```sql
174
+ -- migrations/20240115_add_email_index/migration.sql
175
+ -- Prisma cannot generate CONCURRENTLY, so we write it manually
176
+ CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_users_email ON users (email);
177
+ ```
178
+
179
+ ## Drizzle (TypeScript/Node.js)
180
+
181
+ ### Workflow
182
+
183
+ ```bash
184
+ # Generate migration from schema changes
185
+ npx drizzle-kit generate
186
+
187
+ # Apply migrations
188
+ npx drizzle-kit migrate
189
+
190
+ # Push schema directly (dev only, no migration file)
191
+ npx drizzle-kit push
192
+ ```
193
+
194
+ ### Schema Example
195
+
196
+ ```typescript
197
+ import { pgTable, text, timestamp, uuid, boolean } from "drizzle-orm/pg-core";
198
+
199
+ export const users = pgTable("users", {
200
+ id: uuid("id").primaryKey().defaultRandom(),
201
+ email: text("email").notNull().unique(),
202
+ name: text("name"),
203
+ isActive: boolean("is_active").notNull().default(true),
204
+ createdAt: timestamp("created_at").notNull().defaultNow(),
205
+ updatedAt: timestamp("updated_at").notNull().defaultNow(),
206
+ });
207
+ ```
208
+
209
+ ## Kysely (TypeScript/Node.js)
210
+
211
+ ### Workflow (kysely-ctl)
212
+
213
+ ```bash
214
+ # Initialize config file (kysely.config.ts)
215
+ kysely init
216
+
217
+ # Create a new migration file
218
+ kysely migrate make add_user_avatar
219
+
220
+ # Apply all pending migrations
221
+ kysely migrate latest
222
+
223
+ # Rollback last migration
224
+ kysely migrate down
225
+
226
+ # Show migration status
227
+ kysely migrate list
228
+ ```
229
+
230
+ ### Migration File
231
+
232
+ ```typescript
233
+ // migrations/2024_01_15_001_create_user_profile.ts
234
+ import { type Kysely, sql } from 'kysely'
235
+
236
+ // IMPORTANT: Always use Kysely<any>, not your typed DB interface.
237
+ // Migrations are frozen in time and must not depend on current schema types.
238
+ export async function up(db: Kysely<any>): Promise<void> {
239
+ await db.schema
240
+ .createTable('user_profile')
241
+ .addColumn('id', 'serial', (col) => col.primaryKey())
242
+ .addColumn('email', 'varchar(255)', (col) => col.notNull().unique())
243
+ .addColumn('avatar_url', 'text')
244
+ .addColumn('created_at', 'timestamp', (col) =>
245
+ col.defaultTo(sql`now()`).notNull()
246
+ )
247
+ .execute()
248
+
249
+ await db.schema
250
+ .createIndex('idx_user_profile_avatar')
251
+ .on('user_profile')
252
+ .column('avatar_url')
253
+ .execute()
254
+ }
255
+
256
+ export async function down(db: Kysely<any>): Promise<void> {
257
+ await db.schema.dropTable('user_profile').execute()
258
+ }
259
+ ```
260
+
261
+ ### Programmatic Migrator
262
+
263
+ ```typescript
264
+ import { Migrator, FileMigrationProvider } from 'kysely'
265
+ import { promises as fs } from 'fs'
266
+ import * as path from 'path'
267
+ // ESM only — CJS can use __dirname directly
268
+ import { fileURLToPath } from 'url'
269
+ const migrationFolder = path.join(
270
+ path.dirname(fileURLToPath(import.meta.url)),
271
+ './migrations',
272
+ )
273
+
274
+ // `db` is your Kysely<any> database instance
275
+ const migrator = new Migrator({
276
+ db,
277
+ provider: new FileMigrationProvider({
278
+ fs,
279
+ path,
280
+ migrationFolder,
281
+ }),
282
+ // WARNING: Only enable in development. Disables timestamp-ordering
283
+ // validation, which can cause schema drift between environments.
284
+ // allowUnorderedMigrations: true,
285
+ })
286
+
287
+ const { error, results } = await migrator.migrateToLatest()
288
+
289
+ results?.forEach((it) => {
290
+ if (it.status === 'Success') {
291
+ console.log(`migration "${it.migrationName}" executed successfully`)
292
+ } else if (it.status === 'Error') {
293
+ console.error(`failed to execute migration "${it.migrationName}"`)
294
+ }
295
+ })
296
+
297
+ if (error) {
298
+ console.error('migration failed', error)
299
+ process.exit(1)
300
+ }
301
+ ```
302
+
303
+ ## Django (Python)
304
+
305
+ ### Workflow
306
+
307
+ ```bash
308
+ # Generate migration from model changes
309
+ python manage.py makemigrations
310
+
311
+ # Apply migrations
312
+ python manage.py migrate
313
+
314
+ # Show migration status
315
+ python manage.py showmigrations
316
+
317
+ # Generate empty migration for custom SQL
318
+ python manage.py makemigrations --empty app_name -n description
319
+ ```
320
+
321
+ ### Data Migration
322
+
323
+ ```python
324
+ from django.db import migrations
325
+
326
+ def backfill_display_names(apps, schema_editor):
327
+ User = apps.get_model("accounts", "User")
328
+ batch_size = 5000
329
+ users = User.objects.filter(display_name="")
330
+ while users.exists():
331
+ batch = list(users[:batch_size])
332
+ for user in batch:
333
+ user.display_name = user.username
334
+ User.objects.bulk_update(batch, ["display_name"], batch_size=batch_size)
335
+
336
+ def reverse_backfill(apps, schema_editor):
337
+ pass # Data migration, no reverse needed
338
+
339
+ class Migration(migrations.Migration):
340
+ dependencies = [("accounts", "0015_add_display_name")]
341
+
342
+ operations = [
343
+ migrations.RunPython(backfill_display_names, reverse_backfill),
344
+ ]
345
+ ```
346
+
347
+ ### SeparateDatabaseAndState
348
+
349
+ Remove a column from the Django model without dropping it from the database immediately:
350
+
351
+ ```python
352
+ class Migration(migrations.Migration):
353
+ operations = [
354
+ migrations.SeparateDatabaseAndState(
355
+ state_operations=[
356
+ migrations.RemoveField(model_name="user", name="legacy_field"),
357
+ ],
358
+ database_operations=[], # Don't touch the DB yet
359
+ ),
360
+ ]
361
+ ```
362
+
363
+ ## golang-migrate (Go)
364
+
365
+ ### Workflow
366
+
367
+ ```bash
368
+ # Create migration pair
369
+ migrate create -ext sql -dir migrations -seq add_user_avatar
370
+
371
+ # Apply all pending migrations
372
+ migrate -path migrations -database "$DATABASE_URL" up
373
+
374
+ # Rollback last migration
375
+ migrate -path migrations -database "$DATABASE_URL" down 1
376
+
377
+ # Force version (fix dirty state)
378
+ migrate -path migrations -database "$DATABASE_URL" force VERSION
379
+ ```
380
+
381
+ ### Migration Files
382
+
383
+ ```sql
384
+ -- migrations/000003_add_user_avatar.up.sql
385
+ ALTER TABLE users ADD COLUMN avatar_url TEXT;
386
+ CREATE INDEX CONCURRENTLY idx_users_avatar ON users (avatar_url) WHERE avatar_url IS NOT NULL;
387
+
388
+ -- migrations/000003_add_user_avatar.down.sql
389
+ DROP INDEX IF EXISTS idx_users_avatar;
390
+ ALTER TABLE users DROP COLUMN IF EXISTS avatar_url;
391
+ ```
392
+
393
+ ## Zero-Downtime Migration Strategy
394
+
395
+ For critical production changes, follow the expand-contract pattern:
396
+
397
+ ```
398
+ Phase 1: EXPAND
399
+ - Add new column/table (nullable or with default)
400
+ - Deploy: app writes to BOTH old and new
401
+ - Backfill existing data
402
+
403
+ Phase 2: MIGRATE
404
+ - Deploy: app reads from NEW, writes to BOTH
405
+ - Verify data consistency
406
+
407
+ Phase 3: CONTRACT
408
+ - Deploy: app only uses NEW
409
+ - Drop old column/table in separate migration
410
+ ```
411
+
412
+ ### Timeline Example
413
+
414
+ ```
415
+ Day 1: Migration adds new_status column (nullable)
416
+ Day 1: Deploy app v2 — writes to both status and new_status
417
+ Day 2: Run backfill migration for existing rows
418
+ Day 3: Deploy app v3 — reads from new_status only
419
+ Day 7: Migration drops old status column
420
+ ```
421
+
422
+ ## Anti-Patterns
423
+
424
+ | Anti-Pattern | Why It Fails | Better Approach |
425
+ |-------------|-------------|-----------------|
426
+ | Manual SQL in production | No audit trail, unrepeatable | Always use migration files |
427
+ | Editing deployed migrations | Causes drift between environments | Create new migration instead |
428
+ | NOT NULL without default | Locks table, rewrites all rows | Add nullable, backfill, then add constraint |
429
+ | Inline index on large table | Blocks writes during build | CREATE INDEX CONCURRENTLY |
430
+ | Schema + data in one migration | Hard to rollback, long transactions | Separate migrations |
431
+ | Dropping column before removing code | Application errors on missing column | Remove code first, drop column next deploy |