serene-pub/drizzle/0000_stiff_puma.sql
2025-06-30 02:44:50 -07:00

265 lines
No EOL
16 KiB
SQL

CREATE TABLE "character_lore_entries" (
"id" integer PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY (sequence name "character_lore_entries_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
"lorebook_id" integer NOT NULL,
"character_binding_id" integer,
"name" text NOT NULL,
"keys" text DEFAULT '' NOT NULL,
"use_regex" boolean DEFAULT false,
"case_sensitive" boolean DEFAULT false NOT NULL,
"content" text DEFAULT '' NOT NULL,
"priority" integer DEFAULT 1 NOT NULL,
"constant" boolean DEFAULT false NOT NULL,
"enabled" boolean DEFAULT true NOT NULL,
"extra_json" json DEFAULT '{}'::json NOT NULL,
"created_at" date DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
"updated_at" date DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
"position" integer DEFAULT 0 NOT NULL
);
--> statement-breakpoint
CREATE TABLE "character_tags" (
"character_id" integer NOT NULL,
"tag_id" integer NOT NULL
);
--> statement-breakpoint
CREATE TABLE "characters" (
"id" integer PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY (sequence name "characters_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
"user_id" integer NOT NULL,
"name" text NOT NULL,
"nickname" text,
"character_version" text DEFAULT '1.0',
"description" text NOT NULL,
"personality" text,
"scenario" text,
"first_message" text,
"alternate_greetings" json DEFAULT '[]'::json NOT NULL,
"example_dialogues" text,
"metadata" json DEFAULT '{}'::json NOT NULL,
"avatar" text,
"creator_notes" text,
"creator_notes_multilingual" json,
"group_only_greetings" json,
"post_history_instructions" text,
"source" json DEFAULT '[]'::json NOT NULL,
"assets" json DEFAULT '[]'::json NOT NULL,
"created_at" date DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
"updated_at" date DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
"lorebook_id" integer,
"extensions" json DEFAULT '{}'::json NOT NULL,
"is_favorite" boolean DEFAULT false NOT NULL
);
--> statement-breakpoint
CREATE TABLE "chat_characters" (
"chat_id" integer NOT NULL,
"character_id" integer,
"position" integer DEFAULT 0,
"is_active" boolean NOT NULL
);
--> statement-breakpoint
CREATE TABLE "chat_lorebooks" (
"chat_id" integer NOT NULL,
"lorebook_id" integer NOT NULL,
"position" integer DEFAULT 0
);
--> statement-breakpoint
CREATE TABLE "chat_messages" (
"id" integer PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY (sequence name "chat_messages_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
"chat_id" integer NOT NULL,
"user_id" integer NOT NULL,
"character_id" integer,
"persona_id" integer,
"role" text,
"content" text NOT NULL,
"created_at" date DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
"updated_at" date DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
"is_edited" boolean DEFAULT false NOT NULL,
"metadata" json DEFAULT '{}'::json NOT NULL,
"is_generating" boolean DEFAULT false NOT NULL,
"adapter_id" text,
"is_hidden" boolean DEFAULT false NOT NULL
);
--> statement-breakpoint
CREATE TABLE "chat_personas" (
"chat_id" integer NOT NULL,
"persona_id" integer,
"position" integer DEFAULT 0
);
--> statement-breakpoint
CREATE TABLE "chats" (
"id" integer PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY (sequence name "chats_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
"name" text,
"is_group" boolean NOT NULL,
"user_id" integer NOT NULL,
"created_at" date DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
"updated_at" date DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
"scenario" text,
"metadata" text,
"group_reply_strategy" text DEFAULT 'ordered',
"lorebook_id" integer
);
--> statement-breakpoint
CREATE TABLE "connections" (
"id" integer PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY (sequence name "connections_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
"name" text NOT NULL,
"type" text NOT NULL,
"base_url" text,
"model" text,
"extra_json" json DEFAULT '{}'::json NOT NULL,
"token_counter" text DEFAULT 'estimate' NOT NULL,
"prompt_format" text DEFAULT 'vicuna'
);
--> statement-breakpoint
CREATE TABLE "context_configs" (
"id" integer PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY (sequence name "context_configs_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
"is_immutable" boolean DEFAULT false NOT NULL,
"name" text NOT NULL,
"template" text
);
--> statement-breakpoint
CREATE TABLE "history_entries" (
"id" integer PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY (sequence name "history_entries_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
"lorebook_id" integer NOT NULL,
"year" integer DEFAULT 1 NOT NULL,
"month" integer,
"day" integer,
"keys" text DEFAULT '' NOT NULL,
"use_regex" boolean DEFAULT false,
"case_sensitive" boolean DEFAULT false NOT NULL,
"content" text DEFAULT '' NOT NULL,
"constant" boolean DEFAULT false NOT NULL,
"enabled" boolean DEFAULT true NOT NULL,
"extra_json" json DEFAULT '{}'::json NOT NULL,
"created_at" date DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
"updated_at" date DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
"position" integer DEFAULT 0 NOT NULL
);
--> statement-breakpoint
CREATE TABLE "lorebook_bindings" (
"id" integer PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY (sequence name "lorebook_bindings_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
"lorebook_id" integer NOT NULL,
"character_id" integer,
"persona_id" integer,
"binding" text NOT NULL
);
--> statement-breakpoint
CREATE TABLE "lorebooks" (
"id" integer PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY (sequence name "lorebooks_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
"name" text NOT NULL,
"description" text DEFAULT '' NOT NULL,
"extra_json" json DEFAULT '{}'::json NOT NULL,
"user_id" integer NOT NULL,
"created_at" date DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
"updated_at" date DEFAULT (CURRENT_TIMESTAMP) NOT NULL
);
--> statement-breakpoint
CREATE TABLE "personas" (
"id" integer PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY (sequence name "personas_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
"user_id" integer NOT NULL,
"is_default" boolean NOT NULL,
"avatar" text,
"name" text NOT NULL,
"description" text NOT NULL,
"position" integer DEFAULT 0,
"created_at" date DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
"updated_at" date DEFAULT (CURRENT_TIMESTAMP),
"lorebook_id" integer
);
--> statement-breakpoint
CREATE TABLE "prompt_configs" (
"id" integer PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY (sequence name "prompt_configs_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
"is_immutable" boolean DEFAULT false NOT NULL,
"name" text NOT NULL,
"system_prompt" text NOT NULL
);
--> statement-breakpoint
CREATE TABLE "sampling_configs" (
"id" integer PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY (sequence name "sampling_configs_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
"name" text NOT NULL,
"is_immutable" boolean DEFAULT false NOT NULL,
"temperature" real DEFAULT 0.7 NOT NULL,
"temperature_enabled" boolean DEFAULT true NOT NULL,
"top_p" real DEFAULT 0.92,
"top_p_enabled" boolean DEFAULT false NOT NULL,
"top_k" integer DEFAULT 80,
"top_k_enabled" boolean DEFAULT false NOT NULL,
"repetition_penalty" real DEFAULT 1.15,
"repetition_penalty_enabled" boolean DEFAULT false NOT NULL,
"frequency_penalty" real DEFAULT 0.2,
"frequency_penalty_enabled" boolean DEFAULT false NOT NULL,
"presence_penalty" real DEFAULT 0.6,
"presence_penalty_enabled" boolean DEFAULT false NOT NULL,
"response_tokens" integer DEFAULT 512,
"response_tokens_enabled" boolean DEFAULT true NOT NULL,
"response_tokens_unlocked" boolean DEFAULT false NOT NULL,
"context_tokens" integer DEFAULT 4096,
"context_tokens_enabled" boolean DEFAULT true NOT NULL,
"context_tokens_unlocked" boolean DEFAULT false NOT NULL,
"seed" integer DEFAULT -1,
"seed_enabled" boolean DEFAULT false NOT NULL
);
--> statement-breakpoint
CREATE TABLE "tags" (
"id" integer PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY (sequence name "tags_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
"name" text NOT NULL,
"description" text
);
--> statement-breakpoint
CREATE TABLE "users" (
"id" integer PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY (sequence name "users_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
"username" text NOT NULL,
"active_connection_id" integer,
"active_sampling_id" integer,
"active_context_config_id" integer,
"active_prompt_config_id" integer
);
--> statement-breakpoint
CREATE TABLE "world_lore_entries" (
"id" integer PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY (sequence name "world_lore_entries_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
"lorebook_id" integer NOT NULL,
"name" text NOT NULL,
"category" text,
"keys" text DEFAULT '' NOT NULL,
"use_regex" boolean DEFAULT false,
"case_sensitive" boolean DEFAULT false NOT NULL,
"content" text DEFAULT '' NOT NULL,
"priority" integer DEFAULT 1 NOT NULL,
"constant" boolean DEFAULT false NOT NULL,
"enabled" boolean DEFAULT true NOT NULL,
"extra_json" json DEFAULT '{}'::json NOT NULL,
"created_at" date DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
"updated_at" date DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
"position" integer DEFAULT 0 NOT NULL
);
--> statement-breakpoint
ALTER TABLE "character_lore_entries" ADD CONSTRAINT "character_lore_entries_lorebook_id_lorebooks_id_fk" FOREIGN KEY ("lorebook_id") REFERENCES "public"."lorebooks"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "character_lore_entries" ADD CONSTRAINT "character_lore_entries_character_binding_id_lorebook_bindings_id_fk" FOREIGN KEY ("character_binding_id") REFERENCES "public"."lorebook_bindings"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "character_tags" ADD CONSTRAINT "character_tags_character_id_characters_id_fk" FOREIGN KEY ("character_id") REFERENCES "public"."characters"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "character_tags" ADD CONSTRAINT "character_tags_tag_id_tags_id_fk" FOREIGN KEY ("tag_id") REFERENCES "public"."tags"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "characters" ADD CONSTRAINT "characters_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "characters" ADD CONSTRAINT "characters_lorebook_id_lorebooks_id_fk" FOREIGN KEY ("lorebook_id") REFERENCES "public"."lorebooks"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "chat_characters" ADD CONSTRAINT "chat_characters_chat_id_chats_id_fk" FOREIGN KEY ("chat_id") REFERENCES "public"."chats"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "chat_characters" ADD CONSTRAINT "chat_characters_character_id_characters_id_fk" FOREIGN KEY ("character_id") REFERENCES "public"."characters"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "chat_lorebooks" ADD CONSTRAINT "chat_lorebooks_chat_id_chats_id_fk" FOREIGN KEY ("chat_id") REFERENCES "public"."chats"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "chat_lorebooks" ADD CONSTRAINT "chat_lorebooks_lorebook_id_lorebooks_id_fk" FOREIGN KEY ("lorebook_id") REFERENCES "public"."lorebooks"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "chat_messages" ADD CONSTRAINT "chat_messages_chat_id_chats_id_fk" FOREIGN KEY ("chat_id") REFERENCES "public"."chats"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "chat_messages" ADD CONSTRAINT "chat_messages_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "chat_messages" ADD CONSTRAINT "chat_messages_character_id_characters_id_fk" FOREIGN KEY ("character_id") REFERENCES "public"."characters"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "chat_messages" ADD CONSTRAINT "chat_messages_persona_id_personas_id_fk" FOREIGN KEY ("persona_id") REFERENCES "public"."personas"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "chat_personas" ADD CONSTRAINT "chat_personas_chat_id_chats_id_fk" FOREIGN KEY ("chat_id") REFERENCES "public"."chats"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "chat_personas" ADD CONSTRAINT "chat_personas_persona_id_personas_id_fk" FOREIGN KEY ("persona_id") REFERENCES "public"."personas"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "chats" ADD CONSTRAINT "chats_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "chats" ADD CONSTRAINT "chats_lorebook_id_lorebooks_id_fk" FOREIGN KEY ("lorebook_id") REFERENCES "public"."lorebooks"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "history_entries" ADD CONSTRAINT "history_entries_lorebook_id_lorebooks_id_fk" FOREIGN KEY ("lorebook_id") REFERENCES "public"."lorebooks"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "lorebook_bindings" ADD CONSTRAINT "lorebook_bindings_lorebook_id_lorebooks_id_fk" FOREIGN KEY ("lorebook_id") REFERENCES "public"."lorebooks"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "lorebook_bindings" ADD CONSTRAINT "lorebook_bindings_character_id_characters_id_fk" FOREIGN KEY ("character_id") REFERENCES "public"."characters"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "lorebook_bindings" ADD CONSTRAINT "lorebook_bindings_persona_id_personas_id_fk" FOREIGN KEY ("persona_id") REFERENCES "public"."personas"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "lorebooks" ADD CONSTRAINT "lorebooks_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "personas" ADD CONSTRAINT "personas_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "personas" ADD CONSTRAINT "personas_lorebook_id_lorebooks_id_fk" FOREIGN KEY ("lorebook_id") REFERENCES "public"."lorebooks"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "users" ADD CONSTRAINT "users_active_connection_id_connections_id_fk" FOREIGN KEY ("active_connection_id") REFERENCES "public"."connections"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "users" ADD CONSTRAINT "users_active_sampling_id_sampling_configs_id_fk" FOREIGN KEY ("active_sampling_id") REFERENCES "public"."sampling_configs"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "users" ADD CONSTRAINT "users_active_context_config_id_context_configs_id_fk" FOREIGN KEY ("active_context_config_id") REFERENCES "public"."context_configs"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "users" ADD CONSTRAINT "users_active_prompt_config_id_prompt_configs_id_fk" FOREIGN KEY ("active_prompt_config_id") REFERENCES "public"."prompt_configs"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "world_lore_entries" ADD CONSTRAINT "world_lore_entries_lorebook_id_lorebooks_id_fk" FOREIGN KEY ("lorebook_id") REFERENCES "public"."lorebooks"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
CREATE UNIQUE INDEX "chat_characters_pk" ON "chat_characters" USING btree ("chat_id","character_id");--> statement-breakpoint
CREATE UNIQUE INDEX "chat_personas_pk" ON "chat_personas" USING btree ("chat_id","persona_id");--> statement-breakpoint
CREATE UNIQUE INDEX "lorebook_bindings_unique" ON "lorebook_bindings" USING btree ("lorebook_id","character_id","persona_id");