Jun 24 - Implement devices tracker - Phase32 migration script

This commit is contained in:
Nguyen Ngo
2026-06-24 17:54:39 -04:00
parent 2293f88f42
commit 873faf777c
@@ -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")