mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-28 22:25:24 +00:00
56 lines
2.2 KiB
SQL
56 lines
2.2 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` int AUTO_INCREMENT 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
|
|
);
|
|
RENAME TABLE `ai_providers` TO `p_ai_providers`;
|
|
CREATE TABLE IF NOT EXISTS `ai_conversations` (
|
|
`id` int AUTO_INCREMENT PRIMARY KEY,
|
|
`user_id` varchar(255) NOT NULL,
|
|
`title` text,
|
|
`provider_id` int,
|
|
`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
|
|
);
|
|
RENAME TABLE `ai_conversations` TO `p_ai_conversations`;
|
|
CREATE TABLE IF NOT EXISTS `ai_messages` (
|
|
`id` int AUTO_INCREMENT PRIMARY KEY,
|
|
`conversation_id` int 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
|
|
);
|
|
RENAME TABLE `ai_messages` TO `p_ai_messages`;
|
|
CREATE TABLE IF NOT EXISTS `ai_proposals` (
|
|
`id` int AUTO_INCREMENT PRIMARY KEY,
|
|
`conversation_id` int 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
|
|
);
|
|
RENAME TABLE `ai_proposals` TO `p_ai_proposals`;
|