Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion db/.env.template
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Database connection
DATABASE_URL=postgresql://docs:password@localhost:5432/docs_bot
DATABASE_URL=postgresql://docs:password@localhost:5432/pql-bot

# OpenAI API for embeddings
OPENAI_API_KEY=
Expand Down
8 changes: 4 additions & 4 deletions db/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ bun run db:generate-seed-migration ../promptql-docs/docs

## Database Schema

### `docs_bot.doc_content`
### `pql-bot.doc_content`

- Full documentation pages with metadata
- Stores title, description, keywords, and raw content
- Links to chunked embeddings via foreign key

### `docs_bot.doc_chunk`
### `pql-bot.doc_chunk`

- 500-character content chunks with embeddings
- 1536-dimensional vectors from OpenAI
Expand Down Expand Up @@ -69,8 +69,8 @@ bun run db:down && bun run db:up
sleep 5 && bun run db:migrate

# Connect and explore
# JDBC: jdbc:postgresql://local.hasura.dev:5432/docs_bot?user=docs&password=password
psql postgresql://docs:password@local.hasura.dev:5432/docs_bot
# JDBC: jdbc:postgresql://local.hasura.dev:5432/pql-bot?user=docs&password=password
psql postgresql://docs:password@local.hasura.dev:5432/pql-bot
```

### Production Deployment
Expand Down
4 changes: 2 additions & 2 deletions db/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ services:
postgres:
image: pgvector/pgvector:pg16
environment:
POSTGRES_DB: docs_bot
POSTGRES_DB: pql-bot
POSTGRES_USER: docs
POSTGRES_PASSWORD: password
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U docs -d docs_bot"]
test: ["CMD-SHELL", "pg_isready -U docs -d pql-bot"]
interval: 5s
timeout: 5s
retries: 5
Expand Down
8 changes: 4 additions & 4 deletions db/generate-seed-migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async function generateSeedMigration() {

// Export as INSERT statements
const result = await pool.query(`
SELECT 'INSERT INTO docs_bot.doc_content (id, page_url, title, description, keywords, content, is_checked, created_at, updated_at) VALUES (' ||
SELECT 'INSERT INTO pql-bot.doc_content (id, page_url, title, description, keywords, content, is_checked, created_at, updated_at) VALUES (' ||
quote_literal(id::text) || ', ' ||
quote_literal(page_url) || ', ' ||
quote_literal(title) || ', ' ||
Expand All @@ -24,9 +24,9 @@ async function generateSeedMigration() {
is_checked || ', ' ||
quote_literal(created_at::text) || ', ' ||
quote_literal(updated_at::text) || ');' as sql
FROM docs_bot.doc_content
FROM pql-bot.doc_content
UNION ALL
SELECT 'INSERT INTO docs_bot.doc_chunk (id, doc_content_id_fk, chunk_content, page_title, page_url, chunk_line_start, chunk_line_end, embedding, created_at, updated_at) VALUES (' ||
SELECT 'INSERT INTO pql-bot.doc_chunk (id, doc_content_id_fk, chunk_content, page_title, page_url, chunk_line_start, chunk_line_end, embedding, created_at, updated_at) VALUES (' ||
quote_literal(id::text) || ', ' ||
quote_literal(doc_content_id_fk::text) || ', ' ||
quote_literal(chunk_content) || ', ' ||
Expand All @@ -37,7 +37,7 @@ async function generateSeedMigration() {
quote_literal(embedding::text) || ', ' ||
quote_literal(created_at::text) || ', ' ||
quote_literal(updated_at::text) || ');'
FROM docs_bot.doc_chunk
FROM pql-bot.doc_chunk
`);

const migration = result.rows.map((row) => row.sql).join("\n");
Expand Down
4 changes: 2 additions & 2 deletions db/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async function processDocFile(filePath: string, docsRoot: string) {
// Insert doc_content
const contentResult = await pool.query(
`
INSERT INTO docs_bot.doc_content (page_url, title, description, keywords, content, is_checked)
INSERT INTO pql-bot.doc_content (page_url, title, description, keywords, content, is_checked)
VALUES ($1, $2, $3, $4, $5, true) RETURNING id
`,
[
Expand All @@ -61,7 +61,7 @@ async function processDocFile(filePath: string, docsRoot: string) {

await pool.query(
`
INSERT INTO docs_bot.doc_chunk (doc_content_id_fk, chunk_content, page_title, page_url, chunk_line_start, embedding)
INSERT INTO pql-bot.doc_chunk (doc_content_id_fk, chunk_content, page_title, page_url, chunk_line_start, embedding)
VALUES ($1, $2, $3, $4, $5, $6)
`,
[docContentId, chunk, frontmatter.title, pageUrl, index * CHUNK_SIZE, `[${embedding.join(",")}]`]
Expand Down
Loading