Skip to content

Commit

Permalink
🗃️ feat: 新增 thread db table 和模型
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Nov 6, 2024
1 parent bb4ab9c commit be0d4d9
Show file tree
Hide file tree
Showing 10 changed files with 3,815 additions and 3 deletions.
39 changes: 39 additions & 0 deletions src/database/server/migrations/0011_strange_blade.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
CREATE TABLE IF NOT EXISTS "threads" (
"id" text PRIMARY KEY NOT NULL,
"title" text,
"type" text NOT NULL,
"status" text DEFAULT 'active',
"topic_id" text NOT NULL,
"source_message_id" text NOT NULL,
"parent_thread_id" text,
"source_preview" text,
"user_id" text NOT NULL,
"last_active_at" timestamp with time zone DEFAULT now(),
"accessed_at" timestamp with time zone DEFAULT now() NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "threads" ADD CONSTRAINT "threads_topic_id_topics_id_fk" FOREIGN KEY ("topic_id") REFERENCES "public"."topics"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "threads" ADD CONSTRAINT "threads_source_message_id_messages_id_fk" FOREIGN KEY ("source_message_id") REFERENCES "public"."messages"("id") ON DELETE set null ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "threads" ADD CONSTRAINT "threads_parent_thread_id_threads_id_fk" FOREIGN KEY ("parent_thread_id") REFERENCES "public"."threads"("id") ON DELETE set null ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "threads" ADD CONSTRAINT "threads_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
Loading

0 comments on commit be0d4d9

Please sign in to comment.