Skip to content
Merged
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
113 changes: 61 additions & 52 deletions codehawk/postgresql/db_init.sql
Original file line number Diff line number Diff line change
@@ -1,53 +1,57 @@
CREATE TABLE IF NOT EXISTS code_chunks (
id BIGSERIAL PRIMARY KEY,
repo_id TEXT NOT NULL,
commit_sha TEXT NOT NULL,
file_path TEXT NOT NULL,
language TEXT NOT NULL DEFAULT 'python',
symbol TEXT NOT NULL,
qualified_symbol TEXT NOT NULL,
symbol_type TEXT NOT NULL,
parent_symbol TEXT,
start_line INTEGER NOT NULL,
end_line INTEGER NOT NULL,
start_col INTEGER,
end_col INTEGER,
signature TEXT,
docstring TEXT,
content TEXT NOT NULL,
content_hash TEXT NOT NULL,
metadata JSONB NOT NULL DEFAULT '{}'::jsonb,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
CONSTRAINT code_chunks_line_range_check CHECK (start_line <= end_line),
CONSTRAINT code_chunks_col_range_check CHECK (
start_col IS NULL
OR end_col IS NULL
OR start_col <= end_col
),
CONSTRAINT code_chunks_symbol_type_check CHECK (
symbol_type IN ('module', 'class', 'function', 'method', 'async_function', 'async_method')
),
CONSTRAINT code_chunks_unique_content UNIQUE (
repo_id,
commit_sha,
file_path,
qualified_symbol,
start_line,
end_line,
content_hash
)
);

CREATE INDEX IF NOT EXISTS code_chunks_repo_commit_idx
ON code_chunks (repo_id, commit_sha);

CREATE INDEX IF NOT EXISTS code_chunks_file_range_idx
ON code_chunks (repo_id, commit_sha, file_path, start_line, end_line);

CREATE INDEX IF NOT EXISTS code_chunks_symbol_idx
ON code_chunks (repo_id, commit_sha, qualified_symbol);

CREATE TABLE IF NOT EXISTS code_chunks (
id BIGSERIAL PRIMARY KEY,
repo_id TEXT NOT NULL,
commit_sha TEXT NOT NULL,
file_path TEXT NOT NULL,
language TEXT NOT NULL DEFAULT 'python',
symbol TEXT NOT NULL,
qualified_symbol TEXT NOT NULL,
symbol_type TEXT NOT NULL,
parent_symbol TEXT,
start_line INTEGER NOT NULL,
end_line INTEGER NOT NULL,
start_col INTEGER,
end_col INTEGER,
signature TEXT,
docstring TEXT,
content TEXT NOT NULL,
content_hash TEXT NOT NULL,
metadata JSONB NOT NULL DEFAULT '{}'::jsonb,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
CONSTRAINT code_chunks_line_range_check CHECK (start_line <= end_line),
CONSTRAINT code_chunks_col_range_check CHECK (
start_col IS NULL
OR end_col IS NULL
OR start_line < end_line
OR (
start_line == end_line AND
start_col <= end_col
)
),
CONSTRAINT code_chunks_symbol_type_check CHECK (
symbol_type IN ('module', 'class', 'function', 'method', 'async_function', 'async_method')
),
CONSTRAINT code_chunks_unique_content UNIQUE (
repo_id,
commit_sha,
file_path,
qualified_symbol,
start_line,
end_line,
content_hash
)
);

CREATE INDEX IF NOT EXISTS code_chunks_repo_commit_idx
ON code_chunks (repo_id, commit_sha);

CREATE INDEX IF NOT EXISTS code_chunks_file_range_idx
ON code_chunks (repo_id, commit_sha, file_path, start_line, end_line);

CREATE INDEX IF NOT EXISTS code_chunks_symbol_idx
ON code_chunks (repo_id, commit_sha, qualified_symbol);

CREATE INDEX IF NOT EXISTS code_chunks_content_hash_idx
ON code_chunks (content_hash);

Expand Down Expand Up @@ -78,7 +82,12 @@ CREATE TABLE IF NOT EXISTS code_references (
CONSTRAINT code_references_col_range_check CHECK (
start_col IS NULL
OR end_col IS NULL
OR start_col <= end_col
OR end_line IS NULL
OR start_line < end_line
OR (
start_line = end_line AND
start_col <= end_col
)
),
CONSTRAINT code_references_type_check CHECK (
reference_type IN (
Expand Down Expand Up @@ -118,4 +127,4 @@ CREATE INDEX IF NOT EXISTS code_references_resolved_symbol_idx
ON code_references (repo_id, commit_sha, resolved_symbol);

CREATE INDEX IF NOT EXISTS code_references_target_chunk_idx
ON code_references (target_chunk_id);
ON code_references (target_chunk_id);
Loading