mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-02 09:26:08 -05:00
more files and remove add_letter_org migrations
This commit is contained in:
@@ -8,6 +8,9 @@ Create Date: 2017-11-10 21:42:59.715203
|
||||
from datetime import datetime
|
||||
from alembic import op
|
||||
import uuid
|
||||
|
||||
from sqlalchemy import text
|
||||
|
||||
from app.dao.date_util import get_current_calendar_year_start_year
|
||||
|
||||
|
||||
@@ -21,20 +24,28 @@ def upgrade():
|
||||
|
||||
# Step 1: update the column free_sms_fragment_limit in service table if it is empty
|
||||
update_service_table = """
|
||||
UPDATE services SET free_sms_fragment_limit = {} where free_sms_fragment_limit is null
|
||||
""".format(default_limit)
|
||||
|
||||
op.execute(update_service_table)
|
||||
UPDATE services SET free_sms_fragment_limit = :default_limit where free_sms_fragment_limit is null
|
||||
"""
|
||||
input_params = {
|
||||
"default_limit": default_limit
|
||||
}
|
||||
conn = op.get_bind()
|
||||
conn.execute(text(update_service_table), input_params)
|
||||
|
||||
# Step 2: insert at least one row for every service in current year if none exist for that service
|
||||
input_params = {
|
||||
"current_year": current_year,
|
||||
"default_limit": default_limit,
|
||||
"time_now": datetime.utcnow()
|
||||
}
|
||||
insert_row_if_not_exist = """
|
||||
INSERT INTO annual_billing
|
||||
(id, service_id, financial_year_start, free_sms_fragment_limit, created_at, updated_at)
|
||||
SELECT uuid_in(md5(random()::text)::cstring), id, {}, {}, '{}', '{}'
|
||||
SELECT uuid_in(md5(random()::text)::cstring), id, :current_year, :default_limit, :time_now, :time_now
|
||||
FROM services WHERE id NOT IN
|
||||
(select service_id from annual_billing)
|
||||
""".format(current_year, default_limit, datetime.utcnow(), datetime.utcnow())
|
||||
op.execute(insert_row_if_not_exist)
|
||||
"""
|
||||
conn.execute(text(insert_row_if_not_exist), input_params)
|
||||
|
||||
# Step 3: copy the free_sms_fragment_limit data from the services table across to annual_billing table.
|
||||
update_sms_allowance = """
|
||||
|
||||
Reference in New Issue
Block a user