videogen/migrations/versions/20260811_0926_e5ae1b861df3_growth_referrals_user_presets.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

72 lines
2.6 KiB
Python

"""growth: referrals + user presets
Revision ID: e5ae1b861df3
Revises: 677d1259a269
Create Date: 2026-08-11 09:26:03.071230+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 = 'e5ae1b861df3'
down_revision: Union[str, None] = '677d1259a269'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
# Explicit name for the referral_code unique constraint so the (autogenerated
# nameless) constraint is addressable in ``downgrade`` and portable across the
# SQLite (tests) and Postgres/Neon (prod) backends.
_UQ_REFERRAL_CODE = "uq_users_referral_code"
def upgrade() -> None:
# Phase-7 (growth) persistence. All new user columns are nullable and default
# to NULL so the ADD COLUMN is safe on an already-populated ``users`` table
# and existing rows / prior tests are unaffected.
op.create_table(
'user_presets',
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), nullable=False),
sa.Column('config', sa.JSON(), 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_presets_user_id'), 'user_presets', ['user_id'], unique=False
)
# SQLite cannot ALTER TABLE ADD CONSTRAINT, so add the columns + the
# referral_code unique constraint via batch mode (copy-and-move on SQLite,
# plain ALTERs on Postgres). Named so downgrade can drop it deterministically.
with op.batch_alter_table('users', schema=None) as batch_op:
batch_op.add_column(
sa.Column('referral_code', sa.String(length=16), nullable=True)
)
batch_op.add_column(
sa.Column('referred_by', sa.String(length=32), nullable=True)
)
batch_op.create_unique_constraint(_UQ_REFERRAL_CODE, ['referral_code'])
def downgrade() -> None:
with op.batch_alter_table('users', schema=None) as batch_op:
batch_op.drop_constraint(_UQ_REFERRAL_CODE, type_='unique')
batch_op.drop_column('referred_by')
batch_op.drop_column('referral_code')
op.drop_index(op.f('ix_user_presets_user_id'), table_name='user_presets')
op.drop_table('user_presets')