From 2bb1e61f8ab03946c836b52d50e2356978d6684d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20M=C3=A9taireau?= Date: Fri, 27 Dec 2024 00:26:32 +0100 Subject: [PATCH] Add the alembic automated migration (needs rework) --- .../3334e1f293b4_remove_currencies.py | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 ihatemoney/migrations/versions/3334e1f293b4_remove_currencies.py diff --git a/ihatemoney/migrations/versions/3334e1f293b4_remove_currencies.py b/ihatemoney/migrations/versions/3334e1f293b4_remove_currencies.py new file mode 100644 index 000000000..3e1e0f1e4 --- /dev/null +++ b/ihatemoney/migrations/versions/3334e1f293b4_remove_currencies.py @@ -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 ###