All meal card to account type enum

This commit is contained in:
Luís Murta 2022-12-03 12:54:22 +00:00
parent 0d22b02b3f
commit 246c948d76
Signed by: satprog
GPG Key ID: 169EF1BBD7049F94
2 changed files with 37 additions and 0 deletions

View File

@ -0,0 +1,36 @@
"""Add meal card
Revision ID: d3534f493239
Revises: 50ff1fbb8a00
Create Date: 2022-12-03 12:18:33.519666+00:00
"""
from alembic import op
# revision identifiers, used by Alembic.
revision = "d3534f493239"
down_revision = "50ff1fbb8a00"
branch_labels = None
depends_on = None
def upgrade() -> None:
op.execute("ALTER TYPE transactions.accounttype ADD VALUE 'mealcard' BEFORE 'VISA'")
def downgrade() -> None:
op.execute(
"""CREATE TYPE transactions.accounttype_new
AS ENUM ('checking', 'savings', 'investment', 'VISA', 'MASTERCARD')
"""
)
op.execute("UPDATE transactions.banks SET type = DEFAULT WHERE type = 'mealcard'")
op.execute(
"""ALTER TABLE transactions.banks
ALTER COLUMN type TYPE transactions.accounttype_new
USING type::text::transactions.accounttype_new
"""
)
op.execute("DROP TYPE transactions.accounttype")
op.execute("ALTER TYPE transactions.accounttype_new RENAME TO accounttype")

View File

@ -32,6 +32,7 @@ class AccountType(enum.Enum):
checking = enum.auto()
savings = enum.auto()
investment = enum.auto()
mealcard = enum.auto()
VISA = enum.auto()
MASTERCARD = enum.auto()