80 lines
2.4 KiB
Python
80 lines
2.4 KiB
Python
"""Create immutable content citations."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import sqlalchemy as sa
|
|
from alembic import op
|
|
|
|
revision = "0010_citations"
|
|
down_revision = "0009_content_publication"
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.create_table(
|
|
"citations",
|
|
sa.Column("id", sa.Uuid(), primary_key=True),
|
|
sa.Column("workspace_id", sa.Uuid(), nullable=False),
|
|
sa.Column("space_id", sa.Uuid(), nullable=False),
|
|
sa.Column(
|
|
"document_id",
|
|
sa.Uuid(),
|
|
sa.ForeignKey("content.documents.id", ondelete="RESTRICT"),
|
|
nullable=False,
|
|
),
|
|
sa.Column(
|
|
"document_version_id",
|
|
sa.Uuid(),
|
|
sa.ForeignKey("content.document_versions.id", ondelete="RESTRICT"),
|
|
nullable=False,
|
|
),
|
|
sa.Column(
|
|
"chunk_id",
|
|
sa.Uuid(),
|
|
sa.ForeignKey("content.chunks.id", ondelete="RESTRICT"),
|
|
nullable=False,
|
|
),
|
|
sa.Column(
|
|
"parent_chunk_id",
|
|
sa.Uuid(),
|
|
sa.ForeignKey("content.chunks.id", ondelete="RESTRICT"),
|
|
nullable=True,
|
|
),
|
|
sa.Column("location", sa.JSON(), nullable=False),
|
|
sa.Column("excerpt", sa.Text(), nullable=False),
|
|
sa.Column("excerpt_checksum", sa.String(64), nullable=False),
|
|
sa.Column("source_uri", sa.String(2048), nullable=False),
|
|
sa.Column("acquired_at", sa.DateTime(timezone=True), nullable=False),
|
|
sa.Column("retrieval_run_id", sa.Uuid(), nullable=False),
|
|
sa.Column("index_alias", sa.String(256), nullable=False),
|
|
sa.Column("profile_version", sa.String(256), nullable=False),
|
|
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
|
|
schema="content",
|
|
)
|
|
op.create_index(
|
|
"ix_content_citations_workspace_space",
|
|
"citations",
|
|
["workspace_id", "space_id"],
|
|
schema="content",
|
|
)
|
|
op.create_index(
|
|
"ix_content_citations_document_version",
|
|
"citations",
|
|
["document_version_id"],
|
|
schema="content",
|
|
)
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_index(
|
|
"ix_content_citations_document_version",
|
|
table_name="citations",
|
|
schema="content",
|
|
)
|
|
op.drop_index(
|
|
"ix_content_citations_workspace_space",
|
|
table_name="citations",
|
|
schema="content",
|
|
)
|
|
op.drop_table("citations", schema="content") |