43 lines
1.7 KiB
Python
43 lines
1.7 KiB
Python
"""add push device tokens
|
|||
|
|
|
||
|
|
Revision ID: 0006_push_device_tokens
|
||
|
|
Revises: 0005_mobile_query_indexes
|
||
|
|
Create Date: 2026-06-06
|
||
|
|
"""
|
||
|
|
|
||
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
import sqlalchemy as sa
|
||
|
|
from alembic import op
|
||
|
|
|
||
|
|
|
||
|
|
revision = "0006_push_device_tokens"
|
||
|
|
down_revision = "0005_mobile_query_indexes"
|
||
|
|
branch_labels = None
|
||
|
|
depends_on = None
|
||
|
|
|
||
|
|
|
||
|
|
def upgrade() -> None:
|
||
|
|
op.create_table(
|
||
|
|
"push_device_tokens",
|
||
|
|
sa.Column("user_id", sa.String(length=36), nullable=False),
|
||
|
|
sa.Column("device_id", sa.String(length=128), nullable=False),
|
||
|
|
sa.Column("platform", sa.String(length=20), nullable=False),
|
||
|
|
sa.Column("fcm_token", sa.Text(), nullable=False),
|
||
|
|
sa.Column("is_active", sa.Boolean(), nullable=False),
|
||
|
|
sa.Column("last_seen_at", sa.DateTime(timezone=True), nullable=True),
|
||
|
|
sa.Column("id", sa.String(length=36), nullable=False),
|
||
|
|
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
|
||
|
|
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False),
|
||
|
|
sa.ForeignKeyConstraint(["user_id"], ["users.id"], ondelete="CASCADE"),
|
||
|
|
sa.PrimaryKeyConstraint("id"),
|
||
|
|
sa.UniqueConstraint("user_id", "device_id", name="uq_push_device_tokens_user_device"),
|
||
|
|
)
|
||
|
|
op.create_index("ix_push_device_tokens_is_active", "push_device_tokens", ["is_active"])
|
||
|
|
op.create_index("ix_push_device_tokens_user_active", "push_device_tokens", ["user_id", "is_active"])
|
||
|
|
|
||
|
|
|
||
|
|
def downgrade() -> None:
|
||
|
|
op.drop_index("ix_push_device_tokens_user_active", table_name="push_device_tokens")
|
||
|
|
op.drop_index("ix_push_device_tokens_is_active", table_name="push_device_tokens")
|
||
|
|
op.drop_table("push_device_tokens")
|