Files
orion/alembic/versions_backup/i7d8e9f0a1b2_add_vendor_subscriptions.py
Samir Boulahtit 68493dc6cb feat(subscriptions): migrate subscription management to merchant level and seed tiers
Move subscription create/edit from store detail (broken endpoint) to merchant
detail page with proper modal UI. Seed 4 subscription tiers (Essential,
Professional, Business, Enterprise) in init_production.py. Also includes
cross-module dependency declarations, store domain platform_id migration,
platform context middleware, CMS route fixes, and migration backups.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-09 21:04:04 +01:00

149 lines
4.8 KiB
Python

"""Add vendor subscriptions table
Revision ID: i7d8e9f0a1b2
Revises: h6c7d8e9f0a1
Create Date: 2025-12-24
This migration adds:
- vendor_subscriptions: Per-vendor subscription tracking with tier limits
"""
from typing import Sequence, Union
import sqlalchemy as sa
from alembic import op
# revision identifiers, used by Alembic.
revision: str = "i7d8e9f0a1b2"
down_revision: Union[str, None] = "h6c7d8e9f0a1"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# Create vendor_subscriptions table
op.create_table(
"vendor_subscriptions",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("vendor_id", sa.Integer(), nullable=False),
# Tier and status
sa.Column(
"tier", sa.String(length=20), server_default="essential", nullable=False
),
sa.Column(
"status", sa.String(length=20), server_default="trial", nullable=False
),
# Billing period
sa.Column("period_start", sa.DateTime(timezone=True), nullable=False),
sa.Column("period_end", sa.DateTime(timezone=True), nullable=False),
sa.Column("is_annual", sa.Boolean(), server_default="0", nullable=False),
# Trial
sa.Column("trial_ends_at", sa.DateTime(timezone=True), nullable=True),
# Usage counters
sa.Column("orders_this_period", sa.Integer(), server_default="0", nullable=False),
sa.Column("orders_limit_reached_at", sa.DateTime(timezone=True), nullable=True),
# Custom overrides
sa.Column("custom_orders_limit", sa.Integer(), nullable=True),
sa.Column("custom_products_limit", sa.Integer(), nullable=True),
sa.Column("custom_team_limit", sa.Integer(), nullable=True),
# Payment (future Stripe integration)
sa.Column("stripe_customer_id", sa.String(length=100), nullable=True),
sa.Column("stripe_subscription_id", sa.String(length=100), nullable=True),
# Cancellation
sa.Column("cancelled_at", sa.DateTime(timezone=True), nullable=True),
sa.Column("cancellation_reason", sa.Text(), nullable=True),
# Timestamps
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.ForeignKeyConstraint(
["vendor_id"],
["vendors.id"],
),
sa.PrimaryKeyConstraint("id"),
sa.UniqueConstraint("vendor_id"),
)
op.create_index(
op.f("ix_vendor_subscriptions_id"),
"vendor_subscriptions",
["id"],
unique=False,
)
op.create_index(
op.f("ix_vendor_subscriptions_vendor_id"),
"vendor_subscriptions",
["vendor_id"],
unique=True,
)
op.create_index(
op.f("ix_vendor_subscriptions_tier"),
"vendor_subscriptions",
["tier"],
unique=False,
)
op.create_index(
op.f("ix_vendor_subscriptions_status"),
"vendor_subscriptions",
["status"],
unique=False,
)
op.create_index(
op.f("ix_vendor_subscriptions_stripe_customer_id"),
"vendor_subscriptions",
["stripe_customer_id"],
unique=False,
)
op.create_index(
op.f("ix_vendor_subscriptions_stripe_subscription_id"),
"vendor_subscriptions",
["stripe_subscription_id"],
unique=False,
)
op.create_index(
"idx_subscription_vendor_status",
"vendor_subscriptions",
["vendor_id", "status"],
unique=False,
)
op.create_index(
"idx_subscription_period",
"vendor_subscriptions",
["period_start", "period_end"],
unique=False,
)
def downgrade() -> None:
op.drop_index("idx_subscription_period", table_name="vendor_subscriptions")
op.drop_index("idx_subscription_vendor_status", table_name="vendor_subscriptions")
op.drop_index(
op.f("ix_vendor_subscriptions_stripe_subscription_id"),
table_name="vendor_subscriptions",
)
op.drop_index(
op.f("ix_vendor_subscriptions_stripe_customer_id"),
table_name="vendor_subscriptions",
)
op.drop_index(
op.f("ix_vendor_subscriptions_status"), table_name="vendor_subscriptions"
)
op.drop_index(
op.f("ix_vendor_subscriptions_tier"), table_name="vendor_subscriptions"
)
op.drop_index(
op.f("ix_vendor_subscriptions_vendor_id"), table_name="vendor_subscriptions"
)
op.drop_index(
op.f("ix_vendor_subscriptions_id"), table_name="vendor_subscriptions"
)
op.drop_table("vendor_subscriptions")