Use double quotes
This commit is contained in:
parent
7b32ffc599
commit
ea8f1a13e3
9 changed files with 2464 additions and 2466 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -12,141 +12,141 @@ from alembic import op
|
|||
from velofy import configuration
|
||||
|
||||
|
||||
revision = '888e352d7526'
|
||||
down_revision = 'f11cd76d2f45'
|
||||
revision = "888e352d7526"
|
||||
down_revision = "f11cd76d2f45"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
config = configuration.make_config('testing' if os.getenv('TESTING') else 'production')
|
||||
config = configuration.make_config("testing" if os.getenv("TESTING") else "production")
|
||||
|
||||
|
||||
def upgrade():
|
||||
"""Upgrade to revision 888e352d7526."""
|
||||
op.create_table(
|
||||
'grids',
|
||||
sa.Column('id', sa.SmallInteger(), autoincrement=True, nullable=False),
|
||||
sa.Column('city_id', sa.SmallInteger(), nullable=False),
|
||||
sa.Column('side_length', sa.SmallInteger(), nullable=True),
|
||||
sa.PrimaryKeyConstraint('id', name=op.f('pk_grids')),
|
||||
"grids",
|
||||
sa.Column("id", sa.SmallInteger(), autoincrement=True, nullable=False),
|
||||
sa.Column("city_id", sa.SmallInteger(), nullable=False),
|
||||
sa.Column("side_length", sa.SmallInteger(), nullable=True),
|
||||
sa.PrimaryKeyConstraint("id", name=op.f("pk_grids")),
|
||||
sa.ForeignKeyConstraint(
|
||||
['city_id'],
|
||||
[f'{config.CLEAN_SCHEMA}.cities.id'],
|
||||
name=op.f('fk_grids_to_cities_via_city_id'),
|
||||
onupdate='RESTRICT',
|
||||
ondelete='RESTRICT',
|
||||
["city_id"],
|
||||
[f"{config.CLEAN_SCHEMA}.cities.id"],
|
||||
name=op.f("fk_grids_to_cities_via_city_id"),
|
||||
onupdate="RESTRICT",
|
||||
ondelete="RESTRICT",
|
||||
),
|
||||
sa.UniqueConstraint(
|
||||
'city_id',
|
||||
'side_length',
|
||||
name=op.f('uq_grids_on_city_id_side_length'),
|
||||
"city_id",
|
||||
"side_length",
|
||||
name=op.f("uq_grids_on_city_id_side_length"),
|
||||
),
|
||||
# This `UniqueConstraint` is needed by the `addresses_pixels` table below.
|
||||
sa.UniqueConstraint('id', 'city_id', name=op.f('uq_grids_on_id_city_id')),
|
||||
sa.UniqueConstraint("id", "city_id", name=op.f("uq_grids_on_id_city_id")),
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
|
||||
op.create_table(
|
||||
'pixels',
|
||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||
sa.Column('grid_id', sa.SmallInteger(), nullable=False),
|
||||
sa.Column('n_x', sa.SmallInteger(), nullable=False),
|
||||
sa.Column('n_y', sa.SmallInteger(), nullable=False),
|
||||
sa.CheckConstraint('0 <= n_x', name=op.f('ck_pixels_on_n_x_is_positive')),
|
||||
sa.CheckConstraint('0 <= n_y', name=op.f('ck_pixels_on_n_y_is_positive')),
|
||||
"pixels",
|
||||
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
|
||||
sa.Column("grid_id", sa.SmallInteger(), nullable=False),
|
||||
sa.Column("n_x", sa.SmallInteger(), nullable=False),
|
||||
sa.Column("n_y", sa.SmallInteger(), nullable=False),
|
||||
sa.CheckConstraint("0 <= n_x", name=op.f("ck_pixels_on_n_x_is_positive")),
|
||||
sa.CheckConstraint("0 <= n_y", name=op.f("ck_pixels_on_n_y_is_positive")),
|
||||
sa.ForeignKeyConstraint(
|
||||
['grid_id'],
|
||||
[f'{config.CLEAN_SCHEMA}.grids.id'],
|
||||
name=op.f('fk_pixels_to_grids_via_grid_id'),
|
||||
onupdate='RESTRICT',
|
||||
ondelete='RESTRICT',
|
||||
["grid_id"],
|
||||
[f"{config.CLEAN_SCHEMA}.grids.id"],
|
||||
name=op.f("fk_pixels_to_grids_via_grid_id"),
|
||||
onupdate="RESTRICT",
|
||||
ondelete="RESTRICT",
|
||||
),
|
||||
sa.PrimaryKeyConstraint('id', name=op.f('pk_pixels')),
|
||||
sa.PrimaryKeyConstraint("id", name=op.f("pk_pixels")),
|
||||
sa.UniqueConstraint(
|
||||
'grid_id',
|
||||
'n_x',
|
||||
'n_y',
|
||||
name=op.f('uq_pixels_on_grid_id_n_x_n_y'),
|
||||
"grid_id",
|
||||
"n_x",
|
||||
"n_y",
|
||||
name=op.f("uq_pixels_on_grid_id_n_x_n_y"),
|
||||
),
|
||||
sa.UniqueConstraint('id', 'grid_id', name=op.f('uq_pixels_on_id_grid_id')),
|
||||
sa.UniqueConstraint("id", "grid_id", name=op.f("uq_pixels_on_id_grid_id")),
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
|
||||
op.create_index(
|
||||
op.f('ix_pixels_on_grid_id'),
|
||||
'pixels',
|
||||
['grid_id'],
|
||||
op.f("ix_pixels_on_grid_id"),
|
||||
"pixels",
|
||||
["grid_id"],
|
||||
unique=False,
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
op.create_index(
|
||||
op.f('ix_pixels_on_n_x'),
|
||||
'pixels',
|
||||
['n_x'],
|
||||
op.f("ix_pixels_on_n_x"),
|
||||
"pixels",
|
||||
["n_x"],
|
||||
unique=False,
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
op.create_index(
|
||||
op.f('ix_pixels_on_n_y'),
|
||||
'pixels',
|
||||
['n_y'],
|
||||
op.f("ix_pixels_on_n_y"),
|
||||
"pixels",
|
||||
["n_y"],
|
||||
unique=False,
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
|
||||
# This `UniqueConstraint` is needed by the `addresses_pixels` table below.
|
||||
op.create_unique_constraint(
|
||||
'uq_addresses_on_id_city_id',
|
||||
'addresses',
|
||||
['id', 'city_id'],
|
||||
"uq_addresses_on_id_city_id",
|
||||
"addresses",
|
||||
["id", "city_id"],
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
|
||||
op.create_table(
|
||||
'addresses_pixels',
|
||||
sa.Column('address_id', sa.Integer(), nullable=False),
|
||||
sa.Column('city_id', sa.SmallInteger(), nullable=False),
|
||||
sa.Column('grid_id', sa.SmallInteger(), nullable=False),
|
||||
sa.Column('pixel_id', sa.Integer(), nullable=False),
|
||||
"addresses_pixels",
|
||||
sa.Column("address_id", sa.Integer(), nullable=False),
|
||||
sa.Column("city_id", sa.SmallInteger(), nullable=False),
|
||||
sa.Column("grid_id", sa.SmallInteger(), nullable=False),
|
||||
sa.Column("pixel_id", sa.Integer(), nullable=False),
|
||||
sa.ForeignKeyConstraint(
|
||||
['address_id', 'city_id'],
|
||||
["address_id", "city_id"],
|
||||
[
|
||||
f'{config.CLEAN_SCHEMA}.addresses.id',
|
||||
f'{config.CLEAN_SCHEMA}.addresses.city_id',
|
||||
f"{config.CLEAN_SCHEMA}.addresses.id",
|
||||
f"{config.CLEAN_SCHEMA}.addresses.city_id",
|
||||
],
|
||||
name=op.f('fk_addresses_pixels_to_addresses_via_address_id_city_id'),
|
||||
onupdate='RESTRICT',
|
||||
ondelete='RESTRICT',
|
||||
name=op.f("fk_addresses_pixels_to_addresses_via_address_id_city_id"),
|
||||
onupdate="RESTRICT",
|
||||
ondelete="RESTRICT",
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
['grid_id', 'city_id'],
|
||||
["grid_id", "city_id"],
|
||||
[
|
||||
f'{config.CLEAN_SCHEMA}.grids.id',
|
||||
f'{config.CLEAN_SCHEMA}.grids.city_id',
|
||||
f"{config.CLEAN_SCHEMA}.grids.id",
|
||||
f"{config.CLEAN_SCHEMA}.grids.city_id",
|
||||
],
|
||||
name=op.f('fk_addresses_pixels_to_grids_via_grid_id_city_id'),
|
||||
onupdate='RESTRICT',
|
||||
ondelete='RESTRICT',
|
||||
name=op.f("fk_addresses_pixels_to_grids_via_grid_id_city_id"),
|
||||
onupdate="RESTRICT",
|
||||
ondelete="RESTRICT",
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
['pixel_id', 'grid_id'],
|
||||
["pixel_id", "grid_id"],
|
||||
[
|
||||
f'{config.CLEAN_SCHEMA}.pixels.id',
|
||||
f'{config.CLEAN_SCHEMA}.pixels.grid_id',
|
||||
f"{config.CLEAN_SCHEMA}.pixels.id",
|
||||
f"{config.CLEAN_SCHEMA}.pixels.grid_id",
|
||||
],
|
||||
name=op.f('fk_addresses_pixels_to_pixels_via_pixel_id_grid_id'),
|
||||
onupdate='RESTRICT',
|
||||
ondelete='RESTRICT',
|
||||
name=op.f("fk_addresses_pixels_to_pixels_via_pixel_id_grid_id"),
|
||||
onupdate="RESTRICT",
|
||||
ondelete="RESTRICT",
|
||||
),
|
||||
sa.PrimaryKeyConstraint(
|
||||
'address_id',
|
||||
'pixel_id',
|
||||
name=op.f('pk_addresses_pixels'),
|
||||
"address_id",
|
||||
"pixel_id",
|
||||
name=op.f("pk_addresses_pixels"),
|
||||
),
|
||||
sa.UniqueConstraint(
|
||||
'address_id',
|
||||
'grid_id',
|
||||
name=op.f('uq_addresses_pixels_on_address_id_grid_id'),
|
||||
"address_id",
|
||||
"grid_id",
|
||||
name=op.f("uq_addresses_pixels_on_address_id_grid_id"),
|
||||
),
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
|
|
@ -154,27 +154,27 @@ def upgrade():
|
|||
|
||||
def downgrade():
|
||||
"""Downgrade to revision f11cd76d2f45."""
|
||||
op.drop_table('addresses_pixels', schema=config.CLEAN_SCHEMA)
|
||||
op.drop_table("addresses_pixels", schema=config.CLEAN_SCHEMA)
|
||||
op.drop_constraint(
|
||||
'uq_addresses_on_id_city_id',
|
||||
'addresses',
|
||||
"uq_addresses_on_id_city_id",
|
||||
"addresses",
|
||||
type_=None,
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
op.drop_index(
|
||||
op.f('ix_pixels_on_n_y'),
|
||||
table_name='pixels',
|
||||
op.f("ix_pixels_on_n_y"),
|
||||
table_name="pixels",
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
op.drop_index(
|
||||
op.f('ix_pixels_on_n_x'),
|
||||
table_name='pixels',
|
||||
op.f("ix_pixels_on_n_x"),
|
||||
table_name="pixels",
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
op.drop_index(
|
||||
op.f('ix_pixels_on_grid_id'),
|
||||
table_name='pixels',
|
||||
op.f("ix_pixels_on_grid_id"),
|
||||
table_name="pixels",
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
op.drop_table('pixels', schema=config.CLEAN_SCHEMA)
|
||||
op.drop_table('grids', schema=config.CLEAN_SCHEMA)
|
||||
op.drop_table("pixels", schema=config.CLEAN_SCHEMA)
|
||||
op.drop_table("grids", schema=config.CLEAN_SCHEMA)
|
||||
|
|
|
|||
|
|
@ -13,33 +13,33 @@ from sqlalchemy.dialects import postgresql
|
|||
from velofy import configuration
|
||||
|
||||
|
||||
revision = 'e40623e10405'
|
||||
down_revision = '888e352d7526'
|
||||
revision = "e40623e10405"
|
||||
down_revision = "888e352d7526"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
config = configuration.make_config('testing' if os.getenv('TESTING') else 'production')
|
||||
config = configuration.make_config("testing" if os.getenv("TESTING") else "production")
|
||||
|
||||
|
||||
def upgrade():
|
||||
"""Upgrade to revision e40623e10405."""
|
||||
op.create_table(
|
||||
'forecasts',
|
||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||
sa.Column('pixel_id', sa.Integer(), nullable=False),
|
||||
sa.Column('start_at', sa.DateTime(), nullable=False),
|
||||
sa.Column('time_step', sa.SmallInteger(), nullable=False),
|
||||
sa.Column('training_horizon', sa.SmallInteger(), nullable=False),
|
||||
sa.Column('method', sa.Unicode(length=20), nullable=False),
|
||||
sa.Column('prediction', postgresql.DOUBLE_PRECISION(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('id', name=op.f('pk_forecasts')),
|
||||
"forecasts",
|
||||
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
|
||||
sa.Column("pixel_id", sa.Integer(), nullable=False),
|
||||
sa.Column("start_at", sa.DateTime(), nullable=False),
|
||||
sa.Column("time_step", sa.SmallInteger(), nullable=False),
|
||||
sa.Column("training_horizon", sa.SmallInteger(), nullable=False),
|
||||
sa.Column("method", sa.Unicode(length=20), nullable=False),
|
||||
sa.Column("prediction", postgresql.DOUBLE_PRECISION(), nullable=False),
|
||||
sa.PrimaryKeyConstraint("id", name=op.f("pk_forecasts")),
|
||||
sa.ForeignKeyConstraint(
|
||||
['pixel_id'],
|
||||
[f'{config.CLEAN_SCHEMA}.pixels.id'],
|
||||
name=op.f('fk_forecasts_to_pixels_via_pixel_id'),
|
||||
onupdate='RESTRICT',
|
||||
ondelete='RESTRICT',
|
||||
["pixel_id"],
|
||||
[f"{config.CLEAN_SCHEMA}.pixels.id"],
|
||||
name=op.f("fk_forecasts_to_pixels_via_pixel_id"),
|
||||
onupdate="RESTRICT",
|
||||
ondelete="RESTRICT",
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
"""
|
||||
|
|
@ -49,44 +49,44 @@ def upgrade():
|
|||
EXTRACT(HOUR FROM start_at) > 22
|
||||
)
|
||||
""",
|
||||
name=op.f('ck_forecasts_on_start_at_must_be_within_operating_hours'),
|
||||
name=op.f("ck_forecasts_on_start_at_must_be_within_operating_hours"),
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
'CAST(EXTRACT(MINUTES FROM start_at) AS INTEGER) % 15 = 0',
|
||||
name=op.f('ck_forecasts_on_start_at_minutes_must_be_quarters_of_the_hour'),
|
||||
"CAST(EXTRACT(MINUTES FROM start_at) AS INTEGER) % 15 = 0",
|
||||
name=op.f("ck_forecasts_on_start_at_minutes_must_be_quarters_of_the_hour"),
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
'CAST(EXTRACT(MICROSECONDS FROM start_at) AS INTEGER) % 1000000 = 0',
|
||||
name=op.f('ck_forecasts_on_start_at_allows_no_microseconds'),
|
||||
"CAST(EXTRACT(MICROSECONDS FROM start_at) AS INTEGER) % 1000000 = 0",
|
||||
name=op.f("ck_forecasts_on_start_at_allows_no_microseconds"),
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
'EXTRACT(SECONDS FROM start_at) = 0',
|
||||
name=op.f('ck_forecasts_on_start_at_allows_no_seconds'),
|
||||
"EXTRACT(SECONDS FROM start_at) = 0",
|
||||
name=op.f("ck_forecasts_on_start_at_allows_no_seconds"),
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
'time_step > 0',
|
||||
name=op.f('ck_forecasts_on_time_step_must_be_positive'),
|
||||
"time_step > 0",
|
||||
name=op.f("ck_forecasts_on_time_step_must_be_positive"),
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
'training_horizon > 0',
|
||||
name=op.f('ck_forecasts_on_training_horizon_must_be_positive'),
|
||||
"training_horizon > 0",
|
||||
name=op.f("ck_forecasts_on_training_horizon_must_be_positive"),
|
||||
),
|
||||
sa.UniqueConstraint(
|
||||
'pixel_id',
|
||||
'start_at',
|
||||
'time_step',
|
||||
'training_horizon',
|
||||
'method',
|
||||
"pixel_id",
|
||||
"start_at",
|
||||
"time_step",
|
||||
"training_horizon",
|
||||
"method",
|
||||
name=op.f(
|
||||
'uq_forecasts_on_pixel_id_start_at_time_step_training_horizon_method',
|
||||
"uq_forecasts_on_pixel_id_start_at_time_step_training_horizon_method",
|
||||
),
|
||||
),
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
op.create_index(
|
||||
op.f('ix_forecasts_on_pixel_id'),
|
||||
'forecasts',
|
||||
['pixel_id'],
|
||||
op.f("ix_forecasts_on_pixel_id"),
|
||||
"forecasts",
|
||||
["pixel_id"],
|
||||
unique=False,
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
|
|
@ -94,4 +94,4 @@ def upgrade():
|
|||
|
||||
def downgrade():
|
||||
"""Downgrade to revision 888e352d7526."""
|
||||
op.drop_table('forecasts', schema=config.CLEAN_SCHEMA)
|
||||
op.drop_table("forecasts", schema=config.CLEAN_SCHEMA)
|
||||
|
|
|
|||
|
|
@ -13,46 +13,46 @@ from sqlalchemy.dialects import postgresql
|
|||
from velofy import configuration
|
||||
|
||||
|
||||
revision = '26711cd3f9b9'
|
||||
down_revision = 'e40623e10405'
|
||||
revision = "26711cd3f9b9"
|
||||
down_revision = "e40623e10405"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
config = configuration.make_config('testing' if os.getenv('TESTING') else 'production')
|
||||
config = configuration.make_config("testing" if os.getenv("TESTING") else "production")
|
||||
|
||||
|
||||
def upgrade():
|
||||
"""Upgrade to revision 26711cd3f9b9."""
|
||||
op.alter_column(
|
||||
'forecasts',
|
||||
'method',
|
||||
new_column_name='model',
|
||||
"forecasts",
|
||||
"method",
|
||||
new_column_name="model",
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
op.add_column(
|
||||
'forecasts',
|
||||
sa.Column('low80', postgresql.DOUBLE_PRECISION(), nullable=True),
|
||||
"forecasts",
|
||||
sa.Column("low80", postgresql.DOUBLE_PRECISION(), nullable=True),
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
op.add_column(
|
||||
'forecasts',
|
||||
sa.Column('high80', postgresql.DOUBLE_PRECISION(), nullable=True),
|
||||
"forecasts",
|
||||
sa.Column("high80", postgresql.DOUBLE_PRECISION(), nullable=True),
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
op.add_column(
|
||||
'forecasts',
|
||||
sa.Column('low95', postgresql.DOUBLE_PRECISION(), nullable=True),
|
||||
"forecasts",
|
||||
sa.Column("low95", postgresql.DOUBLE_PRECISION(), nullable=True),
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
op.add_column(
|
||||
'forecasts',
|
||||
sa.Column('high95', postgresql.DOUBLE_PRECISION(), nullable=True),
|
||||
"forecasts",
|
||||
sa.Column("high95", postgresql.DOUBLE_PRECISION(), nullable=True),
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
op.create_check_constraint(
|
||||
op.f('ck_forecasts_on_ci_upper_and_lower_bounds'),
|
||||
'forecasts',
|
||||
op.f("ck_forecasts_on_ci_upper_and_lower_bounds"),
|
||||
"forecasts",
|
||||
"""
|
||||
NOT (
|
||||
low80 IS NULL AND high80 IS NOT NULL
|
||||
|
|
@ -67,8 +67,8 @@ def upgrade():
|
|||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
op.create_check_constraint(
|
||||
op.f('prediction_must_be_within_ci'),
|
||||
'forecasts',
|
||||
op.f("prediction_must_be_within_ci"),
|
||||
"forecasts",
|
||||
"""
|
||||
NOT (
|
||||
prediction < low80
|
||||
|
|
@ -83,8 +83,8 @@ def upgrade():
|
|||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
op.create_check_constraint(
|
||||
op.f('ci_upper_bound_greater_than_lower_bound'),
|
||||
'forecasts',
|
||||
op.f("ci_upper_bound_greater_than_lower_bound"),
|
||||
"forecasts",
|
||||
"""
|
||||
NOT (
|
||||
low80 > high80
|
||||
|
|
@ -95,8 +95,8 @@ def upgrade():
|
|||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
op.create_check_constraint(
|
||||
op.f('ci95_must_be_wider_than_ci80'),
|
||||
'forecasts',
|
||||
op.f("ci95_must_be_wider_than_ci80"),
|
||||
"forecasts",
|
||||
"""
|
||||
NOT (
|
||||
low80 < low95
|
||||
|
|
@ -111,28 +111,28 @@ def upgrade():
|
|||
def downgrade():
|
||||
"""Downgrade to revision e40623e10405."""
|
||||
op.alter_column(
|
||||
'forecasts',
|
||||
'model',
|
||||
new_column_name='method',
|
||||
"forecasts",
|
||||
"model",
|
||||
new_column_name="method",
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
op.drop_column(
|
||||
'forecasts',
|
||||
'low80',
|
||||
"forecasts",
|
||||
"low80",
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
op.drop_column(
|
||||
'forecasts',
|
||||
'high80',
|
||||
"forecasts",
|
||||
"high80",
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
op.drop_column(
|
||||
'forecasts',
|
||||
'low95',
|
||||
"forecasts",
|
||||
"low95",
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
op.drop_column(
|
||||
'forecasts',
|
||||
'high95',
|
||||
"forecasts",
|
||||
"high95",
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -129,13 +129,13 @@ from alembic import op
|
|||
from velofy import configuration
|
||||
|
||||
|
||||
revision = 'e86290e7305e'
|
||||
down_revision = '26711cd3f9b9'
|
||||
revision = "e86290e7305e"
|
||||
down_revision = "26711cd3f9b9"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
config = configuration.make_config('testing' if os.getenv('TESTING') else 'production')
|
||||
config = configuration.make_config("testing" if os.getenv("TESTING") else "production")
|
||||
|
||||
|
||||
def upgrade():
|
||||
|
|
@ -347,26 +347,26 @@ def upgrade():
|
|||
""",
|
||||
)
|
||||
op.create_unique_constraint(
|
||||
'uq_restaurants_on_id_address_id',
|
||||
'restaurants',
|
||||
['id', 'address_id'],
|
||||
"uq_restaurants_on_id_address_id",
|
||||
"restaurants",
|
||||
["id", "address_id"],
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
op.create_foreign_key(
|
||||
op.f('fk_orders_to_restaurants_via_restaurant_id_pickup_address_id'),
|
||||
'orders',
|
||||
'restaurants',
|
||||
['restaurant_id', 'pickup_address_id'],
|
||||
['id', 'address_id'],
|
||||
op.f("fk_orders_to_restaurants_via_restaurant_id_pickup_address_id"),
|
||||
"orders",
|
||||
"restaurants",
|
||||
["restaurant_id", "pickup_address_id"],
|
||||
["id", "address_id"],
|
||||
source_schema=config.CLEAN_SCHEMA,
|
||||
referent_schema=config.CLEAN_SCHEMA,
|
||||
onupdate='RESTRICT',
|
||||
ondelete='RESTRICT',
|
||||
onupdate="RESTRICT",
|
||||
ondelete="RESTRICT",
|
||||
)
|
||||
op.drop_constraint(
|
||||
'fk_orders_to_restaurants_via_restaurant_id',
|
||||
'orders',
|
||||
type_='foreignkey',
|
||||
"fk_orders_to_restaurants_via_restaurant_id",
|
||||
"orders",
|
||||
type_="foreignkey",
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
|
||||
|
|
@ -374,25 +374,25 @@ def upgrade():
|
|||
def downgrade():
|
||||
"""Downgrade to revision 26711cd3f9b9."""
|
||||
op.create_foreign_key(
|
||||
op.f('fk_orders_to_restaurants_via_restaurant_id'),
|
||||
'orders',
|
||||
'restaurants',
|
||||
['restaurant_id'],
|
||||
['id'],
|
||||
op.f("fk_orders_to_restaurants_via_restaurant_id"),
|
||||
"orders",
|
||||
"restaurants",
|
||||
["restaurant_id"],
|
||||
["id"],
|
||||
source_schema=config.CLEAN_SCHEMA,
|
||||
referent_schema=config.CLEAN_SCHEMA,
|
||||
onupdate='RESTRICT',
|
||||
ondelete='RESTRICT',
|
||||
onupdate="RESTRICT",
|
||||
ondelete="RESTRICT",
|
||||
)
|
||||
op.drop_constraint(
|
||||
'fk_orders_to_restaurants_via_restaurant_id_pickup_address_id',
|
||||
'orders',
|
||||
type_='foreignkey',
|
||||
"fk_orders_to_restaurants_via_restaurant_id_pickup_address_id",
|
||||
"orders",
|
||||
type_="foreignkey",
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
op.drop_constraint(
|
||||
'uq_restaurants_on_id_address_id',
|
||||
'restaurants',
|
||||
type_='unique',
|
||||
"uq_restaurants_on_id_address_id",
|
||||
"restaurants",
|
||||
type_="unique",
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -12,30 +12,30 @@ from alembic import op
|
|||
from velofy import configuration
|
||||
|
||||
|
||||
revision = 'c2af85bada01'
|
||||
down_revision = 'e86290e7305e'
|
||||
revision = "c2af85bada01"
|
||||
down_revision = "e86290e7305e"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
config = configuration.make_config('testing' if os.getenv('TESTING') else 'production')
|
||||
config = configuration.make_config("testing" if os.getenv("TESTING") else "production")
|
||||
|
||||
|
||||
def upgrade():
|
||||
"""Upgrade to revision c2af85bada01."""
|
||||
op.add_column(
|
||||
'forecasts',
|
||||
sa.Column('actual', sa.SmallInteger(), nullable=False),
|
||||
"forecasts",
|
||||
sa.Column("actual", sa.SmallInteger(), nullable=False),
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
op.create_check_constraint(
|
||||
op.f('ck_forecasts_on_actuals_must_be_non_negative'),
|
||||
'forecasts',
|
||||
'actual >= 0',
|
||||
op.f("ck_forecasts_on_actuals_must_be_non_negative"),
|
||||
"forecasts",
|
||||
"actual >= 0",
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
|
||||
|
||||
def downgrade():
|
||||
"""Downgrade to revision e86290e7305e."""
|
||||
op.drop_column('forecasts', 'actual', schema=config.CLEAN_SCHEMA)
|
||||
op.drop_column("forecasts", "actual", schema=config.CLEAN_SCHEMA)
|
||||
|
|
|
|||
|
|
@ -11,13 +11,13 @@ from alembic import op
|
|||
from velofy import configuration
|
||||
|
||||
|
||||
revision = '8bfb928a31f8'
|
||||
down_revision = 'c2af85bada01'
|
||||
revision = "8bfb928a31f8"
|
||||
down_revision = "c2af85bada01"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
config = configuration.make_config('testing' if os.getenv('TESTING') else 'production')
|
||||
config = configuration.make_config("testing" if os.getenv("TESTING") else "production")
|
||||
|
||||
|
||||
def upgrade():
|
||||
|
|
|
|||
|
|
@ -13,79 +13,79 @@ from sqlalchemy.dialects import postgresql
|
|||
from velofy import configuration
|
||||
|
||||
|
||||
revision = 'b4dd0b8903a5'
|
||||
down_revision = '8bfb928a31f8'
|
||||
revision = "b4dd0b8903a5"
|
||||
down_revision = "8bfb928a31f8"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
config = configuration.make_config('testing' if os.getenv('TESTING') else 'production')
|
||||
config = configuration.make_config("testing" if os.getenv("TESTING") else "production")
|
||||
|
||||
|
||||
def upgrade():
|
||||
"""Upgrade to revision b4dd0b8903a5."""
|
||||
op.create_table(
|
||||
'addresses_addresses',
|
||||
sa.Column('first_address_id', sa.Integer(), nullable=False),
|
||||
sa.Column('second_address_id', sa.Integer(), nullable=False),
|
||||
sa.Column('city_id', sa.SmallInteger(), nullable=False),
|
||||
sa.Column('air_distance', sa.Integer(), nullable=False),
|
||||
sa.Column('bicycle_distance', sa.Integer(), nullable=True),
|
||||
sa.Column('bicycle_duration', sa.Integer(), nullable=True),
|
||||
sa.Column('directions', postgresql.JSON(), nullable=True),
|
||||
"addresses_addresses",
|
||||
sa.Column("first_address_id", sa.Integer(), nullable=False),
|
||||
sa.Column("second_address_id", sa.Integer(), nullable=False),
|
||||
sa.Column("city_id", sa.SmallInteger(), nullable=False),
|
||||
sa.Column("air_distance", sa.Integer(), nullable=False),
|
||||
sa.Column("bicycle_distance", sa.Integer(), nullable=True),
|
||||
sa.Column("bicycle_duration", sa.Integer(), nullable=True),
|
||||
sa.Column("directions", postgresql.JSON(), nullable=True),
|
||||
sa.PrimaryKeyConstraint(
|
||||
'first_address_id',
|
||||
'second_address_id',
|
||||
name=op.f('pk_addresses_addresses'),
|
||||
"first_address_id",
|
||||
"second_address_id",
|
||||
name=op.f("pk_addresses_addresses"),
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
['first_address_id', 'city_id'],
|
||||
["first_address_id", "city_id"],
|
||||
[
|
||||
f'{config.CLEAN_SCHEMA}.addresses.id',
|
||||
f'{config.CLEAN_SCHEMA}.addresses.city_id',
|
||||
f"{config.CLEAN_SCHEMA}.addresses.id",
|
||||
f"{config.CLEAN_SCHEMA}.addresses.city_id",
|
||||
],
|
||||
name=op.f(
|
||||
'fk_addresses_addresses_to_addresses_via_first_address_id_city_id',
|
||||
"fk_addresses_addresses_to_addresses_via_first_address_id_city_id",
|
||||
),
|
||||
onupdate='RESTRICT',
|
||||
ondelete='RESTRICT',
|
||||
onupdate="RESTRICT",
|
||||
ondelete="RESTRICT",
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
['second_address_id', 'city_id'],
|
||||
["second_address_id", "city_id"],
|
||||
[
|
||||
f'{config.CLEAN_SCHEMA}.addresses.id',
|
||||
f'{config.CLEAN_SCHEMA}.addresses.city_id',
|
||||
f"{config.CLEAN_SCHEMA}.addresses.id",
|
||||
f"{config.CLEAN_SCHEMA}.addresses.city_id",
|
||||
],
|
||||
name=op.f(
|
||||
'fk_addresses_addresses_to_addresses_via_second_address_id_city_id',
|
||||
"fk_addresses_addresses_to_addresses_via_second_address_id_city_id",
|
||||
),
|
||||
onupdate='RESTRICT',
|
||||
ondelete='RESTRICT',
|
||||
onupdate="RESTRICT",
|
||||
ondelete="RESTRICT",
|
||||
),
|
||||
sa.UniqueConstraint(
|
||||
'first_address_id',
|
||||
'second_address_id',
|
||||
name=op.f('uq_addresses_addresses_on_first_address_id_second_address_id'),
|
||||
"first_address_id",
|
||||
"second_address_id",
|
||||
name=op.f("uq_addresses_addresses_on_first_address_id_second_address_id"),
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
'first_address_id < second_address_id',
|
||||
name=op.f('ck_addresses_addresses_on_distances_are_symmetric_for_bicycles'),
|
||||
"first_address_id < second_address_id",
|
||||
name=op.f("ck_addresses_addresses_on_distances_are_symmetric_for_bicycles"),
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
'0 <= air_distance AND air_distance < 20000',
|
||||
name=op.f('ck_addresses_addresses_on_realistic_air_distance'),
|
||||
"0 <= air_distance AND air_distance < 20000",
|
||||
name=op.f("ck_addresses_addresses_on_realistic_air_distance"),
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
'bicycle_distance < 25000',
|
||||
name=op.f('ck_addresses_addresses_on_realistic_bicycle_distance'),
|
||||
"bicycle_distance < 25000",
|
||||
name=op.f("ck_addresses_addresses_on_realistic_bicycle_distance"),
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
'air_distance <= bicycle_distance',
|
||||
name=op.f('ck_addresses_addresses_on_air_distance_is_shortest'),
|
||||
"air_distance <= bicycle_distance",
|
||||
name=op.f("ck_addresses_addresses_on_air_distance_is_shortest"),
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
'0 <= bicycle_duration AND bicycle_duration <= 3600',
|
||||
name=op.f('ck_addresses_addresses_on_realistic_bicycle_travel_time'),
|
||||
"0 <= bicycle_duration AND bicycle_duration <= 3600",
|
||||
name=op.f("ck_addresses_addresses_on_realistic_bicycle_travel_time"),
|
||||
),
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
|
|
@ -93,4 +93,4 @@ def upgrade():
|
|||
|
||||
def downgrade():
|
||||
"""Downgrade to revision 8bfb928a31f8."""
|
||||
op.drop_table('addresses_addresses', schema=config.CLEAN_SCHEMA)
|
||||
op.drop_table("addresses_addresses", schema=config.CLEAN_SCHEMA)
|
||||
|
|
|
|||
|
|
@ -12,13 +12,13 @@ from alembic import op
|
|||
from velofy import configuration
|
||||
|
||||
|
||||
revision = '81aa304d7a6e'
|
||||
down_revision = 'b4dd0b8903a5'
|
||||
revision = "81aa304d7a6e"
|
||||
down_revision = "b4dd0b8903a5"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
config = configuration.make_config('testing' if os.getenv('TESTING') else 'production')
|
||||
config = configuration.make_config("testing" if os.getenv("TESTING") else "production")
|
||||
|
||||
|
||||
def upgrade():
|
||||
|
|
@ -59,88 +59,88 @@ def upgrade():
|
|||
|
||||
# This `UniqueConstraint` is needed by the `replayed_orders` table below.
|
||||
op.create_unique_constraint(
|
||||
'uq_orders_on_id_ad_hoc',
|
||||
'orders',
|
||||
['id', 'ad_hoc'],
|
||||
"uq_orders_on_id_ad_hoc",
|
||||
"orders",
|
||||
["id", "ad_hoc"],
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
|
||||
op.create_table(
|
||||
'replay_simulations',
|
||||
sa.Column('id', sa.Integer, autoincrement=True),
|
||||
sa.Column('city_id', sa.SmallInteger, nullable=False),
|
||||
sa.Column('strategy', sa.Unicode(length=100), nullable=False),
|
||||
sa.Column('run', sa.SmallInteger, nullable=False),
|
||||
sa.PrimaryKeyConstraint('id', name=op.f('pk_replay_simulations')),
|
||||
"replay_simulations",
|
||||
sa.Column("id", sa.Integer, autoincrement=True),
|
||||
sa.Column("city_id", sa.SmallInteger, nullable=False),
|
||||
sa.Column("strategy", sa.Unicode(length=100), nullable=False),
|
||||
sa.Column("run", sa.SmallInteger, nullable=False),
|
||||
sa.PrimaryKeyConstraint("id", name=op.f("pk_replay_simulations")),
|
||||
sa.ForeignKeyConstraint(
|
||||
['city_id'],
|
||||
[f'{config.CLEAN_SCHEMA}.cities.id'],
|
||||
name=op.f('fk_replay_simulations_to_cities_via_city_id'),
|
||||
onupdate='RESTRICT',
|
||||
ondelete='RESTRICT',
|
||||
["city_id"],
|
||||
[f"{config.CLEAN_SCHEMA}.cities.id"],
|
||||
name=op.f("fk_replay_simulations_to_cities_via_city_id"),
|
||||
onupdate="RESTRICT",
|
||||
ondelete="RESTRICT",
|
||||
),
|
||||
sa.UniqueConstraint(
|
||||
'city_id',
|
||||
'strategy',
|
||||
'run',
|
||||
name=op.f('uq_replay_simulations_on_city_id_strategy_run'),
|
||||
"city_id",
|
||||
"strategy",
|
||||
"run",
|
||||
name=op.f("uq_replay_simulations_on_city_id_strategy_run"),
|
||||
),
|
||||
sa.CheckConstraint('run >= 0', name=op.f('run_is_a_count')),
|
||||
sa.CheckConstraint("run >= 0", name=op.f("run_is_a_count")),
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
|
||||
op.create_table(
|
||||
'replayed_orders',
|
||||
sa.Column('simulation_id', sa.Integer, primary_key=True),
|
||||
sa.Column('actual_order_id', sa.Integer, primary_key=True),
|
||||
sa.Column('ad_hoc', sa.Boolean, nullable=False),
|
||||
sa.Column('placed_at', sa.DateTime, nullable=False),
|
||||
sa.Column('scheduled_delivery_at', sa.DateTime),
|
||||
sa.Column('cancelled_at', sa.DateTime),
|
||||
sa.Column('estimated_prep_duration', sa.SmallInteger),
|
||||
sa.Column('restaurant_notified_at', sa.DateTime),
|
||||
sa.Column('restaurant_confirmed_at', sa.DateTime),
|
||||
sa.Column('restaurant_ready_at', sa.DateTime),
|
||||
sa.Column('dispatch_at', sa.DateTime),
|
||||
sa.Column('first_estimated_delivery_at', sa.DateTime),
|
||||
sa.Column('courier_id', sa.Integer),
|
||||
sa.Column('courier_notified_at', sa.DateTime),
|
||||
sa.Column('courier_accepted_at', sa.DateTime),
|
||||
sa.Column('utilization', sa.SmallInteger),
|
||||
sa.Column('reached_pickup_at', sa.DateTime),
|
||||
sa.Column('pickup_at', sa.DateTime),
|
||||
sa.Column('left_pickup_at', sa.DateTime),
|
||||
sa.Column('reached_delivery_at', sa.DateTime),
|
||||
sa.Column('delivery_at', sa.DateTime),
|
||||
"replayed_orders",
|
||||
sa.Column("simulation_id", sa.Integer, primary_key=True),
|
||||
sa.Column("actual_order_id", sa.Integer, primary_key=True),
|
||||
sa.Column("ad_hoc", sa.Boolean, nullable=False),
|
||||
sa.Column("placed_at", sa.DateTime, nullable=False),
|
||||
sa.Column("scheduled_delivery_at", sa.DateTime),
|
||||
sa.Column("cancelled_at", sa.DateTime),
|
||||
sa.Column("estimated_prep_duration", sa.SmallInteger),
|
||||
sa.Column("restaurant_notified_at", sa.DateTime),
|
||||
sa.Column("restaurant_confirmed_at", sa.DateTime),
|
||||
sa.Column("restaurant_ready_at", sa.DateTime),
|
||||
sa.Column("dispatch_at", sa.DateTime),
|
||||
sa.Column("first_estimated_delivery_at", sa.DateTime),
|
||||
sa.Column("courier_id", sa.Integer),
|
||||
sa.Column("courier_notified_at", sa.DateTime),
|
||||
sa.Column("courier_accepted_at", sa.DateTime),
|
||||
sa.Column("utilization", sa.SmallInteger),
|
||||
sa.Column("reached_pickup_at", sa.DateTime),
|
||||
sa.Column("pickup_at", sa.DateTime),
|
||||
sa.Column("left_pickup_at", sa.DateTime),
|
||||
sa.Column("reached_delivery_at", sa.DateTime),
|
||||
sa.Column("delivery_at", sa.DateTime),
|
||||
sa.PrimaryKeyConstraint(
|
||||
'simulation_id',
|
||||
'actual_order_id',
|
||||
name=op.f('pk_replayed_orders'),
|
||||
"simulation_id",
|
||||
"actual_order_id",
|
||||
name=op.f("pk_replayed_orders"),
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
['simulation_id'],
|
||||
[f'{config.CLEAN_SCHEMA}.replay_simulations.id'],
|
||||
name=op.f('fk_replayed_orders_to_replay_simulations_via_simulation_id'),
|
||||
onupdate='RESTRICT',
|
||||
ondelete='RESTRICT',
|
||||
["simulation_id"],
|
||||
[f"{config.CLEAN_SCHEMA}.replay_simulations.id"],
|
||||
name=op.f("fk_replayed_orders_to_replay_simulations_via_simulation_id"),
|
||||
onupdate="RESTRICT",
|
||||
ondelete="RESTRICT",
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
# Needs the `UniqueConstraint` from above.
|
||||
['actual_order_id', 'ad_hoc'],
|
||||
["actual_order_id", "ad_hoc"],
|
||||
[
|
||||
f'{config.CLEAN_SCHEMA}.orders.id',
|
||||
f'{config.CLEAN_SCHEMA}.orders.ad_hoc',
|
||||
f"{config.CLEAN_SCHEMA}.orders.id",
|
||||
f"{config.CLEAN_SCHEMA}.orders.ad_hoc",
|
||||
],
|
||||
name=op.f('fk_replayed_orders_to_orders_via_actual_order_id_ad_hoc'),
|
||||
onupdate='RESTRICT',
|
||||
ondelete='RESTRICT',
|
||||
name=op.f("fk_replayed_orders_to_orders_via_actual_order_id_ad_hoc"),
|
||||
onupdate="RESTRICT",
|
||||
ondelete="RESTRICT",
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
['courier_id'],
|
||||
[f'{config.CLEAN_SCHEMA}.couriers.id'],
|
||||
name=op.f('fk_replayed_orders_to_couriers_via_courier_id'),
|
||||
onupdate='RESTRICT',
|
||||
ondelete='RESTRICT',
|
||||
["courier_id"],
|
||||
[f"{config.CLEAN_SCHEMA}.couriers.id"],
|
||||
name=op.f("fk_replayed_orders_to_couriers_via_courier_id"),
|
||||
onupdate="RESTRICT",
|
||||
ondelete="RESTRICT",
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
"""
|
||||
|
|
@ -156,7 +156,7 @@ def upgrade():
|
|||
scheduled_delivery_at IS NOT NULL
|
||||
)
|
||||
""",
|
||||
name=op.f('either_ad_hoc_or_scheduled_order'),
|
||||
name=op.f("either_ad_hoc_or_scheduled_order"),
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
"""
|
||||
|
|
@ -169,7 +169,7 @@ def upgrade():
|
|||
)
|
||||
)
|
||||
""",
|
||||
name=op.f('ad_hoc_orders_within_business_hours'),
|
||||
name=op.f("ad_hoc_orders_within_business_hours"),
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
"""
|
||||
|
|
@ -190,7 +190,7 @@ def upgrade():
|
|||
)
|
||||
)
|
||||
""",
|
||||
name=op.f('scheduled_orders_within_business_hours'),
|
||||
name=op.f("scheduled_orders_within_business_hours"),
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
"""
|
||||
|
|
@ -204,7 +204,7 @@ def upgrade():
|
|||
= 0
|
||||
)
|
||||
""",
|
||||
name=op.f('scheduled_orders_must_be_at_quarters_of_an_hour'),
|
||||
name=op.f("scheduled_orders_must_be_at_quarters_of_an_hour"),
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
"""
|
||||
|
|
@ -212,7 +212,7 @@ def upgrade():
|
|||
EXTRACT(EPOCH FROM scheduled_delivery_at - placed_at) < 1800
|
||||
)
|
||||
""",
|
||||
name=op.f('scheduled_orders_not_within_30_minutes'),
|
||||
name=op.f("scheduled_orders_not_within_30_minutes"),
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
"""
|
||||
|
|
@ -244,7 +244,7 @@ def upgrade():
|
|||
delivery_at IS NOT NULL
|
||||
)
|
||||
""",
|
||||
name=op.f('orders_must_be_either_cancelled_or_fully_simulated'),
|
||||
name=op.f("orders_must_be_either_cancelled_or_fully_simulated"),
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
"""
|
||||
|
|
@ -272,19 +272,19 @@ def upgrade():
|
|||
delivery_at IS NOT NULL
|
||||
)
|
||||
""",
|
||||
name=op.f('cancellations_may_only_occur_before_pickup'),
|
||||
name=op.f("cancellations_may_only_occur_before_pickup"),
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
'0 <= estimated_prep_duration AND estimated_prep_duration <= 3600',
|
||||
name=op.f('estimated_prep_duration_between_0_and_3600'),
|
||||
"0 <= estimated_prep_duration AND estimated_prep_duration <= 3600",
|
||||
name=op.f("estimated_prep_duration_between_0_and_3600"),
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
'estimated_prep_duration % 60 = 0',
|
||||
name=op.f('estimated_prep_duration_must_be_whole_minutes'),
|
||||
"estimated_prep_duration % 60 = 0",
|
||||
name=op.f("estimated_prep_duration_must_be_whole_minutes"),
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
'0 <= utilization AND utilization <= 100',
|
||||
name=op.f('utilization_between_0_and_100'),
|
||||
"0 <= utilization AND utilization <= 100",
|
||||
name=op.f("utilization_between_0_and_100"),
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
"""
|
||||
|
|
@ -294,71 +294,71 @@ def upgrade():
|
|||
EXTRACT(HOUR FROM dispatch_at) < 11
|
||||
)
|
||||
""",
|
||||
name=op.f('orders_dispatched_in_business_hours'),
|
||||
name=op.f("orders_dispatched_in_business_hours"),
|
||||
),
|
||||
*(
|
||||
sa.CheckConstraint(
|
||||
constraint,
|
||||
name='ordered_timestamps_{index}'.format(index=index),
|
||||
name="ordered_timestamps_{index}".format(index=index),
|
||||
)
|
||||
for index, constraint in enumerate(
|
||||
(
|
||||
'placed_at < scheduled_delivery_at',
|
||||
'placed_at < cancelled_at',
|
||||
'placed_at < restaurant_notified_at',
|
||||
'placed_at < restaurant_confirmed_at',
|
||||
'placed_at < restaurant_ready_at',
|
||||
'placed_at < dispatch_at',
|
||||
'placed_at < first_estimated_delivery_at',
|
||||
'placed_at < courier_notified_at',
|
||||
'placed_at < courier_accepted_at',
|
||||
'placed_at < reached_pickup_at',
|
||||
'placed_at < pickup_at',
|
||||
'placed_at < left_pickup_at',
|
||||
'placed_at < reached_delivery_at',
|
||||
'placed_at < delivery_at',
|
||||
'cancelled_at > restaurant_notified_at',
|
||||
'cancelled_at > restaurant_confirmed_at',
|
||||
'cancelled_at > restaurant_ready_at',
|
||||
'cancelled_at > dispatch_at',
|
||||
'cancelled_at > courier_notified_at',
|
||||
'cancelled_at > courier_accepted_at',
|
||||
'cancelled_at > reached_pickup_at',
|
||||
'restaurant_notified_at < restaurant_confirmed_at',
|
||||
'restaurant_notified_at < restaurant_ready_at',
|
||||
'restaurant_notified_at < pickup_at',
|
||||
'restaurant_confirmed_at < restaurant_ready_at',
|
||||
'restaurant_confirmed_at < pickup_at',
|
||||
'restaurant_ready_at < pickup_at',
|
||||
'dispatch_at < first_estimated_delivery_at',
|
||||
'dispatch_at < courier_notified_at',
|
||||
'dispatch_at < courier_accepted_at',
|
||||
'dispatch_at < reached_pickup_at',
|
||||
'dispatch_at < pickup_at',
|
||||
'dispatch_at < left_pickup_at',
|
||||
'dispatch_at < reached_delivery_at',
|
||||
'dispatch_at < delivery_at',
|
||||
'courier_notified_at < courier_accepted_at',
|
||||
'courier_notified_at < reached_pickup_at',
|
||||
'courier_notified_at < pickup_at',
|
||||
'courier_notified_at < left_pickup_at',
|
||||
'courier_notified_at < reached_delivery_at',
|
||||
'courier_notified_at < delivery_at',
|
||||
'courier_accepted_at < reached_pickup_at',
|
||||
'courier_accepted_at < pickup_at',
|
||||
'courier_accepted_at < left_pickup_at',
|
||||
'courier_accepted_at < reached_delivery_at',
|
||||
'courier_accepted_at < delivery_at',
|
||||
'reached_pickup_at < pickup_at',
|
||||
'reached_pickup_at < left_pickup_at',
|
||||
'reached_pickup_at < reached_delivery_at',
|
||||
'reached_pickup_at < delivery_at',
|
||||
'pickup_at < left_pickup_at',
|
||||
'pickup_at < reached_delivery_at',
|
||||
'pickup_at < delivery_at',
|
||||
'left_pickup_at < reached_delivery_at',
|
||||
'left_pickup_at < delivery_at',
|
||||
'reached_delivery_at < delivery_at',
|
||||
"placed_at < scheduled_delivery_at",
|
||||
"placed_at < cancelled_at",
|
||||
"placed_at < restaurant_notified_at",
|
||||
"placed_at < restaurant_confirmed_at",
|
||||
"placed_at < restaurant_ready_at",
|
||||
"placed_at < dispatch_at",
|
||||
"placed_at < first_estimated_delivery_at",
|
||||
"placed_at < courier_notified_at",
|
||||
"placed_at < courier_accepted_at",
|
||||
"placed_at < reached_pickup_at",
|
||||
"placed_at < pickup_at",
|
||||
"placed_at < left_pickup_at",
|
||||
"placed_at < reached_delivery_at",
|
||||
"placed_at < delivery_at",
|
||||
"cancelled_at > restaurant_notified_at",
|
||||
"cancelled_at > restaurant_confirmed_at",
|
||||
"cancelled_at > restaurant_ready_at",
|
||||
"cancelled_at > dispatch_at",
|
||||
"cancelled_at > courier_notified_at",
|
||||
"cancelled_at > courier_accepted_at",
|
||||
"cancelled_at > reached_pickup_at",
|
||||
"restaurant_notified_at < restaurant_confirmed_at",
|
||||
"restaurant_notified_at < restaurant_ready_at",
|
||||
"restaurant_notified_at < pickup_at",
|
||||
"restaurant_confirmed_at < restaurant_ready_at",
|
||||
"restaurant_confirmed_at < pickup_at",
|
||||
"restaurant_ready_at < pickup_at",
|
||||
"dispatch_at < first_estimated_delivery_at",
|
||||
"dispatch_at < courier_notified_at",
|
||||
"dispatch_at < courier_accepted_at",
|
||||
"dispatch_at < reached_pickup_at",
|
||||
"dispatch_at < pickup_at",
|
||||
"dispatch_at < left_pickup_at",
|
||||
"dispatch_at < reached_delivery_at",
|
||||
"dispatch_at < delivery_at",
|
||||
"courier_notified_at < courier_accepted_at",
|
||||
"courier_notified_at < reached_pickup_at",
|
||||
"courier_notified_at < pickup_at",
|
||||
"courier_notified_at < left_pickup_at",
|
||||
"courier_notified_at < reached_delivery_at",
|
||||
"courier_notified_at < delivery_at",
|
||||
"courier_accepted_at < reached_pickup_at",
|
||||
"courier_accepted_at < pickup_at",
|
||||
"courier_accepted_at < left_pickup_at",
|
||||
"courier_accepted_at < reached_delivery_at",
|
||||
"courier_accepted_at < delivery_at",
|
||||
"reached_pickup_at < pickup_at",
|
||||
"reached_pickup_at < left_pickup_at",
|
||||
"reached_pickup_at < reached_delivery_at",
|
||||
"reached_pickup_at < delivery_at",
|
||||
"pickup_at < left_pickup_at",
|
||||
"pickup_at < reached_delivery_at",
|
||||
"pickup_at < delivery_at",
|
||||
"left_pickup_at < reached_delivery_at",
|
||||
"left_pickup_at < delivery_at",
|
||||
"reached_delivery_at < delivery_at",
|
||||
),
|
||||
)
|
||||
),
|
||||
|
|
@ -366,23 +366,23 @@ def upgrade():
|
|||
)
|
||||
|
||||
op.create_index(
|
||||
op.f('ix_replay_simulations_on_city_id'),
|
||||
'replay_simulations',
|
||||
['city_id'],
|
||||
op.f("ix_replay_simulations_on_city_id"),
|
||||
"replay_simulations",
|
||||
["city_id"],
|
||||
unique=False,
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
op.create_index(
|
||||
op.f('ix_replay_simulations_on_strategy'),
|
||||
'replay_simulations',
|
||||
['strategy'],
|
||||
op.f("ix_replay_simulations_on_strategy"),
|
||||
"replay_simulations",
|
||||
["strategy"],
|
||||
unique=False,
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
op.create_index(
|
||||
op.f('ix_replayed_orders_on_courier_id'),
|
||||
'replayed_orders',
|
||||
['courier_id'],
|
||||
op.f("ix_replayed_orders_on_courier_id"),
|
||||
"replayed_orders",
|
||||
["courier_id"],
|
||||
unique=False,
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
|
|
@ -390,11 +390,11 @@ def upgrade():
|
|||
|
||||
def downgrade():
|
||||
"""Downgrade to revision b4dd0b8903a5."""
|
||||
op.drop_table('replayed_orders', schema=config.CLEAN_SCHEMA)
|
||||
op.drop_table('replay_simulations', schema=config.CLEAN_SCHEMA)
|
||||
op.drop_table("replayed_orders", schema=config.CLEAN_SCHEMA)
|
||||
op.drop_table("replay_simulations", schema=config.CLEAN_SCHEMA)
|
||||
op.drop_constraint(
|
||||
'uq_orders_on_id_ad_hoc',
|
||||
'orders',
|
||||
"uq_orders_on_id_ad_hoc",
|
||||
"orders",
|
||||
type_=None,
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue