Complete CarPass product flows

This commit is contained in:
VPN SaaS Dev
2026-05-14 21:19:37 +09:00
parent a83f55c646
commit c0014ab4ea
28 changed files with 3006 additions and 159 deletions

View File

@@ -0,0 +1,112 @@
"""vehicle finance odometer moderation
Revision ID: 202605140002
Revises: 202605140001
Create Date: 2026-05-14 08:00:00.000000
"""
from collections.abc import Sequence
import sqlalchemy as sa
from alembic import op
revision: str = "202605140002"
down_revision: str | None = "202605140001"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None
def upgrade() -> None:
op.add_column("cars", sa.Column("generation", sa.String(length=120), nullable=True))
op.add_column("cars", sa.Column("body_type", sa.String(length=80), nullable=True))
op.add_column("cars", sa.Column("engine_volume_l", sa.Numeric(5, 2), nullable=True))
op.add_column("cars", sa.Column("transmission", sa.String(length=40), nullable=True))
op.add_column("cars", sa.Column("drive_type", sa.String(length=40), nullable=True))
op.add_column("cars", sa.Column("tire_size", sa.String(length=80), nullable=True))
op.add_column("cars", sa.Column("oil_change_interval_km", sa.Integer(), nullable=True))
op.add_column("cars", sa.Column("oil_change_interval_months", sa.Integer(), nullable=True))
op.add_column("cars", sa.Column("purchase_currency", sa.String(length=3), nullable=True))
op.add_column("cars", sa.Column("purchase_type", sa.String(length=24), server_default="unknown", nullable=False))
op.add_column("cars", sa.Column("expected_ownership_months", sa.Integer(), nullable=True))
op.add_column("cars", sa.Column("expected_residual_value", sa.Numeric(12, 2), nullable=True))
op.add_column("cars", sa.Column("loan_principal", sa.Numeric(12, 2), nullable=True))
op.add_column("cars", sa.Column("loan_down_payment", sa.Numeric(12, 2), nullable=True))
op.add_column("cars", sa.Column("loan_term_months", sa.Integer(), nullable=True))
op.add_column("cars", sa.Column("loan_annual_interest_rate", sa.Numeric(6, 3), nullable=True))
op.add_column("cars", sa.Column("loan_first_payment_date", sa.Date(), nullable=True))
op.add_column("cars", sa.Column("loan_payment_day", sa.Integer(), nullable=True))
op.add_column("cars", sa.Column("loan_payment_type", sa.String(length=24), server_default="annuity", nullable=False))
op.add_column("cars", sa.Column("loan_currency", sa.String(length=3), nullable=True))
op.add_column("cars", sa.Column("loan_comment", sa.Text(), nullable=True))
op.add_column("cars", sa.Column("notes", sa.Text(), nullable=True))
op.alter_column("fuel_entries", "is_full_tank", existing_type=sa.Boolean(), nullable=True)
op.add_column("expense_entries", sa.Column("policy_number", sa.String(length=120), nullable=True))
op.add_column("expense_entries", sa.Column("insurance_type", sa.String(length=40), nullable=True))
op.add_column("expense_entries", sa.Column("payment_period_months", sa.Integer(), nullable=True))
op.add_column("expense_entries", sa.Column("document_urls", sa.JSON(), nullable=True))
op.add_column("expense_entries", sa.Column("metadata_json", sa.JSON(), nullable=True))
op.create_table(
"odometer_history",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("car_id", sa.Integer(), nullable=False),
sa.Column("previous_odometer", sa.Integer(), nullable=True),
sa.Column("new_odometer", sa.Integer(), nullable=False),
sa.Column("source_record_type", sa.String(length=40), nullable=False),
sa.Column("source_record_id", sa.Integer(), nullable=True),
sa.Column("changed_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
sa.Column("changed_by", sa.Integer(), nullable=True),
sa.Column("confirmation_required", sa.Boolean(), server_default=sa.text("false"), nullable=False),
sa.Column("user_confirmed", sa.Boolean(), server_default=sa.text("true"), nullable=False),
sa.ForeignKeyConstraint(["car_id"], ["cars.id"], ondelete="CASCADE"),
sa.ForeignKeyConstraint(["changed_by"], ["users.id"], ondelete="SET NULL"),
sa.PrimaryKeyConstraint("id"),
)
op.create_index("ix_odometer_history_car_id", "odometer_history", ["car_id"])
op.create_index("ix_odometer_history_changed_at", "odometer_history", ["changed_at"])
op.create_index("ix_odometer_history_changed_by", "odometer_history", ["changed_by"])
op.create_index("ix_odometer_history_source_record_id", "odometer_history", ["source_record_id"])
op.create_index("ix_odometer_history_source_record_type", "odometer_history", ["source_record_type"])
def downgrade() -> None:
op.drop_index("ix_odometer_history_source_record_type", table_name="odometer_history")
op.drop_index("ix_odometer_history_source_record_id", table_name="odometer_history")
op.drop_index("ix_odometer_history_changed_by", table_name="odometer_history")
op.drop_index("ix_odometer_history_changed_at", table_name="odometer_history")
op.drop_index("ix_odometer_history_car_id", table_name="odometer_history")
op.drop_table("odometer_history")
op.drop_column("expense_entries", "metadata_json")
op.drop_column("expense_entries", "document_urls")
op.drop_column("expense_entries", "payment_period_months")
op.drop_column("expense_entries", "insurance_type")
op.drop_column("expense_entries", "policy_number")
op.alter_column("fuel_entries", "is_full_tank", existing_type=sa.Boolean(), nullable=False)
op.drop_column("cars", "notes")
op.drop_column("cars", "loan_comment")
op.drop_column("cars", "loan_currency")
op.drop_column("cars", "loan_payment_type")
op.drop_column("cars", "loan_payment_day")
op.drop_column("cars", "loan_first_payment_date")
op.drop_column("cars", "loan_annual_interest_rate")
op.drop_column("cars", "loan_term_months")
op.drop_column("cars", "loan_down_payment")
op.drop_column("cars", "loan_principal")
op.drop_column("cars", "expected_residual_value")
op.drop_column("cars", "expected_ownership_months")
op.drop_column("cars", "purchase_type")
op.drop_column("cars", "purchase_currency")
op.drop_column("cars", "oil_change_interval_months")
op.drop_column("cars", "oil_change_interval_km")
op.drop_column("cars", "tire_size")
op.drop_column("cars", "drive_type")
op.drop_column("cars", "transmission")
op.drop_column("cars", "engine_volume_l")
op.drop_column("cars", "body_type")
op.drop_column("cars", "generation")