This patch extends the categories_rules with a rule for each field of a transaction. It also changes the ORM classes to behave as dataclasses again.
93 lines
2.9 KiB
Python
93 lines
2.9 KiB
Python
"""Transaction based rules
|
|
|
|
Revision ID: 8b5d5fbc8211
|
|
Revises: e77395969585
|
|
Create Date: 2022-12-08 21:05:41.378466+00:00
|
|
|
|
"""
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision = "8b5d5fbc8211"
|
|
down_revision = "e77395969585"
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.drop_constraint("pk_categories_rules", "categories_rules", schema="transactions")
|
|
op.execute(sa.schema.CreateSequence(sa.schema.Sequence("categories_rules_id_seq", schema="transactions")))
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
|
op.add_column(
|
|
"categories_rules",
|
|
sa.Column(
|
|
"id",
|
|
sa.BigInteger(),
|
|
autoincrement=True,
|
|
nullable=False,
|
|
server_default=sa.text(
|
|
"nextval('transactions.categories_rules_id_seq'::regclass)"
|
|
),
|
|
),
|
|
schema="transactions",
|
|
)
|
|
op.add_column(
|
|
"categories_rules",
|
|
sa.Column("date", sa.String(), nullable=True),
|
|
schema="transactions",
|
|
)
|
|
op.add_column(
|
|
"categories_rules",
|
|
sa.Column("description", sa.String(), nullable=True),
|
|
schema="transactions",
|
|
)
|
|
op.add_column(
|
|
"categories_rules",
|
|
sa.Column("bank", sa.String(), nullable=True),
|
|
schema="transactions",
|
|
)
|
|
op.add_column(
|
|
"categories_rules",
|
|
sa.Column("min_amount", sa.Float(), nullable=True),
|
|
schema="transactions",
|
|
)
|
|
op.add_column(
|
|
"categories_rules",
|
|
sa.Column("max_amount", sa.Float(), nullable=True),
|
|
schema="transactions",
|
|
)
|
|
op.drop_column("categories_rules", "rule", schema="transactions")
|
|
# ### end Alembic commands ###
|
|
op.create_primary_key(
|
|
"pk_categories_rules",
|
|
"categories_rules",
|
|
["id"],
|
|
schema="transactions",
|
|
)
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_constraint("pk_categories_rules", "categories_rules", schema="transactions")
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
|
op.add_column(
|
|
"categories_rules",
|
|
sa.Column("rule", sa.String(), autoincrement=False, nullable=False),
|
|
schema="transactions",
|
|
)
|
|
op.drop_column("categories_rules", "max_amount", schema="transactions")
|
|
op.drop_column("categories_rules", "min_amount", schema="transactions")
|
|
op.drop_column("categories_rules", "bank", schema="transactions")
|
|
op.drop_column("categories_rules", "description", schema="transactions")
|
|
op.drop_column("categories_rules", "date", schema="transactions")
|
|
op.drop_column("categories_rules", "id", schema="transactions")
|
|
# ### end Alembic commands ###
|
|
op.execute(sa.schema.DropSequence(sa.schema.Sequence("categories_rules_id_seq", schema="transactions")))
|
|
op.create_primary_key(
|
|
"pk_categories_rules",
|
|
"categories_rules",
|
|
["name", "rule"],
|
|
schema="transactions",
|
|
)
|