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
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.
84 lines
4.0 KiB
Python
84 lines
4.0 KiB
Python
"""Discount codes: ``discount_codes`` + ``discount_redemptions``
|
|
|
|
Launch-offer / promo-code billing primitive: a creator-facing catalog of
|
|
percent/flat-off codes (optionally flagged as the public ``/pricing`` banner)
|
|
plus a redemption ledger that enforces "one use per customer" via a
|
|
``UNIQUE(discount_code_id, user_id)`` constraint. Both tables are brand new
|
|
and purely additive.
|
|
|
|
Revision ID: c3d5e7f9b1a2
|
|
Revises: b4f6a8c0e2d5
|
|
Create Date: 2026-10-24 11:00:00.000000+00:00
|
|
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from typing import Sequence, Union
|
|
|
|
import sqlalchemy as sa
|
|
from alembic import op
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision: str = 'c3d5e7f9b1a2'
|
|
down_revision: Union[str, None] = 'b4f6a8c0e2d5'
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
_UQ_DISCOUNT_REDEMPTION_USER = "uq_discount_redemption_user"
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.create_table(
|
|
"discount_codes",
|
|
sa.Column("id", sa.String(length=32), nullable=False),
|
|
sa.Column("code", sa.String(length=40), nullable=False),
|
|
sa.Column("kind", sa.String(length=10), server_default=sa.text("'percent'"), nullable=False),
|
|
sa.Column("percent_off", sa.Integer(), nullable=True),
|
|
sa.Column("amount_off_cents", sa.Integer(), nullable=True),
|
|
sa.Column("currency", sa.String(length=10), server_default=sa.text("'usd'"), nullable=False),
|
|
sa.Column("scope_plan_keys", sa.String(length=200), server_default=sa.text("''"), nullable=False),
|
|
sa.Column("max_redemptions", sa.Integer(), nullable=True),
|
|
sa.Column("redemption_count", sa.Integer(), server_default=sa.text("0"), nullable=False),
|
|
sa.Column("active", sa.Boolean(), server_default=sa.true(), nullable=False),
|
|
sa.Column("is_public_banner", sa.Boolean(), server_default=sa.false(), nullable=False),
|
|
sa.Column("banner_text", sa.String(length=200), server_default=sa.text("''"), nullable=False),
|
|
sa.Column("starts_at", sa.DateTime(timezone=True), nullable=True),
|
|
sa.Column("expires_at", sa.DateTime(timezone=True), nullable=True),
|
|
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.text("(CURRENT_TIMESTAMP)"), nullable=False),
|
|
sa.Column("updated_at", sa.DateTime(timezone=True), server_default=sa.text("(CURRENT_TIMESTAMP)"), nullable=False),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
sa.UniqueConstraint("code"),
|
|
)
|
|
op.create_index("ix_discount_codes_code", "discount_codes", ["code"], unique=True)
|
|
|
|
op.create_table(
|
|
"discount_redemptions",
|
|
sa.Column("id", sa.String(length=32), nullable=False),
|
|
sa.Column("discount_code_id", sa.String(length=32), nullable=False),
|
|
sa.Column("user_id", sa.String(length=32), nullable=False),
|
|
sa.Column("workspace_id", sa.String(length=32), nullable=True),
|
|
sa.Column("plan_key", sa.String(length=40), nullable=False),
|
|
sa.Column("provider", sa.String(length=20), nullable=False),
|
|
sa.Column("external_ref", sa.String(length=255), server_default=sa.text("''"), nullable=False),
|
|
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.text("(CURRENT_TIMESTAMP)"), nullable=False),
|
|
sa.ForeignKeyConstraint(["discount_code_id"], ["discount_codes.id"]),
|
|
sa.ForeignKeyConstraint(["user_id"], ["users.id"]),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
sa.UniqueConstraint("discount_code_id", "user_id", name=_UQ_DISCOUNT_REDEMPTION_USER),
|
|
)
|
|
op.create_index(
|
|
"ix_discount_redemptions_discount_code_id", "discount_redemptions", ["discount_code_id"]
|
|
)
|
|
op.create_index("ix_discount_redemptions_user_id", "discount_redemptions", ["user_id"])
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_index("ix_discount_redemptions_user_id", table_name="discount_redemptions")
|
|
op.drop_index(
|
|
"ix_discount_redemptions_discount_code_id", table_name="discount_redemptions"
|
|
)
|
|
op.drop_table("discount_redemptions")
|
|
|
|
op.drop_index("ix_discount_codes_code", table_name="discount_codes")
|
|
op.drop_table("discount_codes")
|