mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-26 09:16:22 +02:00
feat: add migration 0 for initial schema setup
This commit is contained in:
parent
443e877a59
commit
924e621a6b
2 changed files with 55 additions and 5 deletions
54
surfsense_backend/alembic/versions/0_initial_schema.py
Normal file
54
surfsense_backend/alembic/versions/0_initial_schema.py
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
"""Initial schema setup
|
||||
|
||||
Revision ID: 0
|
||||
Revises: None
|
||||
|
||||
Creates all tables from SQLAlchemy models. Idempotent - safe to run on existing databases.
|
||||
"""
|
||||
|
||||
from collections.abc import Sequence
|
||||
|
||||
import sqlalchemy as sa
|
||||
|
||||
from alembic import op
|
||||
|
||||
revision: str = "0"
|
||||
down_revision: str | None = None
|
||||
branch_labels: str | Sequence[str] | None = None
|
||||
depends_on: str | Sequence[str] | None = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
from app.db import Base
|
||||
|
||||
connection = op.get_bind()
|
||||
|
||||
# Create tables
|
||||
op.execute(sa.text("CREATE EXTENSION IF NOT EXISTS vector"))
|
||||
Base.metadata.create_all(bind=connection)
|
||||
|
||||
# Set up indexes
|
||||
op.execute(
|
||||
sa.text(
|
||||
"CREATE INDEX IF NOT EXISTS document_vector_index ON documents USING hnsw (embedding public.vector_cosine_ops)"
|
||||
)
|
||||
)
|
||||
op.execute(
|
||||
sa.text(
|
||||
"CREATE INDEX IF NOT EXISTS document_search_index ON documents USING gin (to_tsvector('english', content))"
|
||||
)
|
||||
)
|
||||
op.execute(
|
||||
sa.text(
|
||||
"CREATE INDEX IF NOT EXISTS chucks_vector_index ON chunks USING hnsw (embedding public.vector_cosine_ops)"
|
||||
)
|
||||
)
|
||||
op.execute(
|
||||
sa.text(
|
||||
"CREATE INDEX IF NOT EXISTS chucks_search_index ON chunks USING gin (to_tsvector('english', content))"
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
pass
|
||||
Loading…
Add table
Add a link
Reference in a new issue