Files
notifications-api/migrations/versions/0075_create_rates_table.py

61 lines
1.6 KiB
Python
Raw Normal View History

"""empty message
Revision ID: 0075_create_rates_table
2023-07-18 13:44:38 -07:00
Revises: 0073_add_international_sms_flag
Create Date: 2017-04-24 15:12:18.907629
"""
# revision identifiers, used by Alembic.
import uuid
2023-07-18 09:02:40 -07:00
from sqlalchemy import text
2023-08-29 14:54:30 -07:00
revision = "0075_create_rates_table"
down_revision = "0073_add_international_sms_flag"
import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql
2023-08-29 14:54:30 -07:00
def upgrade():
2023-08-29 14:54:30 -07:00
notification_types = postgresql.ENUM(
"email", "sms", "letter", name="notification_type", create_type=False
)
op.create_table(
"rates",
sa.Column("id", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column("valid_from", sa.DateTime(), nullable=False),
sa.Column("rate", sa.Numeric(), nullable=False),
sa.Column("notification_type", notification_types, nullable=False),
sa.PrimaryKeyConstraint("id"),
)
2023-08-29 14:54:30 -07:00
op.create_index(
op.f("ix_rates_notification_type"), "rates", ["notification_type"], unique=False
)
2023-07-18 09:02:40 -07:00
conn = op.get_bind()
2023-08-29 14:54:30 -07:00
input_params = {"id": uuid.uuid4()}
conn.execute(
text(
"INSERT INTO rates(id, valid_from, rate, notification_type) "
"VALUES(:id, '2016-05-18 00:00:00', 1.65, 'sms')"
),
input_params,
)
input_params = {"id": uuid.uuid4()}
conn.execute(
text(
"INSERT INTO rates(id, valid_from, rate, notification_type) "
"VALUES(:id, '2017-04-01 00:00:00', 1.58, 'sms')"
),
input_params,
)
def downgrade():
2023-08-29 14:54:30 -07:00
op.drop_index(op.f("ix_rates_notification_type"), table_name="rates")
op.drop_table("rates")