Skip to content

Commit bb2cbb9

Browse files
committed
feat: update makefile & readme
1 parent aadf8f6 commit bb2cbb9

7 files changed

Lines changed: 117 additions & 201 deletions

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ clean:
7676
# Database schema management
7777
.PHONY: makemigration migrate
7878
makemigration:
79-
@alembic -c aperag/alembic.ini revision --autogenerate
79+
@uv run alembic -c aperag/alembic.ini revision --autogenerate
8080

8181
migrate:
82-
@alembic -c aperag/alembic.ini upgrade head
82+
@uv run alembic -c aperag/alembic.ini upgrade head
8383

8484
# Docker Compose infrastructure
8585

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
-- PostgreSQL Extensions Initialization
2+
-- This script creates necessary extensions for ApeRAG
3+
-- Extensions must be created before schema tables that use them
4+
5+
-- Create pgvector extension for vector operations
6+
-- Used by LightRAG tables: lightrag_doc_chunks, lightrag_vdb_entity, lightrag_vdb_relation
7+
CREATE EXTENSION IF NOT EXISTS vector;
8+
9+
-- Optional: Create other useful extensions
10+
-- Uncomment as needed based on project requirements
11+
12+
-- CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; -- For UUID generation
13+
-- CREATE EXTENSION IF NOT EXISTS pg_trgm; -- For trigram text search
14+
-- CREATE EXTENSION IF NOT EXISTS btree_gin; -- For GIN indexes on btree data
15+
-- CREATE EXTENSION IF NOT EXISTS btree_gist; -- For GIST indexes on btree data

aperag/migration/versions/20250630123213-495840dd6ff9.py

Lines changed: 0 additions & 107 deletions
This file was deleted.

aperag/migration/versions/20250630151946-97d64d3fe985.py

Lines changed: 0 additions & 46 deletions
This file was deleted.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""Create PostgreSQL extensions (pgvector)
2+
3+
Revision ID: db9c88848f52
4+
Revises:
5+
Create Date: 2025-07-03 13:30:46.635272
6+
7+
"""
8+
from typing import Sequence, Union
9+
10+
from alembic import op
11+
import sqlalchemy as sa
12+
13+
from aperag.migration.utils import execute_sql_file
14+
15+
16+
# revision identifiers, used by Alembic.
17+
revision: str = 'db9c88848f52'
18+
down_revision: Union[str, None] = None
19+
branch_labels: Union[str, Sequence[str], None] = None
20+
depends_on: Union[str, Sequence[str], None] = None
21+
22+
23+
def upgrade() -> None:
24+
"""Create PostgreSQL extensions."""
25+
# Execute extensions initialization SQL
26+
execute_sql_file("extensions_init.sql")
27+
28+
29+
def downgrade() -> None:
30+
"""Drop PostgreSQL extensions."""
31+
# Note: Dropping extensions should be done carefully in production
32+
# as it may affect existing data and other databases
33+
op.execute(sa.text("DROP EXTENSION IF EXISTS vector CASCADE"))

aperag/migration/versions/20250624132425-850b2c5dc08f.py renamed to aperag/migration/versions/20250703133208-0b274fcc91e2.py

Lines changed: 58 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""empty message
22
3-
Revision ID: 850b2c5dc08f
4-
Revises:
5-
Create Date: 2025-06-24 13:24:25.714734
3+
Revision ID: 0b274fcc91e2
4+
Revises: db9c88848f52
5+
Create Date: 2025-07-03 13:32:08.830672
66
77
"""
88
from typing import Sequence, Union
@@ -12,8 +12,8 @@
1212
from pgvector.sqlalchemy import Vector
1313

1414
# revision identifiers, used by Alembic.
15-
revision: str = '850b2c5dc08f'
16-
down_revision: Union[str, None] = None
15+
revision: str = '0b274fcc91e2'
16+
down_revision: Union[str, None] = 'db9c88848f52'
1717
branch_labels: Union[str, Sequence[str], None] = None
1818
depends_on: Union[str, Sequence[str], None] = None
1919

@@ -197,40 +197,48 @@ def upgrade() -> None:
197197
sa.Column('update_time', sa.DateTime(timezone=True), nullable=False),
198198
sa.PrimaryKeyConstraint('id', 'workspace')
199199
)
200-
op.create_table('lightrag_doc_full',
201-
sa.Column('id', sa.String(length=255), nullable=False),
202-
sa.Column('workspace', sa.String(length=255), nullable=False),
203-
sa.Column('doc_name', sa.String(length=1024), nullable=True),
204-
sa.Column('content', sa.Text(), nullable=True),
205-
sa.Column('meta', sa.JSON(), nullable=True),
206-
sa.Column('create_time', sa.DateTime(timezone=True), nullable=False),
207-
sa.Column('update_time', sa.DateTime(timezone=True), nullable=False),
208-
sa.PrimaryKeyConstraint('id', 'workspace')
209-
)
210-
op.create_table('lightrag_doc_status',
200+
op.create_table('lightrag_graph_edges',
201+
sa.Column('id', sa.BigInteger(), autoincrement=True, nullable=False),
202+
sa.Column('source_entity_id', sa.String(length=255), nullable=False),
203+
sa.Column('target_entity_id', sa.String(length=255), nullable=False),
204+
sa.Column('weight', sa.Numeric(precision=10, scale=6), nullable=False),
205+
sa.Column('keywords', sa.Text(), nullable=True),
206+
sa.Column('description', sa.Text(), nullable=True),
207+
sa.Column('source_id', sa.Text(), nullable=True),
208+
sa.Column('file_path', sa.Text(), nullable=True),
211209
sa.Column('workspace', sa.String(length=255), nullable=False),
212-
sa.Column('id', sa.String(length=255), nullable=False),
213-
sa.Column('content', sa.Text(), nullable=True),
214-
sa.Column('content_summary', sa.String(length=255), nullable=True),
215-
sa.Column('content_length', sa.Integer(), nullable=True),
216-
sa.Column('chunks_count', sa.Integer(), nullable=True),
217-
sa.Column('status', sa.Enum('pending', 'processing', 'processed', 'failed', name='lightragdocstatus'), nullable=True),
218-
sa.Column('file_path', sa.String(length=512), nullable=True),
219-
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
220-
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=False),
221-
sa.PrimaryKeyConstraint('workspace', 'id'),
222-
sa.UniqueConstraint('workspace', 'id', name='uq_lightrag_doc_status_workspace_id')
210+
sa.Column('createtime', sa.DateTime(timezone=True), nullable=False),
211+
sa.Column('updatetime', sa.DateTime(timezone=True), nullable=False),
212+
sa.PrimaryKeyConstraint('id'),
213+
sa.UniqueConstraint('workspace', 'source_entity_id', 'target_entity_id', name='uq_lightrag_graph_edges_workspace_source_target')
223214
)
224-
op.create_table('lightrag_llm_cache',
215+
op.create_index('idx_lightrag_edges_degree_calc', 'lightrag_graph_edges', ['workspace', 'source_entity_id', 'target_entity_id', 'weight'], unique=False)
216+
op.create_index('idx_lightrag_edges_metadata', 'lightrag_graph_edges', ['workspace', 'source_entity_id', 'target_entity_id', 'weight', 'keywords'], unique=False)
217+
op.create_index('idx_lightrag_edges_weight', 'lightrag_graph_edges', ['workspace', 'weight'], unique=False)
218+
op.create_index('idx_lightrag_edges_workspace_createtime', 'lightrag_graph_edges', ['workspace', 'createtime'], unique=False)
219+
op.create_index('idx_lightrag_edges_workspace_source', 'lightrag_graph_edges', ['workspace', 'source_entity_id'], unique=False)
220+
op.create_index('idx_lightrag_edges_workspace_source_target', 'lightrag_graph_edges', ['workspace', 'source_entity_id', 'target_entity_id'], unique=False)
221+
op.create_index('idx_lightrag_edges_workspace_target', 'lightrag_graph_edges', ['workspace', 'target_entity_id'], unique=False)
222+
op.create_index('idx_lightrag_edges_workspace_target_source', 'lightrag_graph_edges', ['workspace', 'target_entity_id', 'source_entity_id'], unique=False)
223+
op.create_table('lightrag_graph_nodes',
224+
sa.Column('id', sa.BigInteger(), autoincrement=True, nullable=False),
225+
sa.Column('entity_id', sa.String(length=256), nullable=False),
226+
sa.Column('entity_name', sa.String(length=255), nullable=True),
227+
sa.Column('entity_type', sa.String(length=255), nullable=True),
228+
sa.Column('description', sa.Text(), nullable=True),
229+
sa.Column('source_id', sa.Text(), nullable=True),
230+
sa.Column('file_path', sa.Text(), nullable=True),
225231
sa.Column('workspace', sa.String(length=255), nullable=False),
226-
sa.Column('id', sa.String(length=255), nullable=False),
227-
sa.Column('mode', sa.String(length=32), nullable=False),
228-
sa.Column('original_prompt', sa.Text(), nullable=True),
229-
sa.Column('return_value', sa.Text(), nullable=True),
230-
sa.Column('create_time', sa.DateTime(timezone=True), nullable=False),
231-
sa.Column('update_time', sa.DateTime(timezone=True), nullable=True),
232-
sa.PrimaryKeyConstraint('workspace', 'id', 'mode')
232+
sa.Column('createtime', sa.DateTime(timezone=True), nullable=False),
233+
sa.Column('updatetime', sa.DateTime(timezone=True), nullable=False),
234+
sa.PrimaryKeyConstraint('id'),
235+
sa.UniqueConstraint('workspace', 'entity_id', name='uq_lightrag_graph_nodes_workspace_entity')
233236
)
237+
op.create_index('idx_lightrag_nodes_entity_name', 'lightrag_graph_nodes', ['workspace', 'entity_name'], unique=False)
238+
op.create_index('idx_lightrag_nodes_entity_type', 'lightrag_graph_nodes', ['workspace', 'entity_type'], unique=False)
239+
op.create_index('idx_lightrag_nodes_entity_type_createtime', 'lightrag_graph_nodes', ['workspace', 'entity_type', 'createtime'], unique=False)
240+
op.create_index('idx_lightrag_nodes_workspace_createtime', 'lightrag_graph_nodes', ['workspace', 'createtime'], unique=False)
241+
op.create_index('idx_lightrag_nodes_workspace_type_id', 'lightrag_graph_nodes', ['workspace', 'entity_type', 'entity_id'], unique=False)
234242
op.create_table('lightrag_vdb_entity',
235243
sa.Column('id', sa.String(length=255), nullable=False),
236244
sa.Column('workspace', sa.String(length=255), nullable=False),
@@ -391,9 +399,21 @@ def downgrade() -> None:
391399
op.drop_table('llm_provider')
392400
op.drop_table('lightrag_vdb_relation')
393401
op.drop_table('lightrag_vdb_entity')
394-
op.drop_table('lightrag_llm_cache')
395-
op.drop_table('lightrag_doc_status')
396-
op.drop_table('lightrag_doc_full')
402+
op.drop_index('idx_lightrag_nodes_workspace_type_id', table_name='lightrag_graph_nodes')
403+
op.drop_index('idx_lightrag_nodes_workspace_createtime', table_name='lightrag_graph_nodes')
404+
op.drop_index('idx_lightrag_nodes_entity_type_createtime', table_name='lightrag_graph_nodes')
405+
op.drop_index('idx_lightrag_nodes_entity_type', table_name='lightrag_graph_nodes')
406+
op.drop_index('idx_lightrag_nodes_entity_name', table_name='lightrag_graph_nodes')
407+
op.drop_table('lightrag_graph_nodes')
408+
op.drop_index('idx_lightrag_edges_workspace_target_source', table_name='lightrag_graph_edges')
409+
op.drop_index('idx_lightrag_edges_workspace_target', table_name='lightrag_graph_edges')
410+
op.drop_index('idx_lightrag_edges_workspace_source_target', table_name='lightrag_graph_edges')
411+
op.drop_index('idx_lightrag_edges_workspace_source', table_name='lightrag_graph_edges')
412+
op.drop_index('idx_lightrag_edges_workspace_createtime', table_name='lightrag_graph_edges')
413+
op.drop_index('idx_lightrag_edges_weight', table_name='lightrag_graph_edges')
414+
op.drop_index('idx_lightrag_edges_metadata', table_name='lightrag_graph_edges')
415+
op.drop_index('idx_lightrag_edges_degree_calc', table_name='lightrag_graph_edges')
416+
op.drop_table('lightrag_graph_edges')
397417
op.drop_table('lightrag_doc_chunks')
398418
op.drop_table('invitation')
399419
op.drop_index(op.f('ix_document_index_status'), table_name='document_index')

0 commit comments

Comments
 (0)