fix: fixed migration issues
This commit is contained in:
@@ -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.execute("DROP TYPE billstatus")
|
||||
# ### end Alembic commands ###
|
||||
op.drop_table('bills')
|
||||
op.execute("DROP TYPE billstatus")
|
||||
|
||||
Reference in New Issue
Block a user