CREATE TABLE pp_dictionaries_units ( id INT(11) NOT NULL AUTO_INCREMENT , PRIMARY KEY (id)) ENGINE = InnoDB;
CREATE TABLE pp_dictionaries_units_langs ( id INT NOT NULL AUTO_INCREMENT , unit_id INT NOT NULL , lang_id VARCHAR(255) NOT NULL , text VARCHAR(255) NOT NULL , PRIMARY KEY (id)) ENGINE = InnoDB CHARSET=utf8 COLLATE utf8_polish_ci;
CREATE TABLE pp_dictionaries_units_langs ( id INT NOT NULL AUTO_INCREMENT , unit_id INT NOT NULL , lang_id VARCHAR(255) NOT NULL , text VARCHAR(255) NOT NULL , PRIMARY KEY (id)) ENGINE = InnoDB CHARSET=utf8 COLLATE utf8_polish_ci;
ALTER TABLE pp_dictionaries_units_langs ADD INDEX(lang_id);
ALTER TABLE pp_dictionaries_units_langs ADD FOREIGN KEY (lang_id) REFERENCES pp_langs(id) ON DELETE CASCADE ON UPDATE CASCADE; ALTER TABLE pp_dictionaries_units_langs ADD FOREIGN KEY (unit_id) REFERENCES pp_dictionaries_units(id) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE pp_shop_products ADD product_unit_id INT(11) NULL DEFAULT NULL AFTER price_history_date;
ALTER TABLE pp_shop_products ADD INDEX(product_unit_id);
ALTER TABLE pp_shop_products ADD FOREIGN KEY (product_unit_id) REFERENCES pp_dictionaries_units(id) ON DELETE SET NULL ON UPDATE SET NULL; (edited)
ALTER TABLE `pp_shop_products` CHANGE COLUMN `product_unit_id` `product_unit_id` INT(11) NULL DEFAULT NULL AFTER `price_history_date`;
ALTER TABLE `pp_shop_products` CHANGE COLUMN `product_unit_id` `product_unit_id` INT(11) NULL AFTER `price_history_date`, ADD COLUMN `weight` DECIMAL(12,4) NULL DEFAULT NULL AFTER `product_unit_id`;
RENAME TABLE `pp_dictionaries_units` TO `pp_units`;
RENAME TABLE `pp_dictionaries_units_langs` TO `pp_units_langs`;
ALTER TABLE `pp_shop_products` CHANGE COLUMN `baselinker_product_id` `baselinker_product_id` INT(11) NULL AFTER `weight`;
ALTER TABLE `pp_shop_products` ADD COLUMN `baselinker_get_data_date` DATETIME NULL DEFAULT NULL AFTER `baselinker_product_id`;