Jun 26 update to the latest codes
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
"""phase31 — add ios_version and last_seen_at to api_device_tokens
|
||||
|
||||
Extends the existing api_device_tokens table (phase7) so the admin
|
||||
Devices page can show iOS version and time of last app launch.
|
||||
Drops the unused device_registrations table created by phase30 if it exists.
|
||||
"""
|
||||
|
||||
from alembic import op
|
||||
|
||||
revision = 'phase31_device_registry'
|
||||
down_revision = 'phase30_device_registry'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# Add ios_version column if it doesn't exist
|
||||
op.execute("""
|
||||
ALTER TABLE api_device_tokens
|
||||
ADD COLUMN IF NOT EXISTS ios_version VARCHAR(20) NULL
|
||||
""")
|
||||
|
||||
# Add last_seen_at column if it doesn't exist
|
||||
op.execute("""
|
||||
ALTER TABLE api_device_tokens
|
||||
ADD COLUMN IF NOT EXISTS last_seen_at DATETIME NULL
|
||||
""")
|
||||
|
||||
# Backfill last_seen_at from registered_at for existing rows
|
||||
op.execute("""
|
||||
UPDATE api_device_tokens
|
||||
SET last_seen_at = registered_at
|
||||
WHERE last_seen_at IS NULL
|
||||
""")
|
||||
|
||||
# Drop the incorrectly created device_registrations table from phase30 if present
|
||||
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")
|
||||
Reference in New Issue
Block a user