videogen/migrations/versions/20260812_1607_4e73c6aaa0a5_user_api_keys.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

61 lines
2.8 KiB
Python

"""user_api_keys
Revision ID: 4e73c6aaa0a5
Revises: 54e4dca8a24a
Create Date: 2026-08-12 16:07:38.210318+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 = '4e73c6aaa0a5'
down_revision: Union[str, None] = '54e4dca8a24a'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# PUBLIC API KEYS: a brand-new per-user table backing personal programmatic
# access to the ``/api/v1`` REST API. A user mints a key used as the
# ``x-api-key`` header; only its SHA-256 hex digest (``key_hash``) is stored,
# never the raw secret (revealed once at creation). ``key_hash`` carries a
# UNIQUE index (``ix_user_api_keys_key_hash``) so a presented key resolves to
# at most one owner in an O(index) lookup; ``user_id`` is indexed for
# owner-scoped listing and ``revoked`` is indexed so the hot live-key filter
# never scans the table. Columns declare their ``server_default`` so the row
# shape is self-describing and Alembic autogenerate reports no drift. A
# brand-new table, so the CREATE is safe on an already-populated database and
# existing rows / prior tests are unaffected.
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('user_api_keys',
sa.Column('id', sa.String(length=32), nullable=False),
sa.Column('user_id', sa.String(length=32), nullable=False),
sa.Column('name', sa.String(length=200), server_default=sa.text("('')"), nullable=False),
sa.Column('key_hash', sa.String(length=64), nullable=False),
sa.Column('prefix', sa.String(length=16), server_default=sa.text("('')"), nullable=False),
sa.Column('last_used_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('revoked', sa.Boolean(), server_default=sa.false(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_user_api_keys_key_hash'), 'user_api_keys', ['key_hash'], unique=True)
op.create_index(op.f('ix_user_api_keys_revoked'), 'user_api_keys', ['revoked'], unique=False)
op.create_index(op.f('ix_user_api_keys_user_id'), 'user_api_keys', ['user_id'], unique=False)
# ### end Alembic commands ###
def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f('ix_user_api_keys_user_id'), table_name='user_api_keys')
op.drop_index(op.f('ix_user_api_keys_revoked'), table_name='user_api_keys')
op.drop_index(op.f('ix_user_api_keys_key_hash'), table_name='user_api_keys')
op.drop_table('user_api_keys')
# ### end Alembic commands ###