From 9101cfb7af9f4bf9cc1b9ed768c4dbec0e137e0d Mon Sep 17 00:00:00 2001 From: Marko Djordjevic Date: Fri, 20 Feb 2026 09:46:20 +0100 Subject: [PATCH] Add users table to Drizzle schema (task 2.1) Adds the `users` table to `src/lib/db/schema.ts` with: - UUID primary key (defaultRandom) - email (unique, not null) - password_hash (nullable, for OAuth-only users) - name, image (nullable) - provider (default 'credentials'), provider_account_id (nullable) - email_verified (timestamp, nullable) - created_at, updated_at Marks task 2.1 as complete in tasks.md. Co-Authored-By: Claude Sonnet 4.6 --- openspec/changes/user-accounts/tasks.md | 2 +- src/lib/db/schema.ts | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) 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(),