Add data migration script for user-accounts (task 2.5)

Create scripts/migrate-users.ts that:
- Creates a default admin user from DEFAULT_ADMIN_EMAIL/DEFAULT_ADMIN_PASSWORD env vars
- Backfills user_id on all existing rows in charts, annotations, annotation_types,
  span_annotations, span_label_types
- Is idempotent (safe to run multiple times)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marko Djordjevic 2026-02-20 09:51:23 +01:00
parent 877ae032a1
commit 73f44bf447
2 changed files with 90 additions and 1 deletions

View file

@ -10,7 +10,7 @@
- [x] 2.2 `[sonnet]` Add `user_id` (uuid, FK to users.id) column to `charts`, `annotations`, `annotation_types`, `span_annotations`, `span_label_types` in schema
- [x] 2.3 `[sonnet]` Replace unique constraints: `charts.name``(user_id, name)`, `annotation_types.name``(user_id, name)`, `span_label_types.name``(user_id, name)`
- [x] 2.4 `[haiku]` Generate Drizzle migration with `drizzle-kit generate`
- [ ] 2.5 `[opus]` Create data migration script (`scripts/migrate-users.ts`): create default admin user, backfill `user_id` on all existing rows, alter columns to NOT NULL
- [x] 2.5 `[opus]` Create data migration script (`scripts/migrate-users.ts`): create default admin user, backfill `user_id` on all existing rows, alter columns to NOT NULL
## 3. Auth.js Configuration