Add the alembic automated migration (needs rework)

This commit is contained in:
Alexis Métaireau 2024-12-27 00:26:32 +01:00
parent 04b18a8d3d
commit 8791cc856a
No known key found for this signature in database
GPG key ID: 1C21B876828E5FF2

View file

@ -0,0 +1,78 @@
"""remove currencies
Revision ID: 3334e1f293b4
Revises: 7a9b38559992
Create Date: 2024-12-27 00:25:06.517970
"""
# revision identifiers, used by Alembic.
revision = '3334e1f293b4'
down_revision = '7a9b38559992'
from alembic import op
import sqlalchemy as sa
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('bill', schema=None) as batch_op:
batch_op.drop_column('converted_amount')
batch_op.drop_column('original_currency')
with op.batch_alter_table('bill_version', schema=None) as batch_op:
batch_op.alter_column('bill_type',
existing_type=sa.TEXT(),
type_=sa.Enum('EXPENSE', 'REIMBURSEMENT', name='billtype'),
existing_nullable=True,
autoincrement=False)
batch_op.drop_column('converted_amount')
batch_op.drop_column('original_currency')
with op.batch_alter_table('billowers', schema=None) as batch_op:
batch_op.alter_column('bill_id',
existing_type=sa.INTEGER(),
nullable=False)
batch_op.alter_column('person_id',
existing_type=sa.INTEGER(),
nullable=False)
with op.batch_alter_table('project', schema=None) as batch_op:
batch_op.drop_column('default_currency')
with op.batch_alter_table('project_version', schema=None) as batch_op:
batch_op.drop_column('default_currency')
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('project_version', schema=None) as batch_op:
batch_op.add_column(sa.Column('default_currency', sa.VARCHAR(length=3), nullable=True))
with op.batch_alter_table('project', schema=None) as batch_op:
batch_op.add_column(sa.Column('default_currency', sa.VARCHAR(length=3), server_default=sa.text("('')"), nullable=True))
with op.batch_alter_table('billowers', schema=None) as batch_op:
batch_op.alter_column('person_id',
existing_type=sa.INTEGER(),
nullable=True)
batch_op.alter_column('bill_id',
existing_type=sa.INTEGER(),
nullable=True)
with op.batch_alter_table('bill_version', schema=None) as batch_op:
batch_op.add_column(sa.Column('original_currency', sa.VARCHAR(length=3), nullable=True))
batch_op.add_column(sa.Column('converted_amount', sa.FLOAT(), nullable=True))
batch_op.alter_column('bill_type',
existing_type=sa.Enum('EXPENSE', 'REIMBURSEMENT', name='billtype'),
type_=sa.TEXT(),
existing_nullable=True,
autoincrement=False)
with op.batch_alter_table('bill', schema=None) as batch_op:
batch_op.add_column(sa.Column('original_currency', sa.VARCHAR(length=3), server_default=sa.text("('')"), nullable=True))
batch_op.add_column(sa.Column('converted_amount', sa.FLOAT(), nullable=True))
# ### end Alembic commands ###