more files

This commit is contained in:
Kenneth Kehl
2023-07-17 07:45:54 -07:00
parent 4d090ed9ef
commit de4812efee
11 changed files with 90 additions and 48 deletions

View File

@@ -33,6 +33,7 @@ new_type = sa.Enum(*new_options, name=enum_name)
alter_str = 'ALTER TABLE {table} ALTER COLUMN status TYPE {enum} USING status::text::notify_status_type '
def upgrade():
op.execute('ALTER TYPE {enum} RENAME TO {tmp_name}'.format(enum=enum_name, tmp_name=tmp_name))

View File

@@ -8,6 +8,8 @@ Create Date: 2017-07-12 13:35:45.636618
from datetime import datetime
from alembic import op
import sqlalchemy as sa
from sqlalchemy import text
from app.dao.date_util import get_month_start_and_end_date_in_utc
down_revision = '0111_drop_old_service_flags'
@@ -26,9 +28,13 @@ def upgrade():
for x in res:
start_date, end_date = get_month_start_and_end_date_in_utc(
datetime(int(x.year), datetime.strptime(x.month, '%B').month, 1))
conn.execute("update monthly_billing set start_date = '{}', end_date = '{}' where id = '{}'".format(start_date,
end_date,
x.id))
input_params = {
"start_date": start_date,
"end_date": end_date,
"x_id": x.id
}
conn.execute(text("update monthly_billing set start_date = :start_date, end_date = :end_date where id = :x_id"),
input_params)
op.alter_column('monthly_billing', 'start_date', nullable=False)
op.alter_column('monthly_billing', 'end_date', nullable=False)
op.create_index(op.f('uix_monthly_billing'), 'monthly_billing', ['service_id', 'start_date', 'notification_type'],

View File

@@ -18,13 +18,13 @@ def upgrade():
op.get_bind()
op.execute("""
update templates
set process_type = '{}'
set process_type = 'normal'
where templates.id in (
select templates.id from templates
join templates_history on templates.id=templates_history.id
where templates_history.name = 'Example text message template'
)
""".format(NORMAL))
""")
def downgrade():

View File

@@ -7,6 +7,8 @@ Create Date: 2017-06-29 12:44:16.815039
"""
# revision identifiers, used by Alembic.
from sqlalchemy import text
revision = '0180_another_letter_org'
down_revision = '0179_billing_primary_const'
@@ -19,18 +21,19 @@ NEW_ORGANISATIONS = [
def upgrade():
conn = op.get_bind()
for numeric_id, name in NEW_ORGANISATIONS:
op.execute("""
INSERT
INTO dvla_organisation
VALUES ('{}', '{}')
""".format(numeric_id, name))
input_params = {
"numeric_id": numeric_id,
"name": name
}
conn.execute(text("INSERT INTO dvla_organisation VALUES (:numeric_id, :name)"), input_params)
def downgrade():
conn = op.get_bind()
for numeric_id, _ in NEW_ORGANISATIONS:
op.execute("""
DELETE
FROM dvla_organisation
WHERE id = '{}'
""".format(numeric_id))
input_params = {
"numeric_id": numeric_id
}
conn.execute(text("DELETE FROM dvla_organisation WHERE id = :numeric_id"), input_params)

View File

@@ -6,6 +6,8 @@ Revises: 0213_brand_colour_domain_
"""
# revision identifiers, used by Alembic.
from sqlalchemy import text
revision = '0214_another_letter_org'
down_revision = '0213_brand_colour_domain'
@@ -18,18 +20,20 @@ NEW_ORGANISATIONS = [
def upgrade():
conn = op.get_bind()
for numeric_id, name in NEW_ORGANISATIONS:
op.execute("""
INSERT
INTO dvla_organisation
VALUES ('{}', '{}')
""".format(numeric_id, name))
input_params = {
"numeric_id": numeric_id,
"name": name
}
conn.execute(text("INSERT INTO dvla_organisation VALUES (:numeric_id, :name)"), input_params)
def downgrade():
conn = op.get_bind()
for numeric_id, _ in NEW_ORGANISATIONS:
op.execute("""
DELETE
FROM dvla_organisation
WHERE id = '{}'
""".format(numeric_id))
input_params = {
"numeric_id": numeric_id
}
conn.execute(text("DELETE FROM dvla_organisation WHERE id = :numeric_id"), input_params)

View File

@@ -17,7 +17,7 @@ def upgrade():
INSERT INTO
service_permissions (service_id, permission, created_at)
SELECT
id, '{permission}', now()
id, 'edit_folders', now()
FROM
services
WHERE
@@ -27,11 +27,9 @@ def upgrade():
service_permissions
WHERE
service_id = services.id and
permission = '{permission}'
permission = 'edit_folders'
)
""".format(
permission='edit_folders'
))
""")
def downgrade():

View File

@@ -7,6 +7,8 @@ Create Date: 2016-10-25 17:37:27.660723
"""
# revision identifiers, used by Alembic.
from sqlalchemy import text
revision = '0283_platform_admin_not_live'
down_revision = '0282_add_count_as_live'
@@ -18,7 +20,7 @@ STATEMENT = """
UPDATE
services
SET
count_as_live = {count_as_live}
count_as_live = :count_as_live
FROM
users
WHERE
@@ -29,7 +31,16 @@ STATEMENT = """
def upgrade():
op.execute(STATEMENT.format(count_as_live='false'))
conn = op.get_bind()
input_params = {
"count_as_live": "false"
}
conn.execute(text(STATEMENT), input_params)
def downgrade():
op.execute(STATEMENT.format(count_as_live='true'))
conn = op.get_bind()
input_params = {
"count_as_live": "true"
}
conn.execute(text(STATEMENT), input_params)

View File

@@ -6,6 +6,7 @@ Create Date: 2019-12-09 12:13:49.432993
"""
from alembic import op
from sqlalchemy import text
revision = '0312_populate_returned_letters'
down_revision = '0311_add_inbound_sms_history'
@@ -20,14 +21,18 @@ def upgrade():
and notification_status = 'returned-letter'"""
insert_sql = """
insert into returned_letters(id, reported_at, service_id, notification_id, created_at, updated_at)
values(uuid_in(md5(random()::text)::cstring), '{}', '{}', '{}', now(), null)
values(uuid_in(md5(random()::text)::cstring), :updated_at, :service_id, :id, now(), null)
"""
results = conn.execute(sql)
returned_letters = results.fetchall()
for x in returned_letters:
f = insert_sql.format(x.updated_at.date(), x.service_id, x.id)
conn.execute(f)
input_params = {
"updated_at": x.updated_at.date(),
"service_id": x.service_id,
"id": x.id
}
conn.execute(text(insert_sql), input_params)
def downgrade():

View File

@@ -7,6 +7,7 @@ Create Date: 2021-02-09 09:19:07.957980
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy import text
from sqlalchemy.dialects import postgresql
revision = '0345_move_broadcast_provider'
@@ -23,14 +24,17 @@ def upgrade():
"""
insert_sql = """
insert into service_broadcast_settings(service_id, channel, provider, created_at, updated_at)
values('{}', 'test', '{}', now(), null)
values(:service_id, 'test', :provider, now(), null)
"""
conn = op.get_bind()
results = conn.execute(sql)
restrictions = results.fetchall()
for x in restrictions:
f = insert_sql.format(x.service_id, x.provider)
conn.execute(f)
input_params = {
"service_id": x.service_id,
"provider": x.provider
}
conn.execute(text(insert_sql), input_params)
def downgrade():

View File

@@ -24,7 +24,11 @@ def upgrade():
def downgrade():
conn = op.get_bind()
input_params = {
"id": str(uuid.uuid4()),
}
conn.execute(
text(
"""
INSERT INTO provider_details (
id,
@@ -37,7 +41,7 @@ def downgrade():
created_by_id
)
VALUES (
'{}',
:id,
'Reach',
'reach',
0,
@@ -46,7 +50,4 @@ def downgrade():
1,
null
)
""".format(
str(uuid.uuid4()),
)
)
"""), input_params)

View File

@@ -5,8 +5,11 @@ Revises: 0389_no_more_letters.py
Create Date: 2023-02-28 14:25:50.751952
"""
import uuid
from alembic import op
import sqlalchemy as sa
from sqlalchemy import text
from sqlalchemy.dialects import postgresql
revision = '0390_drop_dvla_provider.py'
@@ -23,10 +26,16 @@ def upgrade():
def downgrade():
# migration 0066 in reverse
provider_id = str(uuid.uuid4())
op.execute(
"INSERT INTO provider_details (id, display_name, identifier, priority, notification_type, active, version) values ('{}', 'DVLA', 'dvla', 50, 'letter', true, 1)".format(provider_id)
input_params = {
"provider_id": provider_id
}
conn = op.get_bind()
conn.execute(
text("INSERT INTO provider_details (id, display_name, identifier, priority, notification_type, active, version) values (:provider_id, 'DVLA', 'dvla', 50, 'letter', true, 1)"),
input_params
)
op.execute(
"INSERT INTO provider_details_history (id, display_name, identifier, priority, notification_type, active, version) values ('{}', 'DVLA', 'dvla', 50, 'letter', true, 1)".format(provider_id)
conn.execute(
text("INSERT INTO provider_details_history (id, display_name, identifier, priority, notification_type, active, version) values (:provider_id, 'DVLA', 'dvla', 50, 'letter', true, 1)"),
input_params
)
# ### end Alembic commands ###