spb/note-spboucher-ai
Public
1CREATE TABLE "ai_comparisons" (2 "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,3 "workspace_id" uuid NOT NULL,4 "prompt" text NOT NULL,5 "models" jsonb NOT NULL,6 "results" jsonb DEFAULT '[]'::jsonb NOT NULL,7 "created_at" timestamp with time zone DEFAULT now() NOT NULL8);9--> statement-breakpoint10CREATE TABLE "ai_conversations" (11 "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,12 "workspace_id" uuid NOT NULL,13 "title" text DEFAULT 'New conversation' NOT NULL,14 "page_id" uuid,15 "model" text,16 "routing" text DEFAULT 'auto',17 "pinned" boolean DEFAULT false NOT NULL,18 "created_at" timestamp with time zone DEFAULT now() NOT NULL,19 "updated_at" timestamp with time zone DEFAULT now() NOT NULL,20 "deleted_at" timestamp with time zone21);22--> statement-breakpoint23CREATE TABLE "ai_executions" (24 "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,25 "workspace_id" uuid NOT NULL,26 "agent" text NOT NULL,27 "task" text NOT NULL,28 "model" text,29 "status" text DEFAULT 'pending' NOT NULL,30 "scopes" jsonb DEFAULT '[]'::jsonb NOT NULL,31 "tools_invoked" jsonb DEFAULT '[]'::jsonb,32 "documents_accessed" jsonb DEFAULT '[]'::jsonb,33 "proposed_changes" jsonb DEFAULT '[]'::jsonb,34 "approvals" jsonb DEFAULT '[]'::jsonb,35 "outcome" text,36 "result" text,37 "error" text,38 "cost_usd" double precision DEFAULT 0,39 "tokens_in" integer DEFAULT 0,40 "tokens_out" integer DEFAULT 0,41 "created_at" timestamp with time zone DEFAULT now() NOT NULL,42 "started_at" timestamp with time zone,43 "finished_at" timestamp with time zone44);45--> statement-breakpoint46CREATE TABLE "ai_messages" (47 "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,48 "conversation_id" uuid NOT NULL,49 "role" text NOT NULL,50 "content" text NOT NULL,51 "model" text,52 "provider" text,53 "sources" jsonb DEFAULT '[]'::jsonb,54 "usage" jsonb DEFAULT '{}'::jsonb,55 "cost_usd" double precision,56 "latency_ms" integer,57 "ttft_ms" integer,58 "meta" jsonb DEFAULT '{}'::jsonb,59 "created_at" timestamp with time zone DEFAULT now() NOT NULL60);61--> statement-breakpoint62CREATE TABLE "ai_models" (63 "id" text PRIMARY KEY NOT NULL,64 "provider" text NOT NULL,65 "display_name" text,66 "category" text DEFAULT 'text' NOT NULL,67 "available" boolean DEFAULT true NOT NULL,68 "enabled" boolean DEFAULT true NOT NULL,69 "context_window" integer,70 "max_output" integer,71 "input_price" double precision,72 "cached_price" double precision,73 "output_price" double precision,74 "pricing_source" text,75 "probes" jsonb DEFAULT '{}'::jsonb,76 "benchmark" jsonb DEFAULT '{}'::jsonb,77 "capabilities" jsonb DEFAULT '{}'::jsonb,78 "notes" jsonb DEFAULT '[]'::jsonb,79 "discovered_at" timestamp with time zone,80 "probed_at" timestamp with time zone,81 "benchmarked_at" timestamp with time zone,82 "created_at" timestamp with time zone DEFAULT now() NOT NULL,83 "updated_at" timestamp with time zone DEFAULT now() NOT NULL84);85--> statement-breakpoint86CREATE TABLE "ai_providers" (87 "id" text PRIMARY KEY NOT NULL,88 "name" text NOT NULL,89 "enabled" boolean DEFAULT true NOT NULL,90 "last_discovery_at" timestamp with time zone,91 "status" text DEFAULT 'unknown',92 "status_detail" text93);94--> statement-breakpoint95CREATE TABLE "ai_usage" (96 "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,97 "workspace_id" uuid,98 "provider" text NOT NULL,99 "model" text NOT NULL,100 "task" text NOT NULL,101 "input_tokens" integer DEFAULT 0 NOT NULL,102 "output_tokens" integer DEFAULT 0 NOT NULL,103 "cached_tokens" integer DEFAULT 0,104 "reasoning_tokens" integer DEFAULT 0,105 "cost_usd" double precision,106 "latency_ms" integer,107 "ttft_ms" integer,108 "ok" boolean DEFAULT true NOT NULL,109 "error" text,110 "ref_id" uuid,111 "created_at" timestamp with time zone DEFAULT now() NOT NULL112);113--> statement-breakpoint114CREATE TABLE "attachments" (115 "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,116 "workspace_id" uuid NOT NULL,117 "page_id" uuid,118 "filename" text NOT NULL,119 "mime" text NOT NULL,120 "size" bigint NOT NULL,121 "sha256" text NOT NULL,122 "storage_path" text NOT NULL,123 "extracted_text" text,124 "page_count" integer,125 "meta" jsonb DEFAULT '{}'::jsonb,126 "created_at" timestamp with time zone DEFAULT now() NOT NULL,127 "deleted_at" timestamp with time zone128);129--> statement-breakpoint130CREATE TABLE "audit_logs" (131 "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,132 "user_id" uuid,133 "action" text NOT NULL,134 "target_type" text,135 "target_id" text,136 "detail" jsonb DEFAULT '{}'::jsonb,137 "ip" text,138 "created_at" timestamp with time zone DEFAULT now() NOT NULL139);140--> statement-breakpoint141CREATE TABLE "backup_jobs" (142 "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,143 "kind" text DEFAULT 'full' NOT NULL,144 "status" text DEFAULT 'running' NOT NULL,145 "path" text,146 "size_bytes" bigint,147 "sha256" text,148 "offsite" boolean DEFAULT false,149 "error" text,150 "started_at" timestamp with time zone DEFAULT now() NOT NULL,151 "finished_at" timestamp with time zone152);153--> statement-breakpoint154CREATE TABLE "chunks" (155 "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,156 "workspace_id" uuid NOT NULL,157 "source_type" text NOT NULL,158 "source_id" uuid NOT NULL,159 "page_id" uuid,160 "ordinal" integer NOT NULL,161 "block_id" text,162 "heading" text,163 "content" text NOT NULL,164 "token_count" integer DEFAULT 0 NOT NULL,165 "content_hash" text NOT NULL,166 "tsv" "tsvector" GENERATED ALWAYS AS (to_tsvector('simple', coalesce(heading,'') || ' ' || content)) STORED,167 "created_at" timestamp with time zone DEFAULT now() NOT NULL168);169--> statement-breakpoint170CREATE TABLE "dashboard_layouts" (171 "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,172 "user_id" uuid NOT NULL,173 "name" text DEFAULT 'Home' NOT NULL,174 "widgets" jsonb DEFAULT '[]'::jsonb NOT NULL,175 "is_default" boolean DEFAULT true NOT NULL,176 "updated_at" timestamp with time zone DEFAULT now() NOT NULL177);178--> statement-breakpoint179CREATE TABLE "database_properties" (180 "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,181 "database_id" uuid NOT NULL,182 "name" text NOT NULL,183 "type" text NOT NULL,184 "config" jsonb DEFAULT '{}'::jsonb NOT NULL,185 "position" integer DEFAULT 0 NOT NULL,186 "width" integer DEFAULT 180,187 "created_at" timestamp with time zone DEFAULT now() NOT NULL188);189--> statement-breakpoint190CREATE TABLE "database_rows" (191 "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,192 "database_id" uuid NOT NULL,193 "page_id" uuid NOT NULL,194 "values" jsonb DEFAULT '{}'::jsonb NOT NULL,195 "position" double precision DEFAULT 0 NOT NULL,196 "created_at" timestamp with time zone DEFAULT now() NOT NULL,197 "updated_at" timestamp with time zone DEFAULT now() NOT NULL,198 "deleted_at" timestamp with time zone199);200--> statement-breakpoint201CREATE TABLE "database_views" (202 "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,203 "database_id" uuid NOT NULL,204 "name" text NOT NULL,205 "type" text DEFAULT 'table' NOT NULL,206 "config" jsonb DEFAULT '{}'::jsonb NOT NULL,207 "position" integer DEFAULT 0 NOT NULL,208 "is_default" boolean DEFAULT false NOT NULL,209 "created_at" timestamp with time zone DEFAULT now() NOT NULL210);211--> statement-breakpoint212CREATE TABLE "databases" (213 "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,214 "workspace_id" uuid NOT NULL,215 "page_id" uuid NOT NULL,216 "name" text NOT NULL,217 "description" text,218 "icon" text,219 "is_template" boolean DEFAULT false NOT NULL,220 "template_of" uuid,221 "created_at" timestamp with time zone DEFAULT now() NOT NULL,222 "updated_at" timestamp with time zone DEFAULT now() NOT NULL,223 "deleted_at" timestamp with time zone224);225--> statement-breakpoint226CREATE TABLE "embeddings" (227 "chunk_id" uuid PRIMARY KEY NOT NULL,228 "model" text NOT NULL,229 "version" integer DEFAULT 1 NOT NULL,230 "embedding" vector(1536) NOT NULL,231 "created_at" timestamp with time zone DEFAULT now() NOT NULL232);233--> statement-breakpoint234CREATE TABLE "experiments" (235 "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,236 "workspace_id" uuid NOT NULL,237 "page_id" uuid,238 "name" text NOT NULL,239 "status" text DEFAULT 'planned' NOT NULL,240 "params" jsonb DEFAULT '{}'::jsonb,241 "metrics" jsonb DEFAULT '{}'::jsonb,242 "dataset_ref" text,243 "repo_url" text,244 "notes" text,245 "started_at" timestamp with time zone,246 "finished_at" timestamp with time zone,247 "created_at" timestamp with time zone DEFAULT now() NOT NULL,248 "updated_at" timestamp with time zone DEFAULT now() NOT NULL249);250--> statement-breakpoint251CREATE TABLE "index_state" (252 "source_type" text NOT NULL,253 "source_id" uuid NOT NULL,254 "content_hash" text NOT NULL,255 "model" text NOT NULL,256 "version" integer DEFAULT 1 NOT NULL,257 "indexed_at" timestamp with time zone DEFAULT now() NOT NULL,258 CONSTRAINT "index_state_source_type_source_id_pk" PRIMARY KEY("source_type","source_id")259);260--> statement-breakpoint261CREATE TABLE "knowledge_edges" (262 "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,263 "workspace_id" uuid NOT NULL,264 "from_id" uuid NOT NULL,265 "to_id" uuid NOT NULL,266 "from_type" text DEFAULT 'page' NOT NULL,267 "to_type" text DEFAULT 'page' NOT NULL,268 "kind" text NOT NULL,269 "status" text DEFAULT 'accepted' NOT NULL,270 "confidence" double precision,271 "rationale" text,272 "model" text,273 "created_at" timestamp with time zone DEFAULT now() NOT NULL,274 "decided_at" timestamp with time zone275);276--> statement-breakpoint277CREATE TABLE "links" (278 "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,279 "from_page_id" uuid NOT NULL,280 "to_page_id" uuid NOT NULL,281 "kind" text DEFAULT 'link' NOT NULL,282 "created_at" timestamp with time zone DEFAULT now() NOT NULL283);284--> statement-breakpoint285CREATE TABLE "login_attempts" (286 "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,287 "ip" text NOT NULL,288 "username" text,289 "success" boolean NOT NULL,290 "created_at" timestamp with time zone DEFAULT now() NOT NULL291);292--> statement-breakpoint293CREATE TABLE "page_tags" (294 "page_id" uuid NOT NULL,295 "tag_id" uuid NOT NULL,296 CONSTRAINT "page_tags_page_id_tag_id_pk" PRIMARY KEY("page_id","tag_id")297);298--> statement-breakpoint299CREATE TABLE "page_versions" (300 "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,301 "page_id" uuid NOT NULL,302 "version" integer NOT NULL,303 "title" text NOT NULL,304 "content" jsonb NOT NULL,305 "properties" jsonb DEFAULT '{}'::jsonb,306 "reason" text DEFAULT 'autosave' NOT NULL,307 "created_at" timestamp with time zone DEFAULT now() NOT NULL,308 "word_count" integer DEFAULT 0309);310--> statement-breakpoint311CREATE TABLE "pages" (312 "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,313 "workspace_id" uuid NOT NULL,314 "parent_id" uuid,315 "database_id" uuid,316 "type" text DEFAULT 'page' NOT NULL,317 "section" text DEFAULT 'notes' NOT NULL,318 "title" text DEFAULT 'Untitled' NOT NULL,319 "icon" text,320 "cover" text,321 "content" jsonb DEFAULT '{"type":"doc","content":[]}'::jsonb NOT NULL,322 "plain_text" text DEFAULT '' NOT NULL,323 "tsv" "tsvector" GENERATED ALWAYS AS (setweight(to_tsvector('simple', coalesce(title,'')), 'A') || setweight(to_tsvector('simple', coalesce(plain_text,'')), 'B')) STORED,324 "properties" jsonb DEFAULT '{}'::jsonb NOT NULL,325 "position" double precision DEFAULT 0 NOT NULL,326 "pinned" boolean DEFAULT false NOT NULL,327 "archived" boolean DEFAULT false NOT NULL,328 "version" integer DEFAULT 1 NOT NULL,329 "word_count" integer DEFAULT 0 NOT NULL,330 "created_at" timestamp with time zone DEFAULT now() NOT NULL,331 "updated_at" timestamp with time zone DEFAULT now() NOT NULL,332 "last_opened_at" timestamp with time zone,333 "deleted_at" timestamp with time zone334);335--> statement-breakpoint336CREATE TABLE "relations" (337 "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,338 "property_id" uuid NOT NULL,339 "from_row_id" uuid NOT NULL,340 "to_row_id" uuid NOT NULL,341 "created_at" timestamp with time zone DEFAULT now() NOT NULL342);343--> statement-breakpoint344CREATE TABLE "references" (345 "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,346 "workspace_id" uuid NOT NULL,347 "page_id" uuid,348 "cite_key" text NOT NULL,349 "entry_type" text DEFAULT 'article' NOT NULL,350 "title" text NOT NULL,351 "authors" jsonb DEFAULT '[]'::jsonb,352 "year" integer,353 "journal" text,354 "doi" text,355 "url" text,356 "bibtex" text,357 "fields" jsonb DEFAULT '{}'::jsonb,358 "verified" text DEFAULT 'user' NOT NULL,359 "attachment_id" uuid,360 "created_at" timestamp with time zone DEFAULT now() NOT NULL,361 "updated_at" timestamp with time zone DEFAULT now() NOT NULL,362 "deleted_at" timestamp with time zone363);364--> statement-breakpoint365CREATE TABLE "sessions" (366 "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,367 "user_id" uuid NOT NULL,368 "token_hash" text NOT NULL,369 "user_agent" text,370 "ip" text,371 "created_at" timestamp with time zone DEFAULT now() NOT NULL,372 "last_seen_at" timestamp with time zone DEFAULT now() NOT NULL,373 "expires_at" timestamp with time zone NOT NULL,374 "absolute_expires_at" timestamp with time zone NOT NULL,375 "revoked_at" timestamp with time zone,376 "mfa_passed" boolean DEFAULT false NOT NULL,377 CONSTRAINT "sessions_token_hash_unique" UNIQUE("token_hash")378);379--> statement-breakpoint380CREATE TABLE "settings" (381 "key" text PRIMARY KEY NOT NULL,382 "value" jsonb NOT NULL,383 "updated_at" timestamp with time zone DEFAULT now() NOT NULL384);385--> statement-breakpoint386CREATE TABLE "tags" (387 "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,388 "workspace_id" uuid NOT NULL,389 "name" text NOT NULL,390 "color" text DEFAULT 'gray',391 "created_at" timestamp with time zone DEFAULT now() NOT NULL392);393--> statement-breakpoint394CREATE TABLE "tasks" (395 "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,396 "workspace_id" uuid NOT NULL,397 "page_id" uuid,398 "title" text NOT NULL,399 "status" text DEFAULT 'todo' NOT NULL,400 "priority" text DEFAULT 'medium',401 "due_at" timestamp with time zone,402 "completed_at" timestamp with time zone,403 "project" text,404 "created_at" timestamp with time zone DEFAULT now() NOT NULL,405 "updated_at" timestamp with time zone DEFAULT now() NOT NULL,406 "deleted_at" timestamp with time zone407);408--> statement-breakpoint409CREATE TABLE "users" (410 "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,411 "username" text NOT NULL,412 "display_name" text NOT NULL,413 "email" text,414 "password_hash" text NOT NULL,415 "totp_secret" text,416 "totp_enabled" boolean DEFAULT false NOT NULL,417 "preferences" jsonb DEFAULT '{}'::jsonb NOT NULL,418 "created_at" timestamp with time zone DEFAULT now() NOT NULL,419 "updated_at" timestamp with time zone DEFAULT now() NOT NULL,420 CONSTRAINT "users_username_unique" UNIQUE("username")421);422--> statement-breakpoint423CREATE TABLE "webauthn_challenges" (424 "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,425 "user_id" uuid,426 "challenge" text NOT NULL,427 "kind" text NOT NULL,428 "created_at" timestamp with time zone DEFAULT now() NOT NULL429);430--> statement-breakpoint431CREATE TABLE "webauthn_credentials" (432 "id" text PRIMARY KEY NOT NULL,433 "user_id" uuid NOT NULL,434 "public_key" text NOT NULL,435 "counter" bigint DEFAULT 0 NOT NULL,436 "transports" jsonb DEFAULT '[]'::jsonb,437 "device_type" text,438 "backed_up" boolean DEFAULT false,439 "label" text,440 "created_at" timestamp with time zone DEFAULT now() NOT NULL,441 "last_used_at" timestamp with time zone442);443--> statement-breakpoint444CREATE TABLE "workspaces" (445 "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,446 "owner_id" uuid NOT NULL,447 "name" text NOT NULL,448 "slug" text NOT NULL,449 "settings" jsonb DEFAULT '{}'::jsonb NOT NULL,450 "created_at" timestamp with time zone DEFAULT now() NOT NULL,451 "updated_at" timestamp with time zone DEFAULT now() NOT NULL,452 CONSTRAINT "workspaces_slug_unique" UNIQUE("slug")453);454--> statement-breakpoint455ALTER TABLE "ai_comparisons" ADD CONSTRAINT "ai_comparisons_workspace_id_workspaces_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspaces"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint456ALTER TABLE "ai_conversations" ADD CONSTRAINT "ai_conversations_workspace_id_workspaces_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspaces"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint457ALTER TABLE "ai_conversations" ADD CONSTRAINT "ai_conversations_page_id_pages_id_fk" FOREIGN KEY ("page_id") REFERENCES "public"."pages"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint458ALTER TABLE "ai_executions" ADD CONSTRAINT "ai_executions_workspace_id_workspaces_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspaces"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint459ALTER TABLE "ai_messages" ADD CONSTRAINT "ai_messages_conversation_id_ai_conversations_id_fk" FOREIGN KEY ("conversation_id") REFERENCES "public"."ai_conversations"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint460ALTER TABLE "ai_models" ADD CONSTRAINT "ai_models_provider_ai_providers_id_fk" FOREIGN KEY ("provider") REFERENCES "public"."ai_providers"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint461ALTER TABLE "attachments" ADD CONSTRAINT "attachments_workspace_id_workspaces_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspaces"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint462ALTER TABLE "attachments" ADD CONSTRAINT "attachments_page_id_pages_id_fk" FOREIGN KEY ("page_id") REFERENCES "public"."pages"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint463ALTER TABLE "chunks" ADD CONSTRAINT "chunks_workspace_id_workspaces_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspaces"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint464ALTER TABLE "dashboard_layouts" ADD CONSTRAINT "dashboard_layouts_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint465ALTER TABLE "database_properties" ADD CONSTRAINT "database_properties_database_id_databases_id_fk" FOREIGN KEY ("database_id") REFERENCES "public"."databases"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint466ALTER TABLE "database_rows" ADD CONSTRAINT "database_rows_database_id_databases_id_fk" FOREIGN KEY ("database_id") REFERENCES "public"."databases"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint467ALTER TABLE "database_rows" ADD CONSTRAINT "database_rows_page_id_pages_id_fk" FOREIGN KEY ("page_id") REFERENCES "public"."pages"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint468ALTER TABLE "database_views" ADD CONSTRAINT "database_views_database_id_databases_id_fk" FOREIGN KEY ("database_id") REFERENCES "public"."databases"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint469ALTER TABLE "databases" ADD CONSTRAINT "databases_workspace_id_workspaces_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspaces"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint470ALTER TABLE "databases" ADD CONSTRAINT "databases_page_id_pages_id_fk" FOREIGN KEY ("page_id") REFERENCES "public"."pages"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint471ALTER TABLE "embeddings" ADD CONSTRAINT "embeddings_chunk_id_chunks_id_fk" FOREIGN KEY ("chunk_id") REFERENCES "public"."chunks"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint472ALTER TABLE "experiments" ADD CONSTRAINT "experiments_workspace_id_workspaces_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspaces"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint473ALTER TABLE "experiments" ADD CONSTRAINT "experiments_page_id_pages_id_fk" FOREIGN KEY ("page_id") REFERENCES "public"."pages"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint474ALTER TABLE "knowledge_edges" ADD CONSTRAINT "knowledge_edges_workspace_id_workspaces_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspaces"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint475ALTER TABLE "links" ADD CONSTRAINT "links_from_page_id_pages_id_fk" FOREIGN KEY ("from_page_id") REFERENCES "public"."pages"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint476ALTER TABLE "links" ADD CONSTRAINT "links_to_page_id_pages_id_fk" FOREIGN KEY ("to_page_id") REFERENCES "public"."pages"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint477ALTER TABLE "page_tags" ADD CONSTRAINT "page_tags_page_id_pages_id_fk" FOREIGN KEY ("page_id") REFERENCES "public"."pages"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint478ALTER TABLE "page_tags" ADD CONSTRAINT "page_tags_tag_id_tags_id_fk" FOREIGN KEY ("tag_id") REFERENCES "public"."tags"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint479ALTER TABLE "page_versions" ADD CONSTRAINT "page_versions_page_id_pages_id_fk" FOREIGN KEY ("page_id") REFERENCES "public"."pages"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint480ALTER TABLE "pages" ADD CONSTRAINT "pages_workspace_id_workspaces_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspaces"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint481ALTER TABLE "relations" ADD CONSTRAINT "relations_property_id_database_properties_id_fk" FOREIGN KEY ("property_id") REFERENCES "public"."database_properties"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint482ALTER TABLE "relations" ADD CONSTRAINT "relations_from_row_id_database_rows_id_fk" FOREIGN KEY ("from_row_id") REFERENCES "public"."database_rows"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint483ALTER TABLE "relations" ADD CONSTRAINT "relations_to_row_id_database_rows_id_fk" FOREIGN KEY ("to_row_id") REFERENCES "public"."database_rows"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint484ALTER TABLE "references" ADD CONSTRAINT "references_workspace_id_workspaces_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspaces"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint485ALTER TABLE "references" ADD CONSTRAINT "references_page_id_pages_id_fk" FOREIGN KEY ("page_id") REFERENCES "public"."pages"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint486ALTER TABLE "references" ADD CONSTRAINT "references_attachment_id_attachments_id_fk" FOREIGN KEY ("attachment_id") REFERENCES "public"."attachments"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint487ALTER TABLE "sessions" ADD CONSTRAINT "sessions_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint488ALTER TABLE "tags" ADD CONSTRAINT "tags_workspace_id_workspaces_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspaces"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint489ALTER TABLE "tasks" ADD CONSTRAINT "tasks_workspace_id_workspaces_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspaces"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint490ALTER TABLE "tasks" ADD CONSTRAINT "tasks_page_id_pages_id_fk" FOREIGN KEY ("page_id") REFERENCES "public"."pages"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint491ALTER TABLE "webauthn_credentials" ADD CONSTRAINT "webauthn_credentials_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint492ALTER TABLE "workspaces" ADD CONSTRAINT "workspaces_owner_id_users_id_fk" FOREIGN KEY ("owner_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint493CREATE INDEX "ai_conv_ws_idx" ON "ai_conversations" USING btree ("workspace_id","updated_at");--> statement-breakpoint494CREATE INDEX "ai_exec_ws_idx" ON "ai_executions" USING btree ("workspace_id","created_at");--> statement-breakpoint495CREATE INDEX "ai_msgs_conv_idx" ON "ai_messages" USING btree ("conversation_id","created_at");--> statement-breakpoint496CREATE INDEX "ai_usage_created_idx" ON "ai_usage" USING btree ("created_at");--> statement-breakpoint497CREATE INDEX "attachments_page_idx" ON "attachments" USING btree ("page_id");--> statement-breakpoint498CREATE INDEX "attachments_sha_idx" ON "attachments" USING btree ("sha256");--> statement-breakpoint499CREATE INDEX "audit_created_idx" ON "audit_logs" USING btree ("created_at");--> statement-breakpoint500CREATE INDEX "chunks_source_idx" ON "chunks" USING btree ("source_type","source_id");--> statement-breakpoint501CREATE INDEX "chunks_tsv_idx" ON "chunks" USING gin ("tsv");--> statement-breakpoint502CREATE UNIQUE INDEX "chunks_unique" ON "chunks" USING btree ("source_type","source_id","ordinal");--> statement-breakpoint503CREATE INDEX "db_props_db_idx" ON "database_properties" USING btree ("database_id");--> statement-breakpoint504CREATE INDEX "db_rows_db_idx" ON "database_rows" USING btree ("database_id");--> statement-breakpoint505CREATE INDEX "db_rows_values_idx" ON "database_rows" USING gin ("values");--> statement-breakpoint506CREATE INDEX "embeddings_hnsw_idx" ON "embeddings" USING hnsw ("embedding" vector_cosine_ops);--> statement-breakpoint507CREATE UNIQUE INDEX "kedges_unique" ON "knowledge_edges" USING btree ("from_id","to_id","kind");--> statement-breakpoint508CREATE INDEX "kedges_ws_idx" ON "knowledge_edges" USING btree ("workspace_id","status");--> statement-breakpoint509CREATE UNIQUE INDEX "links_unique" ON "links" USING btree ("from_page_id","to_page_id","kind");--> statement-breakpoint510CREATE INDEX "links_to_idx" ON "links" USING btree ("to_page_id");--> statement-breakpoint511CREATE INDEX "login_attempts_ip_idx" ON "login_attempts" USING btree ("ip","created_at");--> statement-breakpoint512CREATE UNIQUE INDEX "page_versions_unique" ON "page_versions" USING btree ("page_id","version");--> statement-breakpoint513CREATE INDEX "pages_ws_parent_idx" ON "pages" USING btree ("workspace_id","parent_id");--> statement-breakpoint514CREATE INDEX "pages_tsv_idx" ON "pages" USING gin ("tsv");--> statement-breakpoint515CREATE INDEX "pages_updated_idx" ON "pages" USING btree ("updated_at");--> statement-breakpoint516CREATE INDEX "pages_db_idx" ON "pages" USING btree ("database_id");--> statement-breakpoint517CREATE INDEX "pages_title_trgm_idx" ON "pages" USING gin ("title" gin_trgm_ops);--> statement-breakpoint518CREATE UNIQUE INDEX "relations_unique" ON "relations" USING btree ("property_id","from_row_id","to_row_id");--> statement-breakpoint519CREATE INDEX "relations_to_idx" ON "relations" USING btree ("to_row_id");--> statement-breakpoint520CREATE UNIQUE INDEX "references_key_unique" ON "references" USING btree ("workspace_id","cite_key");--> statement-breakpoint521CREATE INDEX "sessions_user_idx" ON "sessions" USING btree ("user_id");--> statement-breakpoint522CREATE UNIQUE INDEX "tags_unique" ON "tags" USING btree ("workspace_id","name");--> statement-breakpoint523CREATE INDEX "tasks_due_idx" ON "tasks" USING btree ("due_at");