From 427a4913807621d195074572de93f068a26434a2 Mon Sep 17 00:00:00 2001 From: Tianyu Liu Date: Fri, 12 Jun 2026 16:02:46 +0200 Subject: [PATCH] M1-T01: add app-chain revision creating location + poo_records tables Add alembic_app revision 20260611_06_merge_location_poo_tables that builds empty location and poo_records tables (REAL float columns, matching the production schema and the adopt scripts' EXPECTED_*_TABLE_INFO constants). Update APP_BASELINE_REVISION to the new head. Schema-only; data migration is handled separately by scripts/migrate_legacy_data.py (M1-T02). --- .../20260611_06_merge_location_poo_tables.py | 43 +++++++++++++++++++ scripts/app_db_adopt.py | 2 +- 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 alembic_app/versions/20260611_06_merge_location_poo_tables.py diff --git a/alembic_app/versions/20260611_06_merge_location_poo_tables.py b/alembic_app/versions/20260611_06_merge_location_poo_tables.py new file mode 100644 index 0000000..a0d7997 --- /dev/null +++ b/alembic_app/versions/20260611_06_merge_location_poo_tables.py @@ -0,0 +1,43 @@ +"""merge location and poo_records tables into app chain + +Revision ID: 20260611_06_merge_location_poo_tables +Revises: 20260429_05_public_ip_monitor +Create Date: 2026-06-11 00:00:01.000000 +""" + +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa + + +revision: str = "20260611_06_merge_location_poo_tables" +down_revision: Union[str, None] = "20260429_05_public_ip_monitor" +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + op.create_table( + "location", + sa.Column("person", sa.Text(), nullable=False), + sa.Column("datetime", sa.Text(), nullable=False), + sa.Column("latitude", sa.REAL(), nullable=False), + sa.Column("longitude", sa.REAL(), nullable=False), + sa.Column("altitude", sa.REAL(), nullable=True), + sa.PrimaryKeyConstraint("person", "datetime"), + ) + + op.create_table( + "poo_records", + sa.Column("timestamp", sa.Text(), nullable=False), + sa.Column("status", sa.Text(), nullable=False), + sa.Column("latitude", sa.REAL(), nullable=False), + sa.Column("longitude", sa.REAL(), nullable=False), + sa.PrimaryKeyConstraint("timestamp"), + ) + + +def downgrade() -> None: + op.drop_table("poo_records") + op.drop_table("location") diff --git a/scripts/app_db_adopt.py b/scripts/app_db_adopt.py index 4a1b30d..acd0074 100644 --- a/scripts/app_db_adopt.py +++ b/scripts/app_db_adopt.py @@ -15,7 +15,7 @@ if str(PROJECT_ROOT) not in sys.path: from app.config import get_settings -APP_BASELINE_REVISION = "20260429_05_public_ip_monitor" +APP_BASELINE_REVISION = "20260611_06_merge_location_poo_tables" class AppDatabaseAdoptionError(RuntimeError):