started implementing stripe
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
"""add_foreign_key_to_customer_subscription_plan_id
|
||||
|
||||
Revision ID: 3198363f8c4f
|
||||
Revises: add_customer_table
|
||||
Create Date: 2025-06-26 14:35:09.377247
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '3198363f8c4f'
|
||||
down_revision = 'add_customer_table'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
pass
|
||||
|
||||
|
||||
def downgrade():
|
||||
pass
|
||||
@@ -0,0 +1,50 @@
|
||||
"""replace_stripe_links_with_product_ids
|
||||
|
||||
Revision ID: 421f02ac5f59
|
||||
Revises: add_stripe_payment_links
|
||||
Create Date: 2025-06-26 13:49:45.124311
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import text
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '421f02ac5f59'
|
||||
down_revision = 'add_stripe_payment_links'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
conn = op.get_bind()
|
||||
|
||||
# Check if new columns already exist
|
||||
result = conn.execute(text("""
|
||||
SELECT column_name
|
||||
FROM information_schema.columns
|
||||
WHERE table_name = 'pricing_plans'
|
||||
AND column_name IN ('stripe_product_id', 'stripe_monthly_price_id', 'stripe_annual_price_id')
|
||||
"""))
|
||||
existing_columns = [row[0] for row in result.fetchall()]
|
||||
|
||||
# Add new Stripe product/price ID columns if they don't exist
|
||||
if 'stripe_product_id' not in existing_columns:
|
||||
op.add_column('pricing_plans', sa.Column('stripe_product_id', sa.String(length=100), nullable=True))
|
||||
|
||||
if 'stripe_monthly_price_id' not in existing_columns:
|
||||
op.add_column('pricing_plans', sa.Column('stripe_monthly_price_id', sa.String(length=100), nullable=True))
|
||||
|
||||
if 'stripe_annual_price_id' not in existing_columns:
|
||||
op.add_column('pricing_plans', sa.Column('stripe_annual_price_id', sa.String(length=100), nullable=True))
|
||||
|
||||
# Note: We'll keep the old payment link columns for now to allow for a gradual migration
|
||||
# They can be removed in a future migration after the new system is fully implemented
|
||||
|
||||
|
||||
def downgrade():
|
||||
# Remove the new Stripe product/price ID columns
|
||||
op.drop_column('pricing_plans', 'stripe_annual_price_id')
|
||||
op.drop_column('pricing_plans', 'stripe_monthly_price_id')
|
||||
op.drop_column('pricing_plans', 'stripe_product_id')
|
||||
57
migrations/versions/add_customer_table.py
Normal file
57
migrations/versions/add_customer_table.py
Normal file
@@ -0,0 +1,57 @@
|
||||
"""add customer table for Stripe customers
|
||||
|
||||
Revision ID: add_customer_table
|
||||
Revises: 421f02ac5f59
|
||||
Create Date: 2025-06-27 00:00:00.000000
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import inspect
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'add_customer_table'
|
||||
down_revision = '421f02ac5f59'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
def upgrade():
|
||||
conn = op.get_bind()
|
||||
inspector = inspect(conn)
|
||||
tables = inspector.get_table_names()
|
||||
if 'customer' not in tables:
|
||||
op.create_table(
|
||||
'customer',
|
||||
sa.Column('id', sa.Integer, primary_key=True),
|
||||
sa.Column('created_at', sa.DateTime, nullable=False, server_default=sa.text('CURRENT_TIMESTAMP')),
|
||||
sa.Column('updated_at', sa.DateTime, nullable=False, server_default=sa.text('CURRENT_TIMESTAMP'), onupdate=sa.text('CURRENT_TIMESTAMP')),
|
||||
sa.Column('email', sa.String(150), nullable=False),
|
||||
sa.Column('name', sa.String(150), nullable=True),
|
||||
sa.Column('phone', sa.String(50), nullable=True),
|
||||
sa.Column('billing_address_line1', sa.String(255), nullable=True),
|
||||
sa.Column('billing_address_line2', sa.String(255), nullable=True),
|
||||
sa.Column('billing_city', sa.String(100), nullable=True),
|
||||
sa.Column('billing_state', sa.String(100), nullable=True),
|
||||
sa.Column('billing_postal_code', sa.String(20), nullable=True),
|
||||
sa.Column('billing_country', sa.String(100), nullable=True),
|
||||
sa.Column('shipping_address_line1', sa.String(255), nullable=True),
|
||||
sa.Column('shipping_address_line2', sa.String(255), nullable=True),
|
||||
sa.Column('shipping_city', sa.String(100), nullable=True),
|
||||
sa.Column('shipping_state', sa.String(100), nullable=True),
|
||||
sa.Column('shipping_postal_code', sa.String(20), nullable=True),
|
||||
sa.Column('shipping_country', sa.String(100), nullable=True),
|
||||
sa.Column('tax_id_type', sa.String(50), nullable=True),
|
||||
sa.Column('tax_id_value', sa.String(100), nullable=True),
|
||||
sa.Column('stripe_customer_id', sa.String(255), nullable=True),
|
||||
sa.Column('stripe_subscription_id', sa.String(255), nullable=True),
|
||||
sa.Column('subscription_status', sa.String(50), nullable=True),
|
||||
sa.Column('subscription_plan_id', sa.Integer, nullable=True),
|
||||
sa.Column('subscription_billing_cycle', sa.String(20), nullable=True),
|
||||
sa.Column('subscription_current_period_start', sa.DateTime, nullable=True),
|
||||
sa.Column('subscription_current_period_end', sa.DateTime, nullable=True),
|
||||
)
|
||||
op.create_index('idx_customer_email', 'customer', ['email'])
|
||||
|
||||
def downgrade():
|
||||
op.drop_index('idx_customer_email', table_name='customer')
|
||||
op.drop_table('customer')
|
||||
@@ -0,0 +1,30 @@
|
||||
"""add_foreign_key_to_customer_subscription_plan_id
|
||||
|
||||
Revision ID: cc03b4419053
|
||||
Revises: 3198363f8c4f
|
||||
Create Date: 2025-06-26 14:35:15.661164
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'cc03b4419053'
|
||||
down_revision = '3198363f8c4f'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# Add foreign key constraint if it doesn't exist
|
||||
op.create_foreign_key(
|
||||
'fk_customer_subscription_plan_id',
|
||||
'customer', 'pricing_plan',
|
||||
['subscription_plan_id'], ['id'],
|
||||
ondelete='SET NULL'
|
||||
)
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_constraint('fk_customer_subscription_plan_id', 'customer', type_='foreignkey')
|
||||
Reference in New Issue
Block a user