Migration script

Change to command.
This commit is contained in:
Rebecca Law
2018-05-10 16:41:24 +01:00
parent 8028f6cc28
commit d50a0d4cb4
2 changed files with 47 additions and 8 deletions

View File

@@ -551,19 +551,26 @@ def populate_redis_template_usage(service_id, day):
) )
@notify_command(name='rebuild-ft-billing-for-month-and-service') @notify_command(name='rebuild-ft-billing-for-day')
@click.option('-s', '--service_id', required=True, type=click.UUID) @click.option('-s', '--service_id', required=False, type=click.UUID)
@click.option('-d', '--day', help="The date to recalculate, as YYYY-MM-DD", required=True, @click.option('-d', '--day', help="The date to recalculate, as YYYY-MM-DD", required=True,
type=click_dt(format='%Y-%m-%d')) type=click_dt(format='%Y-%m-%d'))
def rebuild_ft_billing_for_month_and_service(service_id, day): def rebuild_ft_billing_for_day(service_id, day):
""" """
Rebuild the data in ft_billing for the given service_id and date Rebuild the data in ft_billing for the given service_id and date
""" """
# confirm the service exists def rebuild_ft_data(process_day, service):
dao_fetch_service_by_id(service_id) transit_data = fetch_billing_data_for_day(process_day=process_day, service_id=service)
transit_data = fetch_billing_data_for_day(process_day=day, service_id=service_id) for data in transit_data:
for data in transit_data: update_fact_billing(data, process_day)
update_fact_billing(data, day) if service_id:
# confirm the service exists
dao_fetch_service_by_id(service_id)
rebuild_ft_data(day, service_id)
else:
services = get_service_ids_that_need_billing_populated(day, day)
for service_id in services:
rebuild_ft_data(day, service_id)
@notify_command(name='compare-ft-billing-to-monthly-billing') @notify_command(name='compare-ft-billing-to-monthly-billing')

View File

@@ -0,0 +1,32 @@
"""
Revision ID: 0189_ft_billing_data_type
Revises: 0187_another_letter_org
Create Date: 2018-05-10 14:57:52.589773
"""
from alembic import op
import sqlalchemy as sa
revision = '0189_ft_billing_data_type'
down_revision = '0187_another_letter_org'
def upgrade():
op.alter_column('ft_billing', 'billable_units',
existing_type=sa.NUMERIC(),
type_=sa.Integer(),
existing_nullable=True)
op.alter_column('ft_billing', 'rate_multiplier',
existing_type=sa.NUMERIC(),
type_=sa.Integer())
def downgrade():
op.alter_column('ft_billing', 'rate_multiplier',
existing_type=sa.Integer(),
type_=sa.NUMERIC())
op.alter_column('ft_billing', 'billable_units',
existing_type=sa.Integer(),
type_=sa.NUMERIC(),
existing_nullable=True)