fix: fixed migration issues

This commit is contained in:
2026-04-27 22:07:35 +07:00
parent fc656c5944
commit 120e19e667
3 changed files with 66 additions and 30 deletions

View File

@@ -0,0 +1,34 @@
"""add columns for better sub tracking
Revision ID: 92dfa9b572f1
Revises: f0668f8e7310
Create Date: 2026-04-27 21:56:51.493795
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = '92dfa9b572f1'
down_revision: Union[str, Sequence[str], None] = 'f0668f8e7310'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
"""Upgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('subscriptions', sa.Column('plan_price_paid', sa.INTEGER(), nullable=False))
op.add_column('subscriptions', sa.Column('duration_days', sa.INTEGER(), nullable=False))
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('subscriptions', 'duration_days')
op.drop_column('subscriptions', 'plan_price_paid')
# ### end Alembic commands ###

View File

@@ -19,23 +19,25 @@ depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
"""Upgrade schema."""
# 1. Сначала создаем тип в базе данных
# Имя 'billstatus' должно совпадать с тем, что в ошибке
bind = op.get_bind()
if bind.dialect.name == 'postgresql':
op.execute("CREATE TYPE billstatus AS ENUM ('NEW', 'PROCESS', 'UNDERPAID', 'SUCCESS', 'OVERPAID', 'FAIL')")
# 2. Теперь добавляем колонку, которая использует этот тип
op.add_column('bills', sa.Column('status', sa.Enum('NEW', 'PROCESS', 'UNDERPAID', 'SUCCESS', 'OVERPAID', 'FAIL', name='billstatus'), nullable=False))
op.create_table(
'bills',
sa.Column('id', sa.BigInteger(), autoincrement=True, nullable=False),
sa.Column('creator_id', sa.BigInteger(), nullable=False),
sa.Column('amount', sa.Integer(), nullable=False),
sa.Column(
'status',
sa.Enum(
'NEW', 'PROCESS', 'UNDERPAID', 'SUCCESS', 'OVERPAID', 'FAIL',
name='billstatus',
),
nullable=False,
),
sa.ForeignKeyConstraint(['creator_id'], ['users.id']),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('id'),
)
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('bills', 'status')
bind = op.get_bind()
if bind.dialect.name == 'postgresql':
op.drop_table('bills')
op.execute("DROP TYPE billstatus")
# ### end Alembic commands ###

View File

@@ -19,21 +19,21 @@ depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
"""Upgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('subscriptions',
op.create_table(
'subscriptions',
sa.Column('user_id', sa.BIGINT(), nullable=False),
sa.Column('end_date', sa.DateTime(timezone=True), nullable=False),
sa.Column('autorenew', sa.Boolean(), nullable=False),
sa.Column('status', sa.Enum('EXPIRED', 'ACTIVE', name='subscriptionstatus'), nullable=False),
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('user_id')
sa.Column(
'status',
sa.Enum('expired', 'active', name='subscriptionstatus'),
nullable=False,
),
sa.ForeignKeyConstraint(['user_id'], ['users.id']),
sa.PrimaryKeyConstraint('user_id'),
)
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('subscriptions')
# ### end Alembic commands ###
op.execute("DROP TYPE subscriptionstatus")