Настройки развертывания
This commit is contained in:
7
docker/postgres-init/00-example-extra-user.sql.example
Normal file
7
docker/postgres-init/00-example-extra-user.sql.example
Normal file
@@ -0,0 +1,7 @@
|
||||
-- Example: create an extra DB user (e.g. read-only). Not executed — rename to 00-create-extra-user.sql to enable.
|
||||
-- Scripts in this folder run in alphabetical order; 00-* runs before 01-schema.sql.
|
||||
|
||||
-- CREATE USER rag_readonly WITH PASSWORD 'change_me';
|
||||
-- GRANT CONNECT ON DATABASE rag TO rag_readonly;
|
||||
-- GRANT USAGE ON SCHEMA public TO rag_readonly;
|
||||
-- GRANT SELECT ON ALL TABLES IN SCHEMA public TO rag_readonly;
|
||||
32
docker/postgres-init/01-schema.sql
Normal file
32
docker/postgres-init/01-schema.sql
Normal file
@@ -0,0 +1,32 @@
|
||||
-- RAG vector DB schema (runs automatically on first Postgres init).
|
||||
-- If RAG_EMBEDDINGS_DIM is not 1536, change vector(1536) below.
|
||||
|
||||
CREATE EXTENSION IF NOT EXISTS vector;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS stories (
|
||||
id SERIAL PRIMARY KEY,
|
||||
slug TEXT UNIQUE NOT NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT (NOW() AT TIME ZONE 'utc')
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS documents (
|
||||
id SERIAL PRIMARY KEY,
|
||||
story_id INTEGER NOT NULL REFERENCES stories(id) ON DELETE CASCADE,
|
||||
path TEXT NOT NULL,
|
||||
version TEXT NOT NULL,
|
||||
updated_at TIMESTAMPTZ NOT NULL,
|
||||
UNIQUE(story_id, path)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS chunks (
|
||||
id SERIAL PRIMARY KEY,
|
||||
document_id INTEGER NOT NULL REFERENCES documents(id) ON DELETE CASCADE,
|
||||
chunk_index INTEGER NOT NULL,
|
||||
hash TEXT NOT NULL,
|
||||
content TEXT NOT NULL,
|
||||
embedding vector(1536) NOT NULL
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_documents_story_id ON documents(story_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_chunks_document_id ON chunks(document_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_chunks_embedding ON chunks USING ivfflat (embedding vector_cosine_ops);
|
||||
9
docker/postgres-init/README.md
Normal file
9
docker/postgres-init/README.md
Normal file
@@ -0,0 +1,9 @@
|
||||
# Postgres init scripts (optional)
|
||||
|
||||
Files here are mounted into the Postgres container at `/docker-entrypoint-initdb.d/` and run **only on first startup** (when the data volume is empty), in alphabetical order.
|
||||
|
||||
- `01-schema.sql` — creates pgvector extension and RAG tables (stories, documents, chunks).
|
||||
- To add more users or other setup, add scripts with names like `00-create-user.sql` (they run before `01-schema.sql`).
|
||||
- To disable init: in `docker-compose.yml`, comment out the postgres volume that mounts this folder, or remove/rename the `.sql` files.
|
||||
|
||||
After the first run, these scripts are not executed again. To re-run them, remove the volume: `docker compose down -v` (this deletes DB data), then `docker compose up -d`.
|
||||
Reference in New Issue
Block a user