From 3d79d61a84773c771e8e56a7057cd5f13ef6feac Mon Sep 17 00:00:00 2001 From: Martin Carlsson Date: Mon, 9 Nov 2020 09:45:18 +0100 Subject: [PATCH] P5-6245 add market_id to product_blacklist table --- migrations/000.261.sql | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 migrations/000.261.sql diff --git a/migrations/000.261.sql b/migrations/000.261.sql new file mode 100644 index 0000000..09c6a2a --- /dev/null +++ b/migrations/000.261.sql @@ -0,0 +1,20 @@ +-- P5-6245: add market id to product blacklist table + +alter table product_blacklist + add column market_id integer; + +alter table product_blacklist + add constraint market_fkey + foreign key (market_id) + references markets(id) match simple; + +update product_blacklist SET market_id = ( + select markets.id from markets + join locales on markets.locale_id = locales.id + where locales.value = product_blacklist.language_id || '_' || product_blacklist.territory_id +); + +alter table product_blacklist + alter column market_id set not null; + +create unique index on product_blacklist (product_id, group_id, market_id);