Jun 24 - Implement devices tracker
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
"""phase30 — device_registrations table for iOS device tracking
|
||||
|
||||
Revision ID: phase30_device_registry
|
||||
Down revision: phase29_broadcasts
|
||||
"""
|
||||
|
||||
revision = 'phase30_device_registry'
|
||||
down_revision = 'phase29_broadcasts'
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
def upgrade():
|
||||
# Guard: skip if table already exists (safe to re-run)
|
||||
conn = op.get_bind()
|
||||
exists = conn.execute(sa.text(
|
||||
"SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES "
|
||||
"WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'device_registrations'"
|
||||
)).scalar()
|
||||
if exists:
|
||||
return
|
||||
|
||||
op.create_table(
|
||||
'device_registrations',
|
||||
sa.Column('id', sa.Integer(), primary_key=True),
|
||||
sa.Column('device_id', sa.String(64), nullable=False),
|
||||
sa.Column('user_id', sa.Integer(), sa.ForeignKey('users.id'), nullable=False),
|
||||
sa.Column('device_name', sa.String(255), nullable=False, server_default=''),
|
||||
sa.Column('app_version', sa.String(32), nullable=False, server_default=''),
|
||||
sa.Column('ios_version', sa.String(32), nullable=False, server_default=''),
|
||||
sa.Column('registered_at', sa.DateTime(), nullable=False),
|
||||
sa.Column('last_seen_at', sa.DateTime(), nullable=False),
|
||||
)
|
||||
|
||||
op.create_index('uq_device_id', 'device_registrations', ['device_id'], unique=True)
|
||||
op.create_index('ix_device_registrations_user_id', 'device_registrations', ['user_id'])
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_table('device_registrations')
|
||||
Reference in New Issue
Block a user