first implementation
This commit is contained in:
33
backend/target/classes/db/migration/V1__initial_schema.sql
Normal file
33
backend/target/classes/db/migration/V1__initial_schema.sql
Normal file
@@ -0,0 +1,33 @@
|
||||
-- ============================================================
|
||||
-- V1: Initial schema
|
||||
-- Spring AI manages the vector_store table separately.
|
||||
-- ============================================================
|
||||
|
||||
CREATE TABLE IF NOT EXISTS book (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
title VARCHAR(500) NOT NULL,
|
||||
file_name VARCHAR(500) NOT NULL,
|
||||
file_size_bytes BIGINT NOT NULL,
|
||||
page_count INT,
|
||||
status VARCHAR(20) NOT NULL DEFAULT 'PENDING',
|
||||
error_message TEXT,
|
||||
uploaded_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
processed_at TIMESTAMPTZ
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS chat_session (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
topic_id VARCHAR(100),
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS message (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
session_id UUID NOT NULL REFERENCES chat_session(id) ON DELETE CASCADE,
|
||||
role VARCHAR(10) NOT NULL,
|
||||
content TEXT NOT NULL,
|
||||
sources JSONB,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_message_session ON message(session_id, created_at);
|
||||
17
backend/target/classes/db/migration/V2__pgvector_store.sql
Normal file
17
backend/target/classes/db/migration/V2__pgvector_store.sql
Normal file
@@ -0,0 +1,17 @@
|
||||
-- ============================================================
|
||||
-- V2: pgvector extension + Spring AI vector_store table
|
||||
-- Replaces Spring AI's initialize-schema=true (which requires
|
||||
-- CREATE SCHEMA privilege and fails on restricted users).
|
||||
-- ============================================================
|
||||
|
||||
CREATE EXTENSION IF NOT EXISTS vector;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS vector_store (
|
||||
id uuid DEFAULT gen_random_uuid() PRIMARY KEY,
|
||||
content text,
|
||||
metadata json,
|
||||
embedding vector(1536)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS spring_ai_vector_index
|
||||
ON vector_store USING hnsw (embedding vector_cosine_ops);
|
||||
Reference in New Issue
Block a user