mirror of
https://github.com/moeru-ai/airi.git
synced 2026-05-19 08:10:45 +00:00
231 lines
No EOL
9.8 KiB
SQL
231 lines
No EOL
9.8 KiB
SQL
CREATE TABLE "account" (
|
|
"id" text PRIMARY KEY NOT NULL,
|
|
"account_id" text NOT NULL,
|
|
"provider_id" text NOT NULL,
|
|
"user_id" text NOT NULL,
|
|
"access_token" text,
|
|
"refresh_token" text,
|
|
"id_token" text,
|
|
"access_token_expires_at" timestamp,
|
|
"refresh_token_expires_at" timestamp,
|
|
"scope" text,
|
|
"password" text,
|
|
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
"updated_at" timestamp NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "session" (
|
|
"id" text PRIMARY KEY NOT NULL,
|
|
"expires_at" timestamp NOT NULL,
|
|
"token" text NOT NULL,
|
|
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
"updated_at" timestamp NOT NULL,
|
|
"ip_address" text,
|
|
"user_agent" text,
|
|
"user_id" text NOT NULL,
|
|
CONSTRAINT "session_token_unique" UNIQUE("token")
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "user" (
|
|
"id" text PRIMARY KEY NOT NULL,
|
|
"name" text NOT NULL,
|
|
"email" text NOT NULL,
|
|
"email_verified" boolean DEFAULT false NOT NULL,
|
|
"image" text,
|
|
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
"updated_at" timestamp DEFAULT now() NOT NULL,
|
|
CONSTRAINT "user_email_unique" UNIQUE("email")
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "verification" (
|
|
"id" text PRIMARY KEY NOT NULL,
|
|
"identifier" text NOT NULL,
|
|
"value" text NOT NULL,
|
|
"expires_at" timestamp NOT NULL,
|
|
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
"updated_at" timestamp DEFAULT now() NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "avatar_model" (
|
|
"id" text PRIMARY KEY NOT NULL,
|
|
"character_id" text NOT NULL,
|
|
"name" text NOT NULL,
|
|
"type" text NOT NULL,
|
|
"description" text NOT NULL,
|
|
"config" jsonb NOT NULL,
|
|
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
"updated_at" timestamp DEFAULT now() NOT NULL,
|
|
"deleted_at" timestamp
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "characters" (
|
|
"id" text PRIMARY KEY NOT NULL,
|
|
"version" text NOT NULL,
|
|
"cover_url" text NOT NULL,
|
|
"creator_id" text NOT NULL,
|
|
"owner_id" text NOT NULL,
|
|
"character_id" text NOT NULL,
|
|
"avatar_url" text,
|
|
"creator_role" text,
|
|
"price_credit" text DEFAULT '0' NOT NULL,
|
|
"likes_count" integer DEFAULT 0 NOT NULL,
|
|
"bookmarks_count" integer DEFAULT 0 NOT NULL,
|
|
"interactions_count" integer DEFAULT 0 NOT NULL,
|
|
"forks_count" integer DEFAULT 0 NOT NULL,
|
|
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
"updated_at" timestamp DEFAULT now() NOT NULL,
|
|
"deleted_at" timestamp
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "character_capabilities" (
|
|
"id" text PRIMARY KEY NOT NULL,
|
|
"character_id" text NOT NULL,
|
|
"type" text NOT NULL,
|
|
"config" jsonb NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "character_covers" (
|
|
"id" text PRIMARY KEY NOT NULL,
|
|
"character_id" text NOT NULL,
|
|
"foreground_url" text NOT NULL,
|
|
"background_url" text NOT NULL,
|
|
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
"updated_at" timestamp DEFAULT now() NOT NULL,
|
|
"deleted_at" timestamp
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "character_i18n" (
|
|
"id" text PRIMARY KEY NOT NULL,
|
|
"character_id" text NOT NULL,
|
|
"language" text NOT NULL,
|
|
"name" text NOT NULL,
|
|
"tagline" text,
|
|
"description" text NOT NULL,
|
|
"tags" text[] NOT NULL,
|
|
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
"updated_at" timestamp DEFAULT now() NOT NULL,
|
|
"deleted_at" timestamp
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "character_prompts" (
|
|
"id" text PRIMARY KEY NOT NULL,
|
|
"character_id" text NOT NULL,
|
|
"language" text NOT NULL,
|
|
"type" text NOT NULL,
|
|
"content" text NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "chat_members" (
|
|
"id" text PRIMARY KEY NOT NULL,
|
|
"chat_id" text NOT NULL,
|
|
"member_type" text NOT NULL,
|
|
"user_id" text,
|
|
"character_id" text
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "chats" (
|
|
"id" text PRIMARY KEY NOT NULL,
|
|
"type" text NOT NULL,
|
|
"title" text,
|
|
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
"updated_at" timestamp DEFAULT now() NOT NULL,
|
|
"deleted_at" timestamp
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "media" (
|
|
"id" text PRIMARY KEY NOT NULL,
|
|
"url" text NOT NULL,
|
|
"mime_type" text NOT NULL,
|
|
"size" integer NOT NULL,
|
|
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
"updated_at" timestamp DEFAULT now() NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "messages" (
|
|
"id" text PRIMARY KEY NOT NULL,
|
|
"chat_id" text NOT NULL,
|
|
"sender_id" text NOT NULL,
|
|
"role" text NOT NULL,
|
|
"content" text NOT NULL,
|
|
"media_ids" text[] NOT NULL,
|
|
"sticker_ids" text[] NOT NULL,
|
|
"reply_message_id" text,
|
|
"forward_from_message_id" text,
|
|
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
"updated_at" timestamp DEFAULT now() NOT NULL,
|
|
"deleted_at" timestamp
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "sticker_packs" (
|
|
"id" text PRIMARY KEY NOT NULL,
|
|
"name" text NOT NULL,
|
|
"description" text NOT NULL,
|
|
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
"updated_at" timestamp DEFAULT now() NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "stickers" (
|
|
"id" text PRIMARY KEY NOT NULL,
|
|
"url" text NOT NULL,
|
|
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
"updated_at" timestamp DEFAULT now() NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "system_provider_configs" (
|
|
"id" text PRIMARY KEY NOT NULL,
|
|
"definition_id" text NOT NULL,
|
|
"name" text NOT NULL,
|
|
"config" jsonb DEFAULT '{}'::jsonb NOT NULL,
|
|
"validated" boolean DEFAULT false NOT NULL,
|
|
"validation_bypassed" boolean DEFAULT false NOT NULL,
|
|
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
"updated_at" timestamp DEFAULT now() NOT NULL,
|
|
"deleted_at" timestamp
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "user_provider_configs" (
|
|
"id" text PRIMARY KEY NOT NULL,
|
|
"owner_id" text NOT NULL,
|
|
"definition_id" text NOT NULL,
|
|
"name" text NOT NULL,
|
|
"config" jsonb DEFAULT '{}'::jsonb NOT NULL,
|
|
"validated" boolean DEFAULT false NOT NULL,
|
|
"validation_bypassed" boolean DEFAULT false NOT NULL,
|
|
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
"updated_at" timestamp DEFAULT now() NOT NULL,
|
|
"deleted_at" timestamp
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "user_character_bookmarks" (
|
|
"user_id" text NOT NULL,
|
|
"character_id" text NOT NULL,
|
|
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
CONSTRAINT "user_character_bookmarks_user_id_character_id_pk" PRIMARY KEY("user_id","character_id")
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "user_character_likes" (
|
|
"user_id" text NOT NULL,
|
|
"character_id" text NOT NULL,
|
|
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
CONSTRAINT "user_character_likes_user_id_character_id_pk" PRIMARY KEY("user_id","character_id")
|
|
);
|
|
--> statement-breakpoint
|
|
ALTER TABLE "account" ADD CONSTRAINT "account_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE "session" ADD CONSTRAINT "session_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE "avatar_model" ADD CONSTRAINT "avatar_model_character_id_characters_id_fk" FOREIGN KEY ("character_id") REFERENCES "public"."characters"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE "characters" ADD CONSTRAINT "characters_creator_id_user_id_fk" FOREIGN KEY ("creator_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE "characters" ADD CONSTRAINT "characters_owner_id_user_id_fk" FOREIGN KEY ("owner_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE "character_capabilities" ADD CONSTRAINT "character_capabilities_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_covers" ADD CONSTRAINT "character_covers_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_i18n" ADD CONSTRAINT "character_i18n_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_prompts" ADD CONSTRAINT "character_prompts_character_id_characters_id_fk" FOREIGN KEY ("character_id") REFERENCES "public"."characters"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE "chat_members" ADD CONSTRAINT "chat_members_chat_id_chats_id_fk" FOREIGN KEY ("chat_id") REFERENCES "public"."chats"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE "messages" ADD CONSTRAINT "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 "user_provider_configs" ADD CONSTRAINT "user_provider_configs_owner_id_user_id_fk" FOREIGN KEY ("owner_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE "user_character_bookmarks" ADD CONSTRAINT "user_character_bookmarks_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE "user_character_bookmarks" ADD CONSTRAINT "user_character_bookmarks_character_id_characters_id_fk" FOREIGN KEY ("character_id") REFERENCES "public"."characters"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE "user_character_likes" ADD CONSTRAINT "user_character_likes_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE "user_character_likes" ADD CONSTRAINT "user_character_likes_character_id_characters_id_fk" FOREIGN KEY ("character_id") REFERENCES "public"."characters"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
CREATE INDEX "account_userId_idx" ON "account" USING btree ("user_id");--> statement-breakpoint
|
|
CREATE INDEX "session_userId_idx" ON "session" USING btree ("user_id");--> statement-breakpoint
|
|
CREATE INDEX "verification_identifier_idx" ON "verification" USING btree ("identifier"); |