[DB missing] Remove SQLAlchemy Enum
This commit is contained in:
parent
271130b107
commit
3698654715
48
alembic/versions/60469d5dd2b0_drop_sqlalchemy_enum.py
Normal file
48
alembic/versions/60469d5dd2b0_drop_sqlalchemy_enum.py
Normal file
@ -0,0 +1,48 @@
|
||||
"""Drop SQLAlchemy enum
|
||||
|
||||
Revision ID: 60469d5dd2b0
|
||||
Revises: b599dafcf468
|
||||
Create Date: 2023-05-15 19:24:07.911352+00:00
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "60469d5dd2b0"
|
||||
down_revision = "b599dafcf468"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.execute(
|
||||
"""
|
||||
CREATE TYPE pfbudget.scheduleperiod
|
||||
AS ENUM ('daily', 'weekly', 'monthly', 'yearly')
|
||||
"""
|
||||
)
|
||||
op.execute(
|
||||
"""ALTER TABLE pfbudget.category_schedules
|
||||
ALTER COLUMN period TYPE pfbudget.scheduleperiod
|
||||
USING period::text::pfbudget.scheduleperiod
|
||||
"""
|
||||
)
|
||||
op.execute("DROP TYPE pfbudget.period")
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.execute(
|
||||
"""
|
||||
CREATE TYPE pfbudget.period
|
||||
AS ENUM ('daily', 'weekly', 'monthly', 'yearly')
|
||||
"""
|
||||
)
|
||||
op.execute(
|
||||
"""ALTER TABLE pfbudget.category_schedules
|
||||
ALTER COLUMN period TYPE pfbudget.period
|
||||
USING period::text::pfbudget.period
|
||||
"""
|
||||
)
|
||||
op.execute("DROP TYPE pfbudget.scheduleperiod")
|
||||
@ -6,7 +6,7 @@ import os
|
||||
import re
|
||||
|
||||
from pfbudget.common.types import Operation
|
||||
from pfbudget.db.model import AccountType, Period
|
||||
from pfbudget.db.model import AccountType, SchedulePeriod
|
||||
|
||||
from pfbudget.db.sqlite import DatabaseClient
|
||||
import pfbudget.reporting.graph
|
||||
@ -269,7 +269,7 @@ def category(parser: argparse.ArgumentParser):
|
||||
schedule = commands.add_parser("schedule")
|
||||
schedule.set_defaults(op=Operation.CategorySchedule)
|
||||
schedule.add_argument("category", nargs="+", type=str)
|
||||
schedule.add_argument("period", nargs=1, choices=[e.value for e in Period])
|
||||
schedule.add_argument("period", nargs=1, choices=[e.value for e in SchedulePeriod])
|
||||
schedule.add_argument("--frequency", nargs=1, default=[1], type=int)
|
||||
|
||||
rule = commands.add_parser("rule")
|
||||
|
||||
@ -50,12 +50,6 @@ class AccountType(enum.Enum):
|
||||
MASTERCARD = enum.auto()
|
||||
|
||||
|
||||
accounttype = Annotated[
|
||||
AccountType,
|
||||
mapped_column(Enum(AccountType, inherit_schema=True)),
|
||||
]
|
||||
|
||||
|
||||
class Export:
|
||||
@property
|
||||
def format(self) -> dict[str, Any]:
|
||||
@ -67,7 +61,7 @@ class Bank(Base, Export):
|
||||
|
||||
name: Mapped[str] = mapped_column(primary_key=True)
|
||||
BIC: Mapped[str] = mapped_column(String(8))
|
||||
type: Mapped[accounttype]
|
||||
type: Mapped[AccountType]
|
||||
|
||||
nordigen: Mapped[Optional[Nordigen]] = relationship(init=False, lazy="joined")
|
||||
|
||||
@ -283,23 +277,18 @@ class TransactionTag(Base, Export, unsafe_hash=True):
|
||||
return dict(tag=self.tag)
|
||||
|
||||
|
||||
class Period(enum.Enum):
|
||||
daily = "daily"
|
||||
weekly = "weekly"
|
||||
monthly = "monthly"
|
||||
yearly = "yearly"
|
||||
|
||||
|
||||
scheduleperiod = Annotated[
|
||||
CategorySelector, mapped_column(Enum(Period, inherit_schema=True))
|
||||
]
|
||||
class SchedulePeriod(enum.Enum):
|
||||
daily = enum.auto()
|
||||
weekly = enum.auto()
|
||||
monthly = enum.auto()
|
||||
yearly = enum.auto()
|
||||
|
||||
|
||||
class CategorySchedule(Base, Export):
|
||||
__tablename__ = "category_schedules"
|
||||
|
||||
name: Mapped[catfk] = mapped_column(primary_key=True)
|
||||
period: Mapped[Optional[scheduleperiod]]
|
||||
period: Mapped[Optional[SchedulePeriod]]
|
||||
period_multiplier: Mapped[Optional[int]]
|
||||
amount: Mapped[Optional[int]]
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user