Files

35 lines
1.2 KiB
Python

"""phase30 — device_registrations table for iOS device tracking
Each row records a device that has opened the JanitorialQC app.
Upserted on every app foreground so last_seen_at stays current.
"""
from alembic import op
revision = 'phase30_device_registry'
down_revision = 'phase29_broadcasts'
branch_labels = None
depends_on = None
def upgrade():
op.execute("""
CREATE TABLE IF NOT EXISTS device_registrations (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
device_id VARCHAR(64) NOT NULL,
user_id INT NOT NULL,
device_name VARCHAR(255) NOT NULL DEFAULT '',
app_version VARCHAR(32) NOT NULL DEFAULT '',
ios_version VARCHAR(32) NOT NULL DEFAULT '',
registered_at DATETIME NOT NULL,
last_seen_at DATETIME NOT NULL,
CONSTRAINT uq_device_id UNIQUE (device_id),
CONSTRAINT fk_device_reg_user
FOREIGN KEY (user_id) REFERENCES users(id)
ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
""")
def downgrade():
op.execute("DROP TABLE IF EXISTS device_registrations")