-- ============================================================
|
-- H2 内存库建表脚本(仅 smoke profile 使用)
|
-- 与 sql/schema.sql 结构一致,差异点:
|
-- json -> varchar(H2 无 MySQL json 类型,应用层按字符串存取)
|
-- longtext -> clob
|
-- datetime -> timestamp
|
-- ============================================================
|
|
DROP TABLE IF EXISTS `user`;
|
CREATE TABLE `user` (
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
`username` varchar(64) NOT NULL,
|
`email` varchar(128) DEFAULT NULL,
|
`password_hash` varchar(256) NOT NULL,
|
`avatar` varchar(255) DEFAULT NULL,
|
`role` varchar(16) NOT NULL DEFAULT 'user',
|
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
PRIMARY KEY (`id`),
|
CONSTRAINT `uk_username` UNIQUE (`username`)
|
);
|
|
DROP TABLE IF EXISTS `chat`;
|
CREATE TABLE `chat` (
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
`user_id` bigint NOT NULL,
|
`title` varchar(255) NOT NULL DEFAULT '新对话',
|
`meta` varchar(4000) DEFAULT NULL,
|
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
PRIMARY KEY (`id`)
|
);
|
|
DROP TABLE IF EXISTS `message`;
|
CREATE TABLE `message` (
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
`chat_id` bigint NOT NULL,
|
`parent_id` bigint DEFAULT NULL,
|
`role` varchar(16) NOT NULL,
|
`content` clob NOT NULL,
|
`model` varchar(128) DEFAULT NULL,
|
`done` tinyint NOT NULL DEFAULT 0,
|
`metadata` varchar(4000) DEFAULT NULL,
|
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
PRIMARY KEY (`id`)
|
);
|
|
DROP TABLE IF EXISTS `upload_file`;
|
CREATE TABLE `upload_file` (
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
`user_id` bigint NOT NULL,
|
`chat_id` bigint DEFAULT NULL,
|
`filename` varchar(255) NOT NULL,
|
`save_path` varchar(512) NOT NULL,
|
`file_size` bigint NOT NULL,
|
`mime_type` varchar(128) DEFAULT NULL,
|
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
PRIMARY KEY (`id`)
|
);
|
|
DROP TABLE IF EXISTS `rag_collection`;
|
CREATE TABLE `rag_collection` (
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
`user_id` bigint NOT NULL,
|
`file_id` bigint NOT NULL,
|
`collection_name` varchar(128) NOT NULL,
|
`chunk_count` int NOT NULL DEFAULT 0,
|
`status` varchar(16) NOT NULL DEFAULT 'pending',
|
`message` varchar(512) DEFAULT NULL,
|
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
PRIMARY KEY (`id`),
|
CONSTRAINT `uk_file_collection` UNIQUE (`file_id`, `collection_name`)
|
);
|
|
DROP TABLE IF EXISTS `chat_collection`;
|
CREATE TABLE `chat_collection` (
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
`chat_id` bigint NOT NULL,
|
`collection_name` varchar(128) NOT NULL,
|
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
PRIMARY KEY (`id`),
|
CONSTRAINT `uk_chat_collection` UNIQUE (`chat_id`, `collection_name`)
|
);
|