Add weekly option on the schedule period

This commit is contained in:
Luís Murta 2022-12-08 16:44:07 +00:00
parent 72974c90aa
commit 6f97b883fb
Signed by: satprog
GPG Key ID: 169EF1BBD7049F94
2 changed files with 41 additions and 3 deletions

View File

@ -0,0 +1,37 @@
"""Weekly period
Revision ID: e77395969585
Revises: d18cbd50f7c6
Create Date: 2022-12-08 16:35:27.506504+00:00
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = "e77395969585"
down_revision = "d18cbd50f7c6"
branch_labels = None
depends_on = None
def upgrade() -> None:
op.execute("ALTER TYPE transactions.period ADD VALUE 'weekly' AFTER 'daily'")
def downgrade() -> None:
op.execute(
"""CREATE TYPE transactions.period_new
AS ENUM ('daily', 'monthly', 'yearly')
"""
)
op.execute("UPDATE transactions.categories_schedules SET period = DEFAULT WHERE period = 'weekly'")
op.execute(
"""ALTER TABLE transactions.categories_schedules
ALTER COLUMN period TYPE transactions.period_new
USING period::text::transactions.period_new
"""
)
op.execute("DROP TYPE transactions.period")
op.execute("ALTER TYPE transactions.period_new RENAME TO period")

View File

@ -204,9 +204,10 @@ class CategorySelector(Base):
class Period(enum.Enum): class Period(enum.Enum):
daily = enum.auto() daily = "daily"
monthly = enum.auto() weekly = "weekly"
yearly = enum.auto() monthly = "monthly"
yearly = "yearly"
scheduleperiod = Annotated[Selector, mapped_column(Enum(Period, inherit_schema=True))] scheduleperiod = Annotated[Selector, mapped_column(Enum(Period, inherit_schema=True))]