mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-23 15:56:45 -04:00
primary key for ft_billing should use notification_type
This commit is contained in:
@@ -13,6 +13,7 @@ from sqlalchemy import func, desc, case
|
|||||||
from app.dao.dao_utils import transactional
|
from app.dao.dao_utils import transactional
|
||||||
from notifications_utils.statsd_decorators import statsd
|
from notifications_utils.statsd_decorators import statsd
|
||||||
from app import notify_celery
|
from app import notify_celery
|
||||||
|
from flask import current_app
|
||||||
|
|
||||||
|
|
||||||
def get_rate(non_letter_rates, letter_rates, notification_type, date, crown=None, rate_multiplier=None):
|
def get_rate(non_letter_rates, letter_rates, notification_type, date, crown=None, rate_multiplier=None):
|
||||||
@@ -76,13 +77,16 @@ def create_nightly_billing(day_start=None):
|
|||||||
'day_created'
|
'day_created'
|
||||||
).all()
|
).all()
|
||||||
|
|
||||||
|
updated_records = 0
|
||||||
|
inserted_records = 0
|
||||||
|
|
||||||
for data in transit_data:
|
for data in transit_data:
|
||||||
update_count = FactBilling.query.filter(
|
update_count = FactBilling.query.filter(
|
||||||
FactBilling.bst_date == data.day_created,
|
FactBilling.bst_date == data.day_created,
|
||||||
FactBilling.template_id == data.template_id,
|
FactBilling.template_id == data.template_id,
|
||||||
FactBilling.provider == data.sent_by, # This could be zero - this is a bug that needs to be fixed.
|
FactBilling.provider == data.sent_by, # This could be zero - this is a bug that needs to be fixed.
|
||||||
FactBilling.rate_multiplier == data.rate_multiplier,
|
FactBilling.rate_multiplier == data.rate_multiplier,
|
||||||
FactBilling.international == data.international,
|
FactBilling.notification_type == data.notification_type,
|
||||||
).update(
|
).update(
|
||||||
{"notifications_sent": data.notifications_sent,
|
{"notifications_sent": data.notifications_sent,
|
||||||
"billable_units": data.billable_units},
|
"billable_units": data.billable_units},
|
||||||
@@ -106,3 +110,9 @@ def create_nightly_billing(day_start=None):
|
|||||||
data.rate_multiplier)
|
data.rate_multiplier)
|
||||||
)
|
)
|
||||||
db.session.add(billing_record)
|
db.session.add(billing_record)
|
||||||
|
inserted_records += 1
|
||||||
|
|
||||||
|
updated_records += update_count
|
||||||
|
|
||||||
|
current_app.logger.info('ft_billing: {} rows updated, {} rows inserted'
|
||||||
|
.format(updated_records, inserted_records))
|
||||||
|
|||||||
@@ -1774,10 +1774,10 @@ class FactBilling(db.Model):
|
|||||||
bst_date = db.Column(db.Date, nullable=False, primary_key=True, index=True)
|
bst_date = db.Column(db.Date, nullable=False, primary_key=True, index=True)
|
||||||
template_id = db.Column(UUID(as_uuid=True), nullable=False, primary_key=True, index=True)
|
template_id = db.Column(UUID(as_uuid=True), nullable=False, primary_key=True, index=True)
|
||||||
service_id = db.Column(UUID(as_uuid=True), nullable=False, index=True)
|
service_id = db.Column(UUID(as_uuid=True), nullable=False, index=True)
|
||||||
notification_type = db.Column(db.Text, nullable=True)
|
notification_type = db.Column(db.Text, nullable=False, primary_key=True)
|
||||||
provider = db.Column(db.Text, nullable=True, primary_key=True)
|
provider = db.Column(db.Text, nullable=True, primary_key=True)
|
||||||
rate_multiplier = db.Column(db.Numeric(), nullable=True, primary_key=True)
|
rate_multiplier = db.Column(db.Numeric(), nullable=True, primary_key=True)
|
||||||
international = db.Column(db.Boolean, nullable=True, primary_key=True)
|
international = db.Column(db.Boolean, nullable=False, primary_key=False)
|
||||||
rate = db.Column(db.Numeric(), nullable=True)
|
rate = db.Column(db.Numeric(), nullable=True)
|
||||||
billable_units = db.Column(db.Numeric(), nullable=True)
|
billable_units = db.Column(db.Numeric(), nullable=True)
|
||||||
notifications_sent = db.Column(db.Integer(), nullable=True)
|
notifications_sent = db.Column(db.Integer(), nullable=True)
|
||||||
|
|||||||
43
migrations/versions/0181_billing_primary_key.py
Normal file
43
migrations/versions/0181_billing_primary_key.py
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
"""
|
||||||
|
|
||||||
|
Revision ID: 0181_billing_primary_key
|
||||||
|
Revises: 0180_another_letter_org
|
||||||
|
Create Date: 2018-03-21 13:41:26.203712
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
from sqlalchemy.dialects import postgresql
|
||||||
|
|
||||||
|
revision = '0181_billing_primary_key'
|
||||||
|
down_revision = '0180_another_letter_org'
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
op.alter_column('ft_billing', 'service_id',
|
||||||
|
existing_type=postgresql.UUID(),
|
||||||
|
nullable=False)
|
||||||
|
op.drop_constraint('ft_billing_pkey', 'ft_billing', type_='primary')
|
||||||
|
|
||||||
|
op.create_primary_key('ft_billing_pkey', 'ft_billing', ['bst_date',
|
||||||
|
'template_id',
|
||||||
|
'rate_multiplier',
|
||||||
|
'provider',
|
||||||
|
'notification_type'])
|
||||||
|
op.create_index(op.f('ix_ft_billing_template_id'), 'ft_billing', ['template_id'], unique=False)
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
op.alter_column('ft_billing', 'service_id',
|
||||||
|
existing_type=postgresql.UUID(),
|
||||||
|
nullable=True)
|
||||||
|
|
||||||
|
op.drop_constraint('ft_billing_pkey', 'ft_billing', type_='primary')
|
||||||
|
|
||||||
|
op.create_primary_key('ft_billing_pkey', 'ft_billing', ['bst_date',
|
||||||
|
'template_id',
|
||||||
|
'rate_multiplier',
|
||||||
|
'provider',
|
||||||
|
'international'])
|
||||||
|
|
||||||
|
op.drop_index(op.f('ix_ft_billing_template_id'), table_name='ft_billing')
|
||||||
Reference in New Issue
Block a user