"""create fee tables Revision ID: 20240501_000006 Revises: 20240501_000005 Create Date: 2025-02-14 00:00:00 """ from alembic import op import sqlalchemy as sa revision = "20240501_000006" down_revision = "20240501_000005" branch_labels = None depends_on = None def upgrade() -> None: op.create_table( "contract_fees", sa.Column("id", sa.dialects.postgresql.UUID(as_uuid=True), primary_key=True), sa.Column("project_id", sa.dialects.postgresql.UUID(as_uuid=True), nullable=False), sa.Column("center_id", sa.dialects.postgresql.UUID(as_uuid=True), nullable=False), sa.Column("contract_amount", sa.Numeric(12, 2), nullable=False), sa.Column("contract_cases", sa.Integer(), nullable=False), sa.Column("actual_cases", sa.Integer(), nullable=True), sa.Column("settlement_amount", sa.Numeric(12, 2), nullable=True), sa.Column("final_payment_amount", sa.Numeric(12, 2), nullable=True), sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=False), sa.Column("updated_at", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=False), sa.ForeignKeyConstraint(["project_id"], ["studies.id"], ondelete="RESTRICT"), sa.ForeignKeyConstraint(["center_id"], ["sites.id"], ondelete="RESTRICT"), sa.UniqueConstraint("project_id", "center_id", name="uq_contract_fees_project_center"), ) op.create_index("ix_contract_fees_project_id", "contract_fees", ["project_id"]) op.create_index("ix_contract_fees_center_id", "contract_fees", ["center_id"]) op.create_table( "contract_fee_payments", sa.Column("id", sa.dialects.postgresql.UUID(as_uuid=True), primary_key=True), sa.Column("contract_fee_id", sa.dialects.postgresql.UUID(as_uuid=True), nullable=False), sa.Column("seq", sa.Integer(), nullable=False), sa.Column("amount", sa.Numeric(12, 2), nullable=False), sa.Column("paid_date", sa.Date(), nullable=True), sa.Column("verified_date", sa.Date(), nullable=True), sa.Column("is_paid", sa.Boolean(), server_default=sa.text("false"), nullable=False), sa.Column("is_verified", sa.Boolean(), server_default=sa.text("false"), nullable=False), sa.Column("remark", sa.Text(), nullable=True), sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=False), sa.Column("updated_at", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=False), sa.ForeignKeyConstraint(["contract_fee_id"], ["contract_fees.id"], ondelete="CASCADE"), ) op.create_index("ix_contract_fee_payments_contract_fee_id", "contract_fee_payments", ["contract_fee_id"]) op.create_table( "special_expenses", sa.Column("id", sa.dialects.postgresql.UUID(as_uuid=True), primary_key=True), sa.Column("project_id", sa.dialects.postgresql.UUID(as_uuid=True), nullable=False), sa.Column("center_id", sa.dialects.postgresql.UUID(as_uuid=True), nullable=True), sa.Column("category", sa.String(50), nullable=False), sa.Column("amount", sa.Numeric(12, 2), nullable=False), sa.Column("happen_date", sa.Date(), nullable=True), sa.Column("description", sa.Text(), nullable=True), sa.Column("is_paid", sa.Boolean(), server_default=sa.text("false"), nullable=False), sa.Column("paid_date", sa.Date(), nullable=True), sa.Column("is_verified", sa.Boolean(), server_default=sa.text("false"), nullable=False), sa.Column("verified_date", sa.Date(), nullable=True), sa.Column("created_by", sa.dialects.postgresql.UUID(as_uuid=True), nullable=True), sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=False), sa.Column("updated_at", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=False), sa.ForeignKeyConstraint(["project_id"], ["studies.id"], ondelete="RESTRICT"), sa.ForeignKeyConstraint(["center_id"], ["sites.id"], ondelete="RESTRICT"), sa.ForeignKeyConstraint(["created_by"], ["users.id"], ondelete="RESTRICT"), ) op.create_index("ix_special_expenses_project_id", "special_expenses", ["project_id"]) op.create_index("ix_special_expenses_center_id", "special_expenses", ["center_id"]) op.create_table( "fee_attachments", sa.Column("id", sa.dialects.postgresql.UUID(as_uuid=True), primary_key=True), sa.Column("entity_type", sa.String(50), nullable=False), sa.Column("entity_id", sa.dialects.postgresql.UUID(as_uuid=True), nullable=False), sa.Column("file_type", sa.String(30), nullable=False), sa.Column("filename", sa.String(255), nullable=False), sa.Column("mime_type", sa.String(100), nullable=True), sa.Column("size", sa.Integer(), nullable=False), sa.Column("storage_key", sa.String(500), nullable=True), sa.Column("url", sa.Text(), nullable=True), sa.Column("uploaded_by", sa.dialects.postgresql.UUID(as_uuid=True), nullable=False), sa.Column("uploaded_at", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=False), sa.Column("is_deleted", sa.Boolean(), server_default=sa.text("false"), nullable=False), sa.ForeignKeyConstraint(["uploaded_by"], ["users.id"], ondelete="RESTRICT"), ) def downgrade() -> None: op.drop_table("fee_attachments") op.drop_index("ix_special_expenses_center_id", table_name="special_expenses") op.drop_index("ix_special_expenses_project_id", table_name="special_expenses") op.drop_table("special_expenses") op.drop_index("ix_contract_fee_payments_contract_fee_id", table_name="contract_fee_payments") op.drop_table("contract_fee_payments") op.drop_index("ix_contract_fees_center_id", table_name="contract_fees") op.drop_index("ix_contract_fees_project_id", table_name="contract_fees") op.drop_table("contract_fees")