mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-28 06:05:24 +00:00
61 lines
2.6 KiB
SQL
61 lines
2.6 KiB
SQL
-- ai 0001: adopt_ai_tables
|
|
-- Generated by termix-plugin migrations. Review before committing.
|
|
-- Hand-edited: keeps the legacy foreign key from messages and proposals to
|
|
-- their conversation, which the SDK cannot declare.
|
|
|
|
CREATE TABLE IF NOT EXISTS "ai_providers" (
|
|
"id" serial PRIMARY KEY,
|
|
"user_id" varchar(255) NOT NULL,
|
|
"provider_type" text NOT NULL,
|
|
"label" varchar(255) NOT NULL,
|
|
"base_url" text,
|
|
"api_key_prefix" text,
|
|
"default_model" text,
|
|
"enabled" boolean NOT NULL DEFAULT true,
|
|
"created_at" text NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
"updated_at" text NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE CASCADE
|
|
);
|
|
CREATE UNIQUE INDEX IF NOT EXISTS "idx_ai_providers_user_label" ON "ai_providers" ("user_id", "label");
|
|
ALTER TABLE "ai_providers" RENAME TO "p_ai_providers";
|
|
CREATE TABLE IF NOT EXISTS "ai_conversations" (
|
|
"id" serial PRIMARY KEY,
|
|
"user_id" varchar(255) NOT NULL,
|
|
"title" text,
|
|
"provider_id" integer,
|
|
"model" text,
|
|
"created_at" text NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
"updated_at" varchar(255) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE CASCADE
|
|
);
|
|
CREATE INDEX IF NOT EXISTS "idx_ai_conversations_user" ON "ai_conversations" ("user_id", "updated_at");
|
|
ALTER TABLE "ai_conversations" RENAME TO "p_ai_conversations";
|
|
CREATE TABLE IF NOT EXISTS "ai_messages" (
|
|
"id" serial PRIMARY KEY,
|
|
"conversation_id" integer NOT NULL,
|
|
"role" text NOT NULL,
|
|
"content" text NOT NULL DEFAULT '',
|
|
"tool_calls" text,
|
|
"created_at" varchar(255) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
FOREIGN KEY ("conversation_id") REFERENCES "p_ai_conversations" ("id") ON DELETE CASCADE
|
|
);
|
|
CREATE INDEX IF NOT EXISTS "idx_ai_messages_conversation" ON "ai_messages" ("conversation_id", "created_at");
|
|
ALTER TABLE "ai_messages" RENAME TO "p_ai_messages";
|
|
CREATE TABLE IF NOT EXISTS "ai_proposals" (
|
|
"id" serial PRIMARY KEY,
|
|
"conversation_id" integer NOT NULL,
|
|
"user_id" varchar(255) NOT NULL,
|
|
"kind" varchar(255) NOT NULL,
|
|
"summary" text,
|
|
"payload" text NOT NULL DEFAULT '{}',
|
|
"status" varchar(32) NOT NULL DEFAULT 'pending',
|
|
"applied_at" text,
|
|
"result_summary" text,
|
|
"created_at" text NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE CASCADE,
|
|
FOREIGN KEY ("conversation_id") REFERENCES "p_ai_conversations" ("id") ON DELETE CASCADE
|
|
);
|
|
CREATE INDEX IF NOT EXISTS "idx_ai_proposals_user" ON "ai_proposals" ("user_id", "status");
|
|
CREATE INDEX IF NOT EXISTS "idx_ai_proposals_conversation" ON "ai_proposals" ("conversation_id");
|
|
ALTER TABLE "ai_proposals" RENAME TO "p_ai_proposals";
|