pricing
This commit is contained in:
62
migrations/versions/add_pricing_plans_table.py
Normal file
62
migrations/versions/add_pricing_plans_table.py
Normal file
@@ -0,0 +1,62 @@
|
||||
"""add pricing plans table
|
||||
|
||||
Revision ID: add_pricing_plans_table
|
||||
Revises: add_help_articles_table
|
||||
Create Date: 2024-12-19 11:00:00.000000
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import text
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'add_pricing_plans_table'
|
||||
down_revision = 'add_help_articles_table'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
conn = op.get_bind()
|
||||
result = conn.execute(text("""
|
||||
SELECT EXISTS (
|
||||
SELECT FROM information_schema.tables
|
||||
WHERE table_name = 'pricing_plans'
|
||||
);
|
||||
"""))
|
||||
exists = result.scalar()
|
||||
if not exists:
|
||||
op.create_table('pricing_plans',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('name', sa.String(length=100), nullable=False),
|
||||
sa.Column('description', sa.Text(), nullable=True),
|
||||
sa.Column('monthly_price', sa.Float(), nullable=False),
|
||||
sa.Column('annual_price', sa.Float(), nullable=False),
|
||||
sa.Column('features', sa.JSON(), nullable=False),
|
||||
sa.Column('is_popular', sa.Boolean(), nullable=True, server_default='false'),
|
||||
sa.Column('is_custom', sa.Boolean(), nullable=True, server_default='false'),
|
||||
sa.Column('button_text', sa.String(length=50), nullable=True, server_default="'Get Started'"),
|
||||
sa.Column('button_url', sa.String(length=200), nullable=True, server_default="'#'"),
|
||||
sa.Column('order_index', sa.Integer(), nullable=True, server_default='0'),
|
||||
sa.Column('is_active', sa.Boolean(), nullable=True, server_default='true'),
|
||||
sa.Column('created_at', sa.DateTime(), nullable=True),
|
||||
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
||||
sa.Column('created_by', sa.Integer(), nullable=False),
|
||||
sa.ForeignKeyConstraint(['created_by'], ['user.id'], ondelete='CASCADE'),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
|
||||
# Create indexes for better performance
|
||||
op.create_index('idx_pricing_plans_active', 'pricing_plans', ['is_active'])
|
||||
op.create_index('idx_pricing_plans_order', 'pricing_plans', ['order_index'])
|
||||
op.create_index('idx_pricing_plans_popular', 'pricing_plans', ['is_popular'])
|
||||
op.create_index('idx_pricing_plans_created_at', 'pricing_plans', ['created_at'])
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_index('idx_pricing_plans_active', table_name='pricing_plans')
|
||||
op.drop_index('idx_pricing_plans_order', table_name='pricing_plans')
|
||||
op.drop_index('idx_pricing_plans_popular', table_name='pricing_plans')
|
||||
op.drop_index('idx_pricing_plans_created_at', table_name='pricing_plans')
|
||||
op.drop_table('pricing_plans')
|
||||
55
migrations/versions/add_quota_fields_to_pricing_plans.py
Normal file
55
migrations/versions/add_quota_fields_to_pricing_plans.py
Normal file
@@ -0,0 +1,55 @@
|
||||
"""add quota fields to pricing plans
|
||||
|
||||
Revision ID: add_quota_fields
|
||||
Revises: add_pricing_plans_table
|
||||
Create Date: 2024-12-19 12:00:00.000000
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import text
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'add_quota_fields'
|
||||
down_revision = 'add_pricing_plans_table'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
conn = op.get_bind()
|
||||
|
||||
# Check if columns already exist
|
||||
result = conn.execute(text("""
|
||||
SELECT column_name
|
||||
FROM information_schema.columns
|
||||
WHERE table_name = 'pricing_plans'
|
||||
AND column_name IN ('room_quota', 'conversation_quota', 'storage_quota_gb', 'manager_quota', 'admin_quota')
|
||||
"""))
|
||||
existing_columns = [row[0] for row in result.fetchall()]
|
||||
|
||||
# Add quota columns if they don't exist
|
||||
if 'room_quota' not in existing_columns:
|
||||
op.add_column('pricing_plans', sa.Column('room_quota', sa.Integer(), nullable=True, server_default='0'))
|
||||
|
||||
if 'conversation_quota' not in existing_columns:
|
||||
op.add_column('pricing_plans', sa.Column('conversation_quota', sa.Integer(), nullable=True, server_default='0'))
|
||||
|
||||
if 'storage_quota_gb' not in existing_columns:
|
||||
op.add_column('pricing_plans', sa.Column('storage_quota_gb', sa.Integer(), nullable=True, server_default='0'))
|
||||
|
||||
if 'manager_quota' not in existing_columns:
|
||||
op.add_column('pricing_plans', sa.Column('manager_quota', sa.Integer(), nullable=True, server_default='0'))
|
||||
|
||||
if 'admin_quota' not in existing_columns:
|
||||
op.add_column('pricing_plans', sa.Column('admin_quota', sa.Integer(), nullable=True, server_default='0'))
|
||||
|
||||
|
||||
def downgrade():
|
||||
# Remove quota columns
|
||||
op.drop_column('pricing_plans', 'admin_quota')
|
||||
op.drop_column('pricing_plans', 'manager_quota')
|
||||
op.drop_column('pricing_plans', 'storage_quota_gb')
|
||||
op.drop_column('pricing_plans', 'conversation_quota')
|
||||
op.drop_column('pricing_plans', 'room_quota')
|
||||
Reference in New Issue
Block a user