diff --git a/app/dao/fact_billing_dao.py b/app/dao/fact_billing_dao.py index 0f284a2e5..b460153f5 100644 --- a/app/dao/fact_billing_dao.py +++ b/app/dao/fact_billing_dao.py @@ -222,13 +222,7 @@ def update_fact_billing(data, process_day): ) stmt = stmt.on_conflict_do_update( - index_elements=[table.c.bst_date, - table.c.template_id, - table.c.service_id, - table.c.provider, - table.c.rate_multiplier, - table.c.notification_type, - table.c.international], + constraint="ft_billing_pkey", set_={"notifications_sent": stmt.excluded.notifications_sent, "billable_units": stmt.excluded.billable_units } diff --git a/migrations/versions/0191_ft_billing_pkey.py b/migrations/versions/0191_ft_billing_pkey.py new file mode 100644 index 000000000..80093083c --- /dev/null +++ b/migrations/versions/0191_ft_billing_pkey.py @@ -0,0 +1,29 @@ +""" + +Revision ID: 0191_ft_billing_pkey +Revises: 0190_another_letter_org +Create Date: 2018-05-21 14:24:27.229511 + +""" +from alembic import op + +revision = '0191_ft_billing_pkey' +down_revision = '0190_another_letter_org' + + +def upgrade(): + op.get_bind() + op.execute("ALTER TABLE ft_billing DROP CONSTRAINT ft_billing_pkey") + sql = """ALTER TABLE ft_billing ADD CONSTRAINT + ft_billing_pkey PRIMARY KEY + (bst_date, template_id, service_id, rate_multiplier, provider, notification_type, international, rate)""" + op.execute(sql) + + +def downgrade(): + op.get_bind() + op.execute("ALTER TABLE ft_billing DROP CONSTRAINT ft_billing_pkey") + sql = """ALTER TABLE ft_billing ADD CONSTRAINT + ft_billing_pkey PRIMARY KEY + (bst_date, template_id, service_id, rate_multiplier, provider, notification_type, international)""" + op.execute(sql) \ No newline at end of file