From f41e0f05ec3e7c86f273812dd8cb5759fcdd0ab3 Mon Sep 17 00:00:00 2001 From: Katie Smith Date: Wed, 26 Sep 2018 15:09:13 +0100 Subject: [PATCH] Make postage column part of ft_billing primary key Now that the postage column is populated and there are no null values, it can be added to the composite primary key of ft_billing. --- app/models.py | 2 +- migrations/versions/0235_add_postage_to_pk.py | 39 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 migrations/versions/0235_add_postage_to_pk.py diff --git a/app/models.py b/app/models.py index 0752f8197..8702b0573 100644 --- a/app/models.py +++ b/app/models.py @@ -1811,7 +1811,7 @@ class FactBilling(db.Model): rate_multiplier = db.Column(db.Integer(), nullable=False, primary_key=True) international = db.Column(db.Boolean, nullable=False, primary_key=True) rate = db.Column(db.Numeric(), nullable=False, primary_key=True) - postage = db.Column(db.String) + postage = db.Column(db.String, nullable=False, primary_key=True) billable_units = db.Column(db.Integer(), nullable=True) notifications_sent = db.Column(db.Integer(), nullable=True) created_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.utcnow) diff --git a/migrations/versions/0235_add_postage_to_pk.py b/migrations/versions/0235_add_postage_to_pk.py new file mode 100644 index 000000000..072f2646e --- /dev/null +++ b/migrations/versions/0235_add_postage_to_pk.py @@ -0,0 +1,39 @@ +""" + +Revision ID: 0235_add_postage_to_pk +Revises: 0234_ft_billing_postage +Create Date: 2018-09-28 15:39:21.115358 + +""" +from alembic import op +import sqlalchemy as sa + + +revision = '0235_add_postage_to_pk' +down_revision = '0234_ft_billing_postage' + + +def upgrade(): + op.drop_constraint('ft_billing_pkey', 'ft_billing', type_='primary') + op.create_primary_key('ft_billing_pkey', 'ft_billing', ['bst_date', + 'template_id', + 'service_id', + 'notification_type', + 'provider', + 'rate_multiplier', + 'international', + 'rate', + 'postage']) + + +def downgrade(): + op.drop_constraint('ft_billing_pkey', 'ft_billing', type_='primary') + op.alter_column('ft_billing', 'postage', nullable=True) + op.create_primary_key('ft_billing_pkey', 'ft_billing', ['bst_date', + 'template_id', + 'service_id', + 'notification_type', + 'provider', + 'rate_multiplier', + 'international', + 'rate'])