videogen/migrations/versions/20260921_1200_e4f5a6b7c8d9_push_tokens.py
caelum0x d56639a594
Some checks are pending
build-images / api (push) Waiting to run
build-images / worker-gpu (push) Waiting to run
build-images / web (push) Waiting to run
codeql / Analyze (javascript-typescript) (push) Waiting to run
codeql / Analyze (python) (push) Waiting to run
perf / API hot-path micro-smoke (budgeted) (push) Waiting to run
perf / Desktop engine crates (release build check) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Waiting to run
vision2026-ci / API phase modules (ruff + pytest) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Waiting to run
vision2026-ci / Python SDK resource tests (push) Waiting to run
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Waiting to run
vision2026-ci / Alembic upgrade + drift check (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Waiting to run
Menivor — open source release (MIT), free to use and fork
Paid, hosted product at menivor.com, now retired as a company project.
Fresh squashed history of the cleaned working tree (secret-scanned,
no .env, no customer data, no outreach logs). Built on
MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
2026-12-04 02:10:26 +03:00

113 lines
3.9 KiB
Python

"""push_tokens: Expo push tokens for out-of-app render notifications
Backs the mobile push backend. The client (``POST /api/v1/me/push-tokens``)
registers one Expo push token per install, keyed by the stable SecureStore
``install_id``; the job-completion path (``app.services.notifications`` ->
``app.services.push``) looks up an owner's *active* tokens and delivers a native
push via Expo so a finished render reaches a backgrounded device.
The model is declared in ``app.models.db.models.PushToken`` and registered on
``Base.metadata`` (imported by ``migrations/env.py``), but no migration created
the table. This is a straight, additive create matching the model definition:
* ``install_id`` is UNIQUE (the UPSERT key — one row per install), so a rotated
token refreshes the row in place instead of duplicating it.
* ``user_id`` is nullable (a token may be seen before its owner resolves) with a
FK to ``users.id`` and an index for the owner-scoped lookup; a composite
``(user_id, is_active)`` index backs the hot "active tokens for this owner"
query the send path runs.
* ``is_active`` lets a dead token (Expo ``DeviceNotRegistered``) or a
signed-out install be flipped off without losing the install<->token history.
A brand-new table, so the CREATE is safe on an already-populated database and
existing rows / prior tests are unaffected.
Revision ID: e4f5a6b7c8d9
Revises: d3e4f5a6b7c8
Create Date: 2026-09-21 12:00:00.000000+00:00
"""
from __future__ import annotations
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = 'e4f5a6b7c8d9'
down_revision: Union[str, None] = 'd3e4f5a6b7c8'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
op.create_table(
"push_tokens",
sa.Column("id", sa.String(length=32), nullable=False),
sa.Column("install_id", sa.String(length=64), nullable=False),
# Opaque ExponentPushToken[...] string (sensitive).
sa.Column("token", sa.String(length=512), nullable=False),
sa.Column(
"platform",
sa.String(length=16),
server_default=sa.text("''"),
nullable=False,
),
sa.Column("user_id", sa.String(length=32), nullable=True),
sa.Column(
"is_active",
sa.Boolean(),
server_default=sa.true(),
nullable=False,
),
sa.Column(
"created_at",
sa.DateTime(timezone=True),
server_default=sa.text("now()"),
nullable=False,
),
sa.Column(
"updated_at",
sa.DateTime(timezone=True),
server_default=sa.text("now()"),
nullable=False,
),
sa.Column(
"last_seen",
sa.DateTime(timezone=True),
server_default=sa.text("now()"),
nullable=False,
),
sa.ForeignKeyConstraint(["user_id"], ["users.id"]),
sa.PrimaryKeyConstraint("id"),
)
# UNIQUE install index — the UPSERT key (one row per install).
op.create_index(
op.f("ix_push_tokens_install_id"),
"push_tokens",
["install_id"],
unique=True,
)
op.create_index(
op.f("ix_push_tokens_user_id"),
"push_tokens",
["user_id"],
unique=False,
)
# Composite index backing the hot "active tokens for this owner" lookup.
op.create_index(
"ix_push_tokens_user_id_is_active",
"push_tokens",
["user_id", "is_active"],
unique=False,
)
def downgrade() -> None:
op.drop_index("ix_push_tokens_user_id_is_active", table_name="push_tokens")
op.drop_index(op.f("ix_push_tokens_user_id"), table_name="push_tokens")
op.drop_index(op.f("ix_push_tokens_install_id"), table_name="push_tokens")
op.drop_table("push_tokens")