Automated Action a8b6d5b972 Fix SQLAlchemy reserved attribute error
- Renamed 'metadata' column to 'payment_metadata' in Payment model
- Updated database migration to use new column name
- Updated StripeService to use payment_metadata field
- Fixed application startup issue caused by reserved attribute name
2025-06-20 12:30:47 +00:00

102 lines
3.4 KiB
Python

"""Initial migration - create payments and payment_methods tables
Revision ID: 001
Revises:
Create Date: 2024-01-01 00:00:00.000000
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = "001"
down_revision = None
branch_labels = None
depends_on = None
def upgrade() -> None:
# Create payments table
op.create_table(
"payments",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("stripe_payment_intent_id", sa.String(), nullable=True),
sa.Column("amount", sa.Float(), nullable=False),
sa.Column("currency", sa.String(), nullable=True),
sa.Column("status", sa.String(), nullable=False),
sa.Column("customer_email", sa.String(), nullable=True),
sa.Column("customer_name", sa.String(), nullable=True),
sa.Column("description", sa.String(), nullable=True),
sa.Column("payment_metadata", sa.String(), nullable=True),
sa.Column(
"created_at",
sa.DateTime(timezone=True),
server_default=sa.text("(CURRENT_TIMESTAMP)"),
nullable=True,
),
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=True),
sa.Column("is_webhook_processed", sa.Boolean(), nullable=True),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(
op.f("ix_payments_customer_email"), "payments", ["customer_email"], unique=False
)
op.create_index(op.f("ix_payments_id"), "payments", ["id"], unique=False)
op.create_index(
op.f("ix_payments_stripe_payment_intent_id"),
"payments",
["stripe_payment_intent_id"],
unique=True,
)
# Create payment_methods table
op.create_table(
"payment_methods",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("stripe_payment_method_id", sa.String(), nullable=True),
sa.Column("customer_email", sa.String(), nullable=True),
sa.Column("type", sa.String(), nullable=False),
sa.Column("card_brand", sa.String(), nullable=True),
sa.Column("card_last_four", sa.String(), nullable=True),
sa.Column("is_default", sa.Boolean(), nullable=True),
sa.Column(
"created_at",
sa.DateTime(timezone=True),
server_default=sa.text("(CURRENT_TIMESTAMP)"),
nullable=True,
),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(
op.f("ix_payment_methods_customer_email"),
"payment_methods",
["customer_email"],
unique=False,
)
op.create_index(
op.f("ix_payment_methods_id"), "payment_methods", ["id"], unique=False
)
op.create_index(
op.f("ix_payment_methods_stripe_payment_method_id"),
"payment_methods",
["stripe_payment_method_id"],
unique=True,
)
def downgrade() -> None:
op.drop_index(
op.f("ix_payment_methods_stripe_payment_method_id"),
table_name="payment_methods",
)
op.drop_index(op.f("ix_payment_methods_id"), table_name="payment_methods")
op.drop_index(
op.f("ix_payment_methods_customer_email"), table_name="payment_methods"
)
op.drop_table("payment_methods")
op.drop_index(op.f("ix_payments_stripe_payment_intent_id"), table_name="payments")
op.drop_index(op.f("ix_payments_id"), table_name="payments")
op.drop_index(op.f("ix_payments_customer_email"), table_name="payments")
op.drop_table("payments")