diff --git a/openspec/changes/user-accounts/tasks.md b/openspec/changes/user-accounts/tasks.md index 7f3d668..13a6493 100644 --- a/openspec/changes/user-accounts/tasks.md +++ b/openspec/changes/user-accounts/tasks.md @@ -6,7 +6,7 @@ ## 2. Database Schema & Migration -- [ ] 2.1 `[sonnet]` Add `users` table to Drizzle schema (`src/lib/db/schema.ts`) with UUID PK, email, password_hash, name, image, provider, provider_account_id, email_verified, created_at, updated_at +- [x] 2.1 `[sonnet]` Add `users` table to Drizzle schema (`src/lib/db/schema.ts`) with UUID PK, email, password_hash, name, image, provider, provider_account_id, email_verified, created_at, updated_at - [ ] 2.2 `[sonnet]` Add `user_id` (uuid, FK to users.id) column to `charts`, `annotations`, `annotation_types`, `span_annotations`, `span_label_types` in schema - [ ] 2.3 `[sonnet]` Replace unique constraints: `charts.name` → `(user_id, name)`, `annotation_types.name` → `(user_id, name)`, `span_label_types.name` → `(user_id, name)` - [ ] 2.4 `[haiku]` Generate Drizzle migration with `drizzle-kit generate` diff --git a/src/lib/db/schema.ts b/src/lib/db/schema.ts index c4b1a88..f40f57f 100644 --- a/src/lib/db/schema.ts +++ b/src/lib/db/schema.ts @@ -1,4 +1,17 @@ -import { pgTable, serial, text, timestamp, doublePrecision, integer, boolean, jsonb, uniqueIndex } from 'drizzle-orm/pg-core'; +import { pgTable, serial, text, timestamp, doublePrecision, integer, boolean, jsonb, uniqueIndex, uuid } from 'drizzle-orm/pg-core'; + +export const users = pgTable('users', { + id: uuid('id').primaryKey().defaultRandom(), + email: text('email').notNull().unique(), + password_hash: text('password_hash'), // null for OAuth-only users + name: text('name'), + image: text('image'), + provider: text('provider').notNull().default('credentials'), // 'credentials' | 'google' + provider_account_id: text('provider_account_id'), // Google sub ID + email_verified: timestamp('email_verified'), // nullable — set when email is verified + created_at: timestamp('created_at').notNull().defaultNow(), + updated_at: timestamp('updated_at').notNull().defaultNow(), +}); export const charts = pgTable('charts', { id: serial('id').primaryKey(),