Coverage for nexusLIMS/db/migrations/versions/v2_4_0a_add_upload_log_table.py: 100%
15 statements
« prev ^ index » next coverage.py v7.11.3, created at 2026-03-24 05:23 +0000
« prev ^ index » next coverage.py v7.11.3, created at 2026-03-24 05:23 +0000
1"""Add upload_log table and BUILT_NOT_EXPORTED status.
3Revision ID: v2_4_0a
4Revises: v1_4_3
5Create Date: 2026-01-23 12:12:15.867734
7"""
9from typing import Sequence, Union
11import sqlalchemy as sa
12from alembic import op
14# revision identifiers, used by Alembic.
15revision: str = "v2_4_0a"
16down_revision: Union[str, Sequence[str], None] = "v1_4_3"
17branch_labels: Union[str, Sequence[str], None] = None
18depends_on: Union[str, Sequence[str], None] = None
21def upgrade() -> None:
22 """Upgrade schema."""
23 # Create upload_log table
24 op.create_table(
25 "upload_log",
26 sa.Column("id", sa.Integer(), nullable=False),
27 sa.Column("session_identifier", sa.String(length=36), nullable=False),
28 sa.Column("destination_name", sa.String(length=100), nullable=False),
29 sa.Column("success", sa.Boolean(), nullable=False),
30 sa.Column("timestamp", sa.String(), nullable=False),
31 sa.Column("record_id", sa.String(length=255), nullable=True),
32 sa.Column("record_url", sa.String(length=500), nullable=True),
33 sa.Column("error_message", sa.String(), nullable=True),
34 sa.Column("metadata_json", sa.String(), nullable=True),
35 sa.PrimaryKeyConstraint("id"),
36 )
38 # Create indexes
39 op.create_index(
40 op.f("ix_upload_log_session_identifier"),
41 "upload_log",
42 ["session_identifier"],
43 unique=False,
44 )
45 op.create_index(
46 op.f("ix_upload_log_destination_name"),
47 "upload_log",
48 ["destination_name"],
49 unique=False,
50 )
52 # Note: BUILT_NOT_EXPORTED status is added to the RecordStatus enum in code.
53 # SQLite stores enums as strings, so no schema migration is needed for the enum.
54 # The new status will be available immediately upon deploying the updated code.
57def downgrade() -> None:
58 """Downgrade schema."""
59 # Drop indexes
60 op.drop_index(op.f("ix_upload_log_destination_name"), table_name="upload_log")
61 op.drop_index(op.f("ix_upload_log_session_identifier"), table_name="upload_log")
63 # Drop table
64 op.drop_table("upload_log")
66 # Note: Downgrading the BUILT_NOT_EXPORTED status would require updating
67 # any session_log rows that use it. Since SQLite stores enums as strings,
68 # the old code will simply not recognize this status value.
69 # Manual cleanup may be needed if any rows use BUILT_NOT_EXPORTED.