Add unique key on annual_billing for service_id + financial_year_start.

This is an extra precaution for the table to ensure data integrity. Since we only update/insert the data using the annual_billing_dao methods the integrity is in tact. I've check the data on preview, staging and prod there are no violations of this unique key.
This commit is contained in:
Rebecca Law
2021-04-20 13:42:20 +01:00
parent bcd1939179
commit a637c8eb92
3 changed files with 26 additions and 1 deletions

View File

@@ -102,7 +102,7 @@ def set_default_free_allowance_for_service(service, year_start=None):
f"{default_free_sms_fragment_limits['other'][year_start]}")
free_allowance = default_free_sms_fragment_limits['other'][year_start]
dao_create_or_update_annual_billing_for_year(
return dao_create_or_update_annual_billing_for_year(
service.id,
free_allowance,
year_start

View File

@@ -579,6 +579,9 @@ class AnnualBilling(db.Model):
UniqueConstraint('financial_year_start', 'service_id', name='ix_annual_billing_service_id')
service = db.relationship(Service, backref=db.backref("annual_billing", uselist=True))
__table_args__ = (UniqueConstraint(
'service_id', 'financial_year_start', name='uix_service_id_financial_year_start'),)
def serialize_free_sms_items(self):
return {
'free_sms_fragment_limit': self.free_sms_fragment_limit,