From 873faf777c1c8e3b5a0b503abd1bbfc8797d4c79 Mon Sep 17 00:00:00 2001 From: Nguyen Ngo Date: Wed, 24 Jun 2026 17:54:39 -0400 Subject: [PATCH] Jun 24 - Implement devices tracker - Phase32 migration script --- .../versions/phase32_device_token_columns.py | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 migrations/versions/phase32_device_token_columns.py diff --git a/migrations/versions/phase32_device_token_columns.py b/migrations/versions/phase32_device_token_columns.py new file mode 100644 index 0000000..af542ea --- /dev/null +++ b/migrations/versions/phase32_device_token_columns.py @@ -0,0 +1,40 @@ +"""phase32 — add ios_version and last_seen_at to api_device_tokens + +phase31 recorded as applied but the ALTER statements never ran because +the migration used op.get_bind() pattern that failed silently. +This migration adds the two columns using raw SQL with IF NOT EXISTS +(same pattern as all working migrations in this project). +Also drops the orphaned device_registrations table from phase30 if present. +""" + +from alembic import op + +revision = 'phase32_device_token_columns' +down_revision = 'phase31_device_registry' +branch_labels = None +depends_on = None + + +def upgrade(): + op.execute(""" + ALTER TABLE api_device_tokens + ADD COLUMN IF NOT EXISTS ios_version VARCHAR(20) NULL + """) + + op.execute(""" + ALTER TABLE api_device_tokens + ADD COLUMN IF NOT EXISTS last_seen_at DATETIME NULL + """) + + op.execute(""" + UPDATE api_device_tokens + SET last_seen_at = registered_at + WHERE last_seen_at IS NULL + """) + + op.execute("DROP TABLE IF EXISTS device_registrations") + + +def downgrade(): + op.execute("ALTER TABLE api_device_tokens DROP COLUMN IF EXISTS ios_version") + op.execute("ALTER TABLE api_device_tokens DROP COLUMN IF EXISTS last_seen_at")