Drop product ID migration

Actually really really a lot of work and almost no benefit.
This commit is contained in:
Midgard 2020-02-25 16:29:43 +01:00
parent 57d65661de
commit 38e10257d2
Signed by: midgard
GPG key ID: 511C112F1331BBB4

View file

@ -47,10 +47,6 @@ LOCATION_LEGACY_TO_HLDS = {
30: "kebab_anadolu", 30: "kebab_anadolu",
} }
DISH_LEGACY_TO_HLDS = {
# TODO
}
def upgrade(): def upgrade():
# First the simple actions # First the simple actions
@ -86,19 +82,11 @@ def upgrade():
column("price", sa.Integer) column("price", sa.Integer)
) )
# Construct and execute queries # Construct and execute queries
new_dish_id = [ op.execute(text("""
order_item.update()
.where(order_item.c.product_id == old_id)
.values(dish_id=new_id)
for old_id, new_id in DISH_LEGACY_TO_HLDS.items()
]
dish_name_and_price_from_product = text("""
UPDATE order_item UPDATE order_item
SET dish_name = (SELECT product.name FROM product WHERE product.id = order_item.product_id), SET dish_name = (SELECT product.name FROM product WHERE product.id = order_item.product_id),
price = (SELECT product.price FROM product WHERE product.id = order_item.product_id)""" price = (SELECT product.price FROM product WHERE product.id = order_item.product_id)"""
) ))
for query in chain(new_dish_id, [dish_name_and_price_from_product]):
op.execute(query)
# Historical product data migrated, drop obsolete column and table # Historical product data migrated, drop obsolete column and table
op.execute(text("ALTER TABLE order_item DROP FOREIGN KEY order_item_ibfk_3")) op.execute(text("ALTER TABLE order_item DROP FOREIGN KEY order_item_ibfk_3"))
op.drop_column("order_item", "product_id") op.drop_column("order_item", "product_id")