File size: 1,159 Bytes
b74c6ae
 
95412b7
 
b74c6ae
 
 
 
 
95412b7
 
b74c6ae
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""citations.kind: a citation can point at an earlier chat (no document) as well as a post

Revision ID: 0014_chat_citations
Revises: 0013_workspace_memory
Create Date: 2026-10-01
"""
import sqlalchemy as sa
from alembic import op

revision = "0014_chat_citations"
down_revision = "0013_workspace_memory"
branch_labels = None
depends_on = None


def upgrade() -> None:
    # 0001 builds from the live models, so a fresh database may already have the column.
    columns = {c["name"]: c for c in sa.inspect(op.get_bind()).get_columns("citations")}
    with op.batch_alter_table("citations") as b:
        if "kind" not in columns:
            b.add_column(sa.Column("kind", sa.String(10), nullable=False, server_default="post"))
        if not columns["document_id"]["nullable"]:
            b.alter_column("document_id", existing_type=sa.Uuid(), nullable=True)


def downgrade() -> None:
    op.execute("DELETE FROM citations WHERE document_id IS NULL")  # a chat citation has no document to point at
    with op.batch_alter_table("citations") as b:
        b.alter_column("document_id", existing_type=sa.Uuid(), nullable=False)
        b.drop_column("kind")