From 633a76876f6befa7a16af70a070ba5bc9575cf9e Mon Sep 17 00:00:00 2001 From: Marko Djordjevic Date: Fri, 20 Feb 2026 09:47:30 +0100 Subject: [PATCH] Add user_id FK column to charts, annotations, annotation_types, span_annotations, span_label_types Adds nullable uuid user_id column referencing users.id to each of the 5 data tables. Column is nullable for now to allow the data migration script (task 2.5) to backfill existing rows before enforcing NOT NULL. Co-Authored-By: Claude Sonnet 4.6 --- src/lib/db/schema.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/lib/db/schema.ts b/src/lib/db/schema.ts index f40f57f..5aad160 100644 --- a/src/lib/db/schema.ts +++ b/src/lib/db/schema.ts @@ -15,6 +15,7 @@ export const users = pgTable('users', { export const charts = pgTable('charts', { id: serial('id').primaryKey(), + user_id: uuid('user_id').references(() => users.id), // nullable for now; will be NOT NULL after data migration (task 2.5) name: text('name').notNull().unique(), created_at: timestamp('created_at').notNull().defaultNow(), }); @@ -33,6 +34,7 @@ export const candles = pgTable('candles', { export const annotationTypes = pgTable('annotation_types', { id: serial('id').primaryKey(), + user_id: uuid('user_id').references(() => users.id), // nullable for now; will be NOT NULL after data migration (task 2.5) name: text('name').notNull().unique(), // internal name (e.g., 'break_up') display_name: text('display_name').notNull(), // display name (e.g., 'Break Up') color: text('color').notNull(), // hex color code @@ -44,6 +46,7 @@ export const annotationTypes = pgTable('annotation_types', { export const annotations = pgTable('annotations', { id: serial('id').primaryKey(), + user_id: uuid('user_id').references(() => users.id), // nullable for now; will be NOT NULL after data migration (task 2.5) chart_id: integer('chart_id').notNull().references(() => charts.id), timestamp: timestamp('timestamp').notNull(), label_type: text('label_type').notNull(), @@ -54,6 +57,7 @@ export const annotations = pgTable('annotations', { export const spanLabelTypes = pgTable('span_label_types', { id: serial('id').primaryKey(), + user_id: uuid('user_id').references(() => users.id), // nullable for now; will be NOT NULL after data migration (task 2.5) name: text('name').notNull().unique(), // internal name (e.g., 'bull_flag') display_name: text('display_name').notNull(), // UI label (e.g., 'Bull Flag') color: text('color').notNull(), // hex color for rectangle fill @@ -65,6 +69,7 @@ export const spanLabelTypes = pgTable('span_label_types', { export const spanAnnotations = pgTable('span_annotations', { id: serial('id').primaryKey(), + user_id: uuid('user_id').references(() => users.id), // nullable for now; will be NOT NULL after data migration (task 2.5) chart_id: integer('chart_id').notNull().references(() => charts.id), start_time: timestamp('start_time').notNull(), // timestamp of first candle end_time: timestamp('end_time').notNull(), // timestamp of last candle