53 lines
1.6 KiB
Python
53 lines
1.6 KiB
Python
"""transaction refact
|
|
|
|
Revision ID: 5ea1426af0d0
|
|
Revises: 3b61a6fbc6b2
|
|
Create Date: 2026-05-17 11:34:08.045462
|
|
|
|
"""
|
|
|
|
from typing import Sequence, Union
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision: str = "5ea1426af0d0"
|
|
down_revision: Union[str, Sequence[str], None] = "3b61a6fbc6b2"
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
"""Upgrade schema."""
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
|
op.add_column(
|
|
"aps_transaction",
|
|
sa.Column("_total_amount", sa.Numeric(precision=10, scale=2), nullable=True),
|
|
)
|
|
# copy data from total_amount to _total_amount
|
|
conn = op.get_bind()
|
|
transactions = conn.execute(
|
|
sa.text("SELECT id, total_amount FROM aps_transaction")
|
|
).fetchall()
|
|
for transaction in transactions:
|
|
conn.execute(
|
|
sa.text(
|
|
"UPDATE aps_transaction SET _total_amount = :total_amount WHERE id = :id"
|
|
),
|
|
{"total_amount": transaction.total_amount, "id": transaction.id},
|
|
)
|
|
op.drop_column("aps_transaction", "total_amount")
|
|
# ### end Alembic commands ###
|
|
|
|
|
|
def downgrade() -> None:
|
|
"""Downgrade schema."""
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
|
op.add_column(
|
|
"aps_transaction",
|
|
sa.Column("total_amount", sa.NUMERIC(precision=10, scale=2), nullable=False),
|
|
)
|
|
op.drop_column("aps_transaction", "_total_amount")
|
|
# ### end Alembic commands ###
|