Skip to content

Commit c8ad2fd

Browse files
committed
instructions about new columns
1 parent 6291c45 commit c8ad2fd

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

.claude/rules/database-safety.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ paths:
77

88
- When adding indexes to **existing tables**, use `CREATE INDEX CONCURRENTLY IF NOT EXISTS` to avoid table locks. These must be in their own separate migration file (one index per file).
99
- Indexes on **newly created tables** (same migration as `CREATE TABLE`) do not need CONCURRENTLY.
10+
- When indexing a **new column on an existing table**, split into two migrations: first `ADD COLUMN IF NOT EXISTS`, then `CREATE INDEX CONCURRENTLY IF NOT EXISTS` in a separate file.
1011
- After generating a migration with Prisma, remove extraneous lines for: `_BackgroundWorkerToBackgroundWorkerFile`, `_BackgroundWorkerToTaskQueue`, `_TaskRunToTaskRunTag`, `_WaitpointRunConnections`, `_completedWaitpoints`, `SecretStore_key_idx`, and unrelated TaskRun indexes.
1112
- Never drop columns or tables without explicit approval.
1213
- New code should target `RunEngineVersion.V2` only.

internal-packages/database/CLAUDE.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ When adding indexes to **existing tables**:
4949

5050
Indexes on **newly created tables** (in the same migration as `CREATE TABLE`) do not need CONCURRENTLY and can be in the same migration file.
5151

52+
When adding an index on a **new column on an existing table**, use two migrations:
53+
1. First migration: `ALTER TABLE ... ADD COLUMN IF NOT EXISTS ...` (the column)
54+
2. Second migration: `CREATE INDEX CONCURRENTLY IF NOT EXISTS ...` (the index, in its own file)
55+
5256
See `README.md` in this directory and `ai/references/migrations.md` for the full index workflow.
5357

5458
## Read Replicas

0 commit comments

Comments
 (0)