CREATE TABLE "annotation_types" ( "id" serial PRIMARY KEY NOT NULL, "name" text NOT NULL, "display_name" text NOT NULL, "color" text NOT NULL, "category" text NOT NULL, "icon" text, "is_active" boolean DEFAULT true NOT NULL, "created_at" timestamp DEFAULT now() NOT NULL, CONSTRAINT "annotation_types_name_unique" UNIQUE("name") ); --> statement-breakpoint CREATE TABLE "annotations" ( "id" serial PRIMARY KEY NOT NULL, "chart_id" integer NOT NULL, "timestamp" timestamp NOT NULL, "label_type" text NOT NULL, "geometry" jsonb, "color" text DEFAULT '#3b82f6', "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "candles" ( "id" serial PRIMARY KEY NOT NULL, "chart_id" integer NOT NULL, "time" timestamp NOT NULL, "open" double precision NOT NULL, "high" double precision NOT NULL, "low" double precision NOT NULL, "close" double precision NOT NULL ); --> statement-breakpoint CREATE TABLE "charts" ( "id" serial PRIMARY KEY NOT NULL, "name" text NOT NULL, "created_at" timestamp DEFAULT now() NOT NULL, CONSTRAINT "charts_name_unique" UNIQUE("name") ); --> statement-breakpoint CREATE TABLE "span_annotations" ( "id" serial PRIMARY KEY NOT NULL, "chart_id" integer NOT NULL, "start_time" timestamp NOT NULL, "end_time" timestamp NOT NULL, "label" text NOT NULL, "confidence" integer, "outcome" text, "notes" text, "sub_spans" jsonb, "color" text DEFAULT '#2196F3' NOT NULL, "source" text DEFAULT 'human' NOT NULL, "model_prediction" jsonb, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "span_label_types" ( "id" serial PRIMARY KEY NOT NULL, "name" text NOT NULL, "display_name" text NOT NULL, "color" text NOT NULL, "hotkey" text, "is_active" boolean DEFAULT true NOT NULL, "sort_order" integer DEFAULT 0 NOT NULL, "created_at" timestamp DEFAULT now() NOT NULL, CONSTRAINT "span_label_types_name_unique" UNIQUE("name") ); --> statement-breakpoint ALTER TABLE "annotations" ADD CONSTRAINT "annotations_chart_id_charts_id_fk" FOREIGN KEY ("chart_id") REFERENCES "public"."charts"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "candles" ADD CONSTRAINT "candles_chart_id_charts_id_fk" FOREIGN KEY ("chart_id") REFERENCES "public"."charts"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "span_annotations" ADD CONSTRAINT "span_annotations_chart_id_charts_id_fk" FOREIGN KEY ("chart_id") REFERENCES "public"."charts"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint CREATE UNIQUE INDEX "candles_chart_time_unique" ON "candles" USING btree ("chart_id","time");