|
| 1 | +"""Add note_content table |
| 2 | +
|
| 3 | +Revision ID: l5g6h7i8j9k0 |
| 4 | +Revises: k4e5f6g7h8i9 |
| 5 | +Create Date: 2026-04-04 12:00:00.000000 |
| 6 | +
|
| 7 | +""" |
| 8 | + |
| 9 | +from typing import Sequence, Union |
| 10 | + |
| 11 | +import sqlalchemy as sa |
| 12 | +from alembic import op |
| 13 | + |
| 14 | + |
| 15 | +# revision identifiers, used by Alembic. |
| 16 | +revision: str = "l5g6h7i8j9k0" |
| 17 | +down_revision: Union[str, None] = "k4e5f6g7h8i9" |
| 18 | +branch_labels: Union[str, Sequence[str], None] = None |
| 19 | +depends_on: Union[str, Sequence[str], None] = None |
| 20 | + |
| 21 | + |
| 22 | +def upgrade() -> None: |
| 23 | + """Create note_content for materialized note content and sync state.""" |
| 24 | + op.create_table( |
| 25 | + "note_content", |
| 26 | + sa.Column("entity_id", sa.Integer(), nullable=False), |
| 27 | + sa.Column("project_id", sa.Integer(), nullable=False), |
| 28 | + sa.Column("external_id", sa.String(), nullable=False), |
| 29 | + sa.Column("file_path", sa.String(), nullable=False), |
| 30 | + sa.Column("markdown_content", sa.Text(), nullable=False), |
| 31 | + sa.Column("db_version", sa.BigInteger(), nullable=False), |
| 32 | + sa.Column("db_checksum", sa.String(), nullable=False), |
| 33 | + sa.Column("file_version", sa.BigInteger(), nullable=True), |
| 34 | + sa.Column("file_checksum", sa.String(), nullable=True), |
| 35 | + sa.Column("file_write_status", sa.String(), nullable=False), |
| 36 | + sa.Column("last_source", sa.String(), nullable=True), |
| 37 | + sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False), |
| 38 | + sa.Column("file_updated_at", sa.DateTime(timezone=True), nullable=True), |
| 39 | + sa.Column("last_materialization_error", sa.Text(), nullable=True), |
| 40 | + sa.Column("last_materialization_attempt_at", sa.DateTime(timezone=True), nullable=True), |
| 41 | + sa.CheckConstraint( |
| 42 | + "file_write_status IN (" |
| 43 | + "'pending', " |
| 44 | + "'writing', " |
| 45 | + "'synced', " |
| 46 | + "'failed', " |
| 47 | + "'external_change_detected'" |
| 48 | + ")", |
| 49 | + name="ck_note_content_file_write_status", |
| 50 | + ), |
| 51 | + sa.ForeignKeyConstraint(["entity_id"], ["entity.id"], ondelete="CASCADE"), |
| 52 | + sa.ForeignKeyConstraint(["project_id"], ["project.id"], ondelete="CASCADE"), |
| 53 | + sa.PrimaryKeyConstraint("entity_id"), |
| 54 | + ) |
| 55 | + op.create_index("ix_note_content_project_id", "note_content", ["project_id"], unique=False) |
| 56 | + op.create_index("ix_note_content_file_path", "note_content", ["file_path"], unique=False) |
| 57 | + op.create_index("ix_note_content_external_id", "note_content", ["external_id"], unique=True) |
| 58 | + |
| 59 | + |
| 60 | +def downgrade() -> None: |
| 61 | + """Drop note_content and its supporting indexes.""" |
| 62 | + op.drop_index("ix_note_content_external_id", table_name="note_content") |
| 63 | + op.drop_index("ix_note_content_file_path", table_name="note_content") |
| 64 | + op.drop_index("ix_note_content_project_id", table_name="note_content") |
| 65 | + op.drop_table("note_content") |
0 commit comments