fix: fixed migration issues
This commit is contained in:
@@ -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 ###
|
||||||
@@ -19,23 +19,25 @@ depends_on: Union[str, Sequence[str], None] = None
|
|||||||
|
|
||||||
|
|
||||||
def upgrade() -> None:
|
def upgrade() -> None:
|
||||||
"""Upgrade schema."""
|
op.create_table(
|
||||||
# 1. Сначала создаем тип в базе данных
|
'bills',
|
||||||
# Имя 'billstatus' должно совпадать с тем, что в ошибке
|
sa.Column('id', sa.BigInteger(), autoincrement=True, nullable=False),
|
||||||
bind = op.get_bind()
|
sa.Column('creator_id', sa.BigInteger(), nullable=False),
|
||||||
if bind.dialect.name == 'postgresql':
|
sa.Column('amount', sa.Integer(), nullable=False),
|
||||||
op.execute("CREATE TYPE billstatus AS ENUM ('NEW', 'PROCESS', 'UNDERPAID', 'SUCCESS', 'OVERPAID', 'FAIL')")
|
sa.Column(
|
||||||
|
'status',
|
||||||
# 2. Теперь добавляем колонку, которая использует этот тип
|
sa.Enum(
|
||||||
op.add_column('bills', sa.Column('status', sa.Enum('NEW', 'PROCESS', 'UNDERPAID', 'SUCCESS', 'OVERPAID', 'FAIL', name='billstatus'), nullable=False))
|
'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:
|
def downgrade() -> None:
|
||||||
"""Downgrade schema."""
|
op.drop_table('bills')
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
op.execute("DROP TYPE billstatus")
|
||||||
op.drop_column('bills', 'status')
|
|
||||||
|
|
||||||
bind = op.get_bind()
|
|
||||||
if bind.dialect.name == 'postgresql':
|
|
||||||
op.execute("DROP TYPE billstatus")
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
|
|||||||
@@ -19,21 +19,21 @@ depends_on: Union[str, Sequence[str], None] = None
|
|||||||
|
|
||||||
|
|
||||||
def upgrade() -> None:
|
def upgrade() -> None:
|
||||||
"""Upgrade schema."""
|
op.create_table(
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
'subscriptions',
|
||||||
op.create_table('subscriptions',
|
sa.Column('user_id', sa.BIGINT(), nullable=False),
|
||||||
sa.Column('user_id', sa.BIGINT(), nullable=False),
|
sa.Column('end_date', sa.DateTime(timezone=True), nullable=False),
|
||||||
sa.Column('end_date', sa.DateTime(timezone=True), nullable=False),
|
sa.Column('autorenew', sa.Boolean(), nullable=False),
|
||||||
sa.Column('autorenew', sa.Boolean(), nullable=False),
|
sa.Column(
|
||||||
sa.Column('status', sa.Enum('EXPIRED', 'ACTIVE', name='subscriptionstatus'), nullable=False),
|
'status',
|
||||||
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
|
sa.Enum('expired', 'active', name='subscriptionstatus'),
|
||||||
sa.PrimaryKeyConstraint('user_id')
|
nullable=False,
|
||||||
|
),
|
||||||
|
sa.ForeignKeyConstraint(['user_id'], ['users.id']),
|
||||||
|
sa.PrimaryKeyConstraint('user_id'),
|
||||||
)
|
)
|
||||||
# ### end Alembic commands ###
|
|
||||||
|
|
||||||
|
|
||||||
def downgrade() -> None:
|
def downgrade() -> None:
|
||||||
"""Downgrade schema."""
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
op.drop_table('subscriptions')
|
op.drop_table('subscriptions')
|
||||||
# ### end Alembic commands ###
|
op.execute("DROP TYPE subscriptionstatus")
|
||||||
|
|||||||
Reference in New Issue
Block a user