mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-02 09:26:08 -05:00
migrate bst_date to local_date
This commit is contained in:
@@ -16,7 +16,7 @@ down_revision = '0173_create_daily_sorted_letter'
|
||||
def upgrade():
|
||||
# Create notifications_for_today table
|
||||
op.create_table('ft_billing',
|
||||
sa.Column('bst_date', sa.Date(), nullable=True),
|
||||
sa.Column('local_date', sa.Date(), nullable=True),
|
||||
sa.Column('template_id', postgresql.UUID(as_uuid=True), nullable=True),
|
||||
sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=True),
|
||||
sa.Column('organisation_id', postgresql.UUID(as_uuid=True), nullable=True),
|
||||
@@ -29,15 +29,15 @@ def upgrade():
|
||||
sa.Column('rate', sa.Numeric(), nullable=True),
|
||||
sa.Column('billable_units', sa.Numeric(), nullable=True),
|
||||
sa.Column('notifications_sent', sa.Integer(), nullable=True),
|
||||
sa.PrimaryKeyConstraint('bst_date', 'template_id')
|
||||
sa.PrimaryKeyConstraint('local_date', 'template_id')
|
||||
)
|
||||
# Set indexes
|
||||
op.create_index(op.f('ix_ft_billing_bst_date'), 'ft_billing', ['bst_date'], unique=False)
|
||||
op.create_index(op.f('ix_ft_billing_local_date'), 'ft_billing', ['local_date'], unique=False)
|
||||
op.create_index(op.f('ix_ft_billing_service_id'), 'ft_billing', ['service_id'], unique=False)
|
||||
|
||||
# Create dm_datetime table
|
||||
op.create_table('dm_datetime',
|
||||
sa.Column('bst_date', sa.Date(), nullable=False),
|
||||
sa.Column('local_date', sa.Date(), nullable=False),
|
||||
sa.Column('year', sa.Integer(), nullable=False),
|
||||
sa.Column('month', sa.Integer(), nullable=False),
|
||||
sa.Column('month_name', sa.String(), nullable=False),
|
||||
@@ -53,18 +53,18 @@ def upgrade():
|
||||
sa.Column('financial_year', sa.Integer(), nullable=True),
|
||||
sa.Column('utc_daytime_start', sa.DateTime(), nullable=False),
|
||||
sa.Column('utc_daytime_end', sa.DateTime(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('bst_date')
|
||||
sa.PrimaryKeyConstraint('local_date')
|
||||
)
|
||||
# Set indexes
|
||||
op.create_index(op.f('ix_dm_datetime_yearmonth'), 'dm_datetime', ['year', 'month'], unique=False)
|
||||
op.create_index(op.f('ix_dm_datetime_bst_date'), 'dm_datetime', ['bst_date'], unique=False)
|
||||
op.create_index(op.f('ix_dm_datetime_local_date'), 'dm_datetime', ['local_date'], unique=False)
|
||||
|
||||
# Insert data into table
|
||||
op.execute(
|
||||
"""
|
||||
INSERT into dm_datetime (
|
||||
SELECT
|
||||
datum AS bst_date,
|
||||
datum AS local_date,
|
||||
EXTRACT(YEAR FROM datum) AS year,
|
||||
EXTRACT(MONTH FROM datum) AS month,
|
||||
-- Localized month name
|
||||
@@ -91,7 +91,7 @@ def upgrade():
|
||||
FROM generate_series(0,365*50+10) AS SEQUENCE(DAY)
|
||||
GROUP BY SEQUENCE.day
|
||||
) DQ
|
||||
ORDER BY bst_date
|
||||
ORDER BY local_date
|
||||
);
|
||||
"""
|
||||
)
|
||||
|
||||
@@ -20,7 +20,7 @@ def upgrade():
|
||||
op.drop_constraint('ft_billing_pkey', 'ft_billing', type_='primary')
|
||||
# These are the orthogonal dimensions that define a row (except international).
|
||||
# These entries define a unique record.
|
||||
op.create_primary_key('ft_billing_pkey', 'ft_billing', ['bst_date',
|
||||
op.create_primary_key('ft_billing_pkey', 'ft_billing', ['local_date',
|
||||
'template_id',
|
||||
'rate_multiplier',
|
||||
'provider',
|
||||
@@ -32,5 +32,5 @@ def downgrade():
|
||||
op.add_column('ft_billing', sa.Column('annual_billing_id', postgresql.UUID(), autoincrement=False, nullable=True))
|
||||
op.add_column('ft_billing', sa.Column('crown', sa.TEXT(), autoincrement=False, nullable=True))
|
||||
op.drop_constraint('ft_billing_pkey', 'ft_billing', type_='primary')
|
||||
op.create_primary_key('ft_billing_pkey', 'ft_billing', ['bst_date',
|
||||
op.create_primary_key('ft_billing_pkey', 'ft_billing', ['local_date',
|
||||
'template_id'])
|
||||
|
||||
@@ -19,7 +19,7 @@ def upgrade():
|
||||
nullable=False)
|
||||
op.drop_constraint('ft_billing_pkey', 'ft_billing', type_='primary')
|
||||
|
||||
op.create_primary_key('ft_billing_pkey', 'ft_billing', ['bst_date',
|
||||
op.create_primary_key('ft_billing_pkey', 'ft_billing', ['local_date',
|
||||
'template_id',
|
||||
'rate_multiplier',
|
||||
'provider',
|
||||
@@ -34,7 +34,7 @@ def downgrade():
|
||||
|
||||
op.drop_constraint('ft_billing_pkey', 'ft_billing', type_='primary')
|
||||
|
||||
op.create_primary_key('ft_billing_pkey', 'ft_billing', ['bst_date',
|
||||
op.create_primary_key('ft_billing_pkey', 'ft_billing', ['local_date',
|
||||
'template_id',
|
||||
'rate_multiplier',
|
||||
'provider',
|
||||
|
||||
@@ -24,7 +24,7 @@ def upgrade():
|
||||
"""
|
||||
INSERT into dm_datetime (
|
||||
SELECT
|
||||
datum AS bst_date,
|
||||
datum AS local_date,
|
||||
EXTRACT(YEAR FROM datum) AS year,
|
||||
EXTRACT(MONTH FROM datum) AS month,
|
||||
-- Localized month name
|
||||
@@ -51,14 +51,14 @@ def upgrade():
|
||||
FROM generate_series(0,365*50+10) AS SEQUENCE(DAY)
|
||||
GROUP BY SEQUENCE.day
|
||||
) DQ
|
||||
ORDER BY bst_date
|
||||
ORDER BY local_date
|
||||
);
|
||||
"""
|
||||
)
|
||||
|
||||
op.drop_constraint('ft_billing_pkey', 'ft_billing', type_='primary')
|
||||
|
||||
op.create_primary_key('ft_billing_pkey', 'ft_billing', ['bst_date',
|
||||
op.create_primary_key('ft_billing_pkey', 'ft_billing', ['local_date',
|
||||
'template_id',
|
||||
'service_id',
|
||||
'rate_multiplier',
|
||||
@@ -70,7 +70,7 @@ def downgrade():
|
||||
# We don't downgrade populated data
|
||||
op.drop_constraint('ft_billing_pkey', 'ft_billing', type_='primary')
|
||||
|
||||
op.create_primary_key('ft_billing_pkey', 'ft_billing', ['bst_date',
|
||||
op.create_primary_key('ft_billing_pkey', 'ft_billing', ['local_date',
|
||||
'template_id',
|
||||
'rate_multiplier',
|
||||
'provider',
|
||||
|
||||
@@ -16,7 +16,7 @@ down_revision = '0183_alter_primary_key'
|
||||
def upgrade():
|
||||
op.drop_constraint('ft_billing_pkey', 'ft_billing', type_='primary')
|
||||
|
||||
op.create_primary_key('ft_billing_pkey', 'ft_billing', ['bst_date',
|
||||
op.create_primary_key('ft_billing_pkey', 'ft_billing', ['local_date',
|
||||
'template_id',
|
||||
'service_id',
|
||||
'rate_multiplier',
|
||||
@@ -28,7 +28,7 @@ def upgrade():
|
||||
def downgrade():
|
||||
op.drop_constraint('ft_billing_pkey', 'ft_billing', type_='primary')
|
||||
|
||||
op.create_primary_key('ft_billing_pkey', 'ft_billing', ['bst_date',
|
||||
op.create_primary_key('ft_billing_pkey', 'ft_billing', ['local_date',
|
||||
'template_id',
|
||||
'service_id',
|
||||
'rate_multiplier',
|
||||
|
||||
@@ -15,7 +15,7 @@ down_revision = '0187_another_letter_org'
|
||||
|
||||
def upgrade():
|
||||
op.create_table('ft_notification_status',
|
||||
sa.Column('bst_date', sa.Date(), nullable=False),
|
||||
sa.Column('local_date', sa.Date(), nullable=False),
|
||||
sa.Column('template_id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||
sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||
sa.Column('job_id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||
@@ -23,16 +23,16 @@ def upgrade():
|
||||
sa.Column('key_type', sa.Text(), nullable=False),
|
||||
sa.Column('notification_status', sa.Text(), nullable=False),
|
||||
sa.Column('notification_count', sa.Integer(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('bst_date', 'template_id', 'service_id', 'job_id', 'notification_type', 'key_type', 'notification_status')
|
||||
sa.PrimaryKeyConstraint('local_date', 'template_id', 'service_id', 'job_id', 'notification_type', 'key_type', 'notification_status')
|
||||
)
|
||||
op.create_index(op.f('ix_ft_notification_status_bst_date'), 'ft_notification_status', ['bst_date'], unique=False)
|
||||
op.create_index(op.f('ix_ft_notification_status_local_date'), 'ft_notification_status', ['local_date'], unique=False)
|
||||
op.create_index(op.f('ix_ft_notification_status_job_id'), 'ft_notification_status', ['job_id'], unique=False)
|
||||
op.create_index(op.f('ix_ft_notification_status_service_id'), 'ft_notification_status', ['service_id'], unique=False)
|
||||
op.create_index(op.f('ix_ft_notification_status_template_id'), 'ft_notification_status', ['template_id'], unique=False)
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_index(op.f('ix_ft_notification_status_bst_date'), table_name='ft_notification_status')
|
||||
op.drop_index(op.f('ix_ft_notification_status_local_date'), table_name='ft_notification_status')
|
||||
op.drop_index(op.f('ix_ft_notification_status_template_id'), table_name='ft_notification_status')
|
||||
op.drop_index(op.f('ix_ft_notification_status_service_id'), table_name='ft_notification_status')
|
||||
op.drop_index(op.f('ix_ft_notification_status_job_id'), table_name='ft_notification_status')
|
||||
|
||||
@@ -16,7 +16,7 @@ def upgrade():
|
||||
op.execute("ALTER TABLE ft_billing DROP CONSTRAINT ft_billing_pkey")
|
||||
sql = """ALTER TABLE ft_billing ADD CONSTRAINT
|
||||
ft_billing_pkey PRIMARY KEY
|
||||
(bst_date, template_id, service_id, rate_multiplier, provider, notification_type, international, rate)"""
|
||||
(local_date, template_id, service_id, rate_multiplier, provider, notification_type, international, rate)"""
|
||||
op.execute(sql)
|
||||
|
||||
|
||||
@@ -25,5 +25,5 @@ def downgrade():
|
||||
op.execute("ALTER TABLE ft_billing DROP CONSTRAINT ft_billing_pkey")
|
||||
sql = """ALTER TABLE ft_billing ADD CONSTRAINT
|
||||
ft_billing_pkey PRIMARY KEY
|
||||
(bst_date, template_id, service_id, rate_multiplier, provider, notification_type, international)"""
|
||||
(local_date, template_id, service_id, rate_multiplier, provider, notification_type, international)"""
|
||||
op.execute(sql)
|
||||
@@ -15,7 +15,7 @@ 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',
|
||||
op.create_primary_key('ft_billing_pkey', 'ft_billing', ['local_date',
|
||||
'template_id',
|
||||
'service_id',
|
||||
'notification_type',
|
||||
@@ -29,7 +29,7 @@ def upgrade():
|
||||
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',
|
||||
op.create_primary_key('ft_billing_pkey', 'ft_billing', ['local_date',
|
||||
'template_id',
|
||||
'service_id',
|
||||
'notification_type',
|
||||
|
||||
@@ -14,14 +14,14 @@ down_revision = '0306_letter_rates_price_rise'
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.drop_index('ix_dm_datetime_bst_date', table_name='dm_datetime')
|
||||
op.drop_index('ix_dm_datetime_local_date', table_name='dm_datetime')
|
||||
op.drop_index('ix_dm_datetime_yearmonth', table_name='dm_datetime')
|
||||
op.drop_table('dm_datetime')
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.create_table('dm_datetime',
|
||||
sa.Column('bst_date', sa.DATE(), autoincrement=False, nullable=False),
|
||||
sa.Column('local_date', sa.DATE(), autoincrement=False, nullable=False),
|
||||
sa.Column('year', sa.INTEGER(), autoincrement=False, nullable=False),
|
||||
sa.Column('month', sa.INTEGER(), autoincrement=False, nullable=False),
|
||||
sa.Column('month_name', sa.VARCHAR(), autoincrement=False, nullable=False),
|
||||
@@ -37,7 +37,7 @@ def downgrade():
|
||||
sa.Column('financial_year', sa.INTEGER(), autoincrement=False, nullable=False),
|
||||
sa.Column('utc_daytime_start', postgresql.TIMESTAMP(), autoincrement=False, nullable=False),
|
||||
sa.Column('utc_daytime_end', postgresql.TIMESTAMP(), autoincrement=False, nullable=False),
|
||||
sa.PrimaryKeyConstraint('bst_date', name='dm_datetime_pkey')
|
||||
sa.PrimaryKeyConstraint('local_date', name='dm_datetime_pkey')
|
||||
)
|
||||
op.create_index('ix_dm_datetime_yearmonth', 'dm_datetime', ['year', 'month'], unique=False)
|
||||
op.create_index('ix_dm_datetime_bst_date', 'dm_datetime', ['bst_date'], unique=False)
|
||||
op.create_index('ix_dm_datetime_local_date', 'dm_datetime', ['local_date'], unique=False)
|
||||
|
||||
@@ -15,16 +15,16 @@ down_revision = '0348_migrate_broadcast_settings'
|
||||
|
||||
def upgrade():
|
||||
op.create_table('ft_processing_time',
|
||||
sa.Column('bst_date', sa.Date(), nullable=False),
|
||||
sa.Column('local_date', sa.Date(), nullable=False),
|
||||
sa.Column('messages_total', sa.Integer(), nullable=False),
|
||||
sa.Column('messages_within_10_secs', sa.Integer(), nullable=False),
|
||||
sa.Column('created_at', sa.DateTime(), nullable=False),
|
||||
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
||||
sa.PrimaryKeyConstraint('bst_date')
|
||||
sa.PrimaryKeyConstraint('local_date')
|
||||
)
|
||||
op.create_index(op.f('ix_ft_processing_time_bst_date'), 'ft_processing_time', ['bst_date'], unique=False)
|
||||
op.create_index(op.f('ix_ft_processing_time_local_date'), 'ft_processing_time', ['local_date'], unique=False)
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_index(op.f('ix_ft_processing_time_bst_date'), table_name='ft_processing_time')
|
||||
op.drop_index(op.f('ix_ft_processing_time_local_date'), table_name='ft_processing_time')
|
||||
op.drop_table('ft_processing_time')
|
||||
|
||||
@@ -24,8 +24,8 @@ def upgrade():
|
||||
SET rate = 0.0161
|
||||
WHERE
|
||||
notification_type = 'sms' AND
|
||||
bst_date >= '2022-04-01' AND
|
||||
bst_date < '2022-05-01'
|
||||
local_date >= '2022-04-01' AND
|
||||
local_date < '2022-05-01'
|
||||
"""
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user