56 lines
1.9 KiB
Python
56 lines
1.9 KiB
Python
"""add_donation_columns
|
|
|
|
Revision ID: 008_add_donations
|
|
Revises: 007_add_sub_fields
|
|
Create Date: 2026-01-04
|
|
|
|
Fixes:
|
|
- Add missing Stripe payment columns to donations table
|
|
"""
|
|
from typing import Sequence, Union
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
from sqlalchemy import inspect
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision: str = '008_add_donations'
|
|
down_revision: Union[str, None] = '007_add_sub_fields'
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
"""Add missing columns to donations table (skip if already exists)"""
|
|
|
|
# Get database connection
|
|
conn = op.get_bind()
|
|
inspector = inspect(conn)
|
|
existing_columns = {col['name'] for col in inspector.get_columns('donations')}
|
|
|
|
# Stripe payment columns
|
|
if 'stripe_checkout_session_id' not in existing_columns:
|
|
op.add_column('donations', sa.Column('stripe_checkout_session_id', sa.String(), nullable=True))
|
|
|
|
if 'stripe_payment_intent_id' not in existing_columns:
|
|
op.add_column('donations', sa.Column('stripe_payment_intent_id', sa.String(), nullable=True))
|
|
|
|
if 'payment_method' not in existing_columns:
|
|
op.add_column('donations', sa.Column('payment_method', sa.String(), nullable=True))
|
|
|
|
if 'notes' not in existing_columns:
|
|
op.add_column('donations', sa.Column('notes', sa.Text(), nullable=True))
|
|
|
|
if 'updated_at' not in existing_columns:
|
|
op.add_column('donations', sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True))
|
|
|
|
|
|
def downgrade() -> None:
|
|
"""Remove added columns (rollback)"""
|
|
|
|
op.drop_column('donations', 'updated_at')
|
|
op.drop_column('donations', 'notes')
|
|
op.drop_column('donations', 'payment_method')
|
|
op.drop_column('donations', 'stripe_payment_intent_id')
|
|
op.drop_column('donations', 'stripe_checkout_session_id')
|