Create missing foreign key constraints and indexes #62
Closed
Description
These should be created through liquibase.
Inventory Snapshot
alter table inventory_snapshot add constraint foreign key (location_id) references location(id);
alter table inventory_snapshot add constraint foreign key (product_id) references product(id);
alter table inventory_snapshot add constraint foreign key (inventory_item_id) references inventory_item(id);
create index date_idx on inventory_snapshot(date);
Product Group
ALTER TABLE product_group ADD PRIMARY KEY(id);
alter table product_group ADD CONSTRAINT FOREIGN KEY (category_id) references category(id);
alter table product_group_product add constraint foreign key (product_group_id) references product_group(id);
alter table product_group_product add constraint foreign key (product_id) references product(id);
NOTE: May need to delete broken product groups before executing the third and fourth statements.
delete from product_group_product where product_id in (select * from (select distinct product_id from product_group_product left outer join product on product_id = product.id where product.id is null) as p);
Product Tag
alter table product_tag add constraint foreign key (tag_id) references tag(id);
alter table product_tag add constraint foreign key (product_id) references product(id);