diff options
| author | dark0dave <52840419+dark0dave@users.noreply.github.com> | 2020-04-29 21:57:08 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-04-29 22:57:08 +0200 |
| commit | f389c562595f74bea86e49c29949f4a7b0e78900 (patch) | |
| tree | c3c0ac339ad002f47e2be9cd3a46d347012b1d70 /ihatemoney/migrations/versions | |
| parent | 162193c787341118621b36b4c8933bbe8af092df (diff) | |
| download | ihatemoney-mirror-f389c562595f74bea86e49c29949f4a7b0e78900.zip ihatemoney-mirror-f389c562595f74bea86e49c29949f4a7b0e78900.tar.gz ihatemoney-mirror-f389c562595f74bea86e49c29949f4a7b0e78900.tar.bz2 | |
Feature/currencies (#541)
Now each project can have a currency, default to None.
Each bill can use a different currency, and a conversion to project default currency is done on settle.
Fix #512
Diffstat (limited to 'ihatemoney/migrations/versions')
| -rw-r--r-- | ihatemoney/migrations/versions/927ed575acbd_add_currencies.py | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/ihatemoney/migrations/versions/927ed575acbd_add_currencies.py b/ihatemoney/migrations/versions/927ed575acbd_add_currencies.py new file mode 100644 index 0000000..b70d902 --- /dev/null +++ b/ihatemoney/migrations/versions/927ed575acbd_add_currencies.py @@ -0,0 +1,73 @@ +"""Add currencies + +Revision ID: 927ed575acbd +Revises: cb038f79982e +Create Date: 2020-04-25 14:49:41.136602 + +""" + +# revision identifiers, used by Alembic. +revision = "927ed575acbd" +down_revision = "cb038f79982e" + +from alembic import op +import sqlalchemy as sa +from ihatemoney.currency_convertor import CurrencyConverter + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column("bill", sa.Column("converted_amount", sa.Float(), nullable=True)) + op.add_column( + "bill", + sa.Column( + "original_currency", + sa.String(length=3), + server_default=CurrencyConverter.default, + nullable=True, + ), + ) + op.add_column( + "bill_version", + sa.Column("converted_amount", sa.Float(), autoincrement=False, nullable=True), + ) + op.add_column( + "bill_version", + sa.Column( + "original_currency", sa.String(length=3), autoincrement=False, nullable=True + ), + ) + op.add_column( + "project", + sa.Column( + "default_currency", + sa.String(length=3), + server_default=CurrencyConverter.default, + nullable=True, + ), + ) + op.add_column( + "project_version", + sa.Column( + "default_currency", sa.String(length=3), autoincrement=False, nullable=True + ), + ) + # ### end Alembic commands ### + op.execute( + """ + UPDATE bill + SET converted_amount = amount + WHERE converted_amount IS NULL + """ + ) + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column("project_version", "default_currency") + op.drop_column("project", "default_currency") + op.drop_column("bill_version", "original_currency") + op.drop_column("bill_version", "converted_amount") + op.drop_column("bill", "original_currency") + op.drop_column("bill", "converted_amount") + # ### end Alembic commands ### |
