2017-05-31 13:34:54 +01:00
|
|
|
"""empty message
|
|
|
|
|
|
2017-06-02 14:47:28 +01:00
|
|
|
Revision ID: 0091_letter_billing
|
|
|
|
|
Revises: 0090_inbound_sms
|
2017-05-31 13:34:54 +01:00
|
|
|
Create Date: 2017-05-31 11:43:55.744631
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
import uuid
|
|
|
|
|
from alembic import op
|
|
|
|
|
import sqlalchemy as sa
|
2023-07-17 11:29:08 -07:00
|
|
|
from sqlalchemy import text
|
2017-05-31 13:34:54 +01:00
|
|
|
from sqlalchemy.dialects import postgresql
|
|
|
|
|
|
2017-06-02 14:47:28 +01:00
|
|
|
revision = '0091_letter_billing'
|
|
|
|
|
down_revision = '0090_inbound_sms'
|
2017-05-31 13:34:54 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def upgrade():
|
|
|
|
|
op.create_table('letter_rates',
|
|
|
|
|
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
|
|
|
|
|
sa.Column('valid_from', sa.DateTime(), nullable=False),
|
|
|
|
|
sa.PrimaryKeyConstraint('id')
|
|
|
|
|
)
|
|
|
|
|
op.create_table('letter_rate_details',
|
|
|
|
|
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
|
|
|
|
|
sa.Column('letter_rate_id', postgresql.UUID(as_uuid=True), nullable=False),
|
|
|
|
|
sa.Column('page_total', sa.Integer(), nullable=False),
|
|
|
|
|
sa.Column('rate', sa.Numeric(), nullable=False),
|
|
|
|
|
sa.ForeignKeyConstraint(['letter_rate_id'], ['letter_rates.id'], ),
|
|
|
|
|
sa.PrimaryKeyConstraint('id')
|
|
|
|
|
)
|
|
|
|
|
op.create_index(op.f('ix_letter_rate_details_letter_rate_id'), 'letter_rate_details', ['letter_rate_id'],
|
|
|
|
|
unique=False)
|
|
|
|
|
|
2023-07-17 11:29:08 -07:00
|
|
|
conn = op.get_bind()
|
2017-05-31 13:34:54 +01:00
|
|
|
letter_id = uuid.uuid4()
|
2023-07-17 11:29:08 -07:00
|
|
|
input_params = {
|
|
|
|
|
"letter_id": letter_id
|
|
|
|
|
}
|
|
|
|
|
conn.execute(text("insert into letter_rates(id, valid_from) values(:letter_id, '2017-03-31 23:00:00')"), input_params)
|
|
|
|
|
insert_details = "insert into letter_rate_details(id, letter_rate_id, page_total, rate) values(:id, :letter_id, :page_total, :rate)"
|
|
|
|
|
input_params = {
|
|
|
|
|
"id": uuid.uuid4(),
|
|
|
|
|
"letter_id": letter_id,
|
|
|
|
|
"page_total": 1,
|
|
|
|
|
"rate": 29.3
|
|
|
|
|
}
|
|
|
|
|
conn.execute(text(insert_details), input_params)
|
|
|
|
|
input_params = {
|
|
|
|
|
"id": uuid.uuid4(),
|
|
|
|
|
"letter_id": letter_id,
|
|
|
|
|
"page_total": 2,
|
|
|
|
|
"rate": 32
|
|
|
|
|
}
|
|
|
|
|
conn.execute(text(insert_details), input_params)
|
|
|
|
|
input_params = {
|
|
|
|
|
"id": uuid.uuid4(),
|
|
|
|
|
"letter_id": letter_id,
|
|
|
|
|
"page_total": 3,
|
|
|
|
|
"rate": 35
|
|
|
|
|
}
|
|
|
|
|
conn.execute(text(insert_details), input_params)
|
2017-05-31 13:34:54 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def downgrade():
|
|
|
|
|
op.get_bind()
|
|
|
|
|
op.drop_index('ix_letter_rate_details_letter_rate_id')
|
|
|
|
|
op.drop_table('letter_rate_details')
|
|
|
|
|
op.drop_table('letter_rates')
|