Each children is essentually a type of transaction. We currently have: - bank transactions - money transactions - split transactions The table inheritance is implemented as a single table, with a polymorphic type and Null columns. Adds a IsSplit interface, which will later be used for the category views, so as to not repeat transactions.
75 lines
1.8 KiB
Python
75 lines
1.8 KiB
Python
"""Inheritance
|
|
|
|
Revision ID: 37d80de801a7
|
|
Revises: 8cc9870b0d74
|
|
Create Date: 2023-01-10 22:41:03.540108+00:00
|
|
|
|
"""
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision = "37d80de801a7"
|
|
down_revision = "8cc9870b0d74"
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
|
op.add_column(
|
|
"originals",
|
|
sa.Column("type", sa.String(), nullable=False),
|
|
schema="transactions",
|
|
)
|
|
op.add_column(
|
|
"originals",
|
|
sa.Column("split", sa.Boolean(), nullable=True),
|
|
schema="transactions",
|
|
)
|
|
op.add_column(
|
|
"originals",
|
|
sa.Column("original", sa.BigInteger(), nullable=True),
|
|
schema="transactions",
|
|
)
|
|
op.alter_column(
|
|
"originals",
|
|
"bank",
|
|
existing_type=sa.TEXT(),
|
|
nullable=True,
|
|
schema="transactions",
|
|
)
|
|
op.create_foreign_key(
|
|
op.f("fk_originals_original_originals"),
|
|
"originals",
|
|
"originals",
|
|
["original"],
|
|
["id"],
|
|
source_schema="transactions",
|
|
referent_schema="transactions",
|
|
ondelete="CASCADE",
|
|
)
|
|
# ### end Alembic commands ###
|
|
|
|
|
|
def downgrade() -> None:
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
|
op.drop_constraint(
|
|
op.f("fk_originals_original_originals"),
|
|
"originals",
|
|
schema="transactions",
|
|
type_="foreignkey",
|
|
)
|
|
op.alter_column(
|
|
"originals",
|
|
"bank",
|
|
existing_type=sa.TEXT(),
|
|
nullable=False,
|
|
schema="transactions",
|
|
)
|
|
op.drop_column("originals", "original", schema="transactions")
|
|
op.drop_column("originals", "split", schema="transactions")
|
|
op.drop_column("originals", "type", schema="transactions")
|
|
# ### end Alembic commands ###
|