Skip to content

Commit

Permalink
SQL script fix
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-kl1 committed Dec 12, 2019
1 parent 86c2cb8 commit 4d803ef
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 156 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ However the usage of this tool is advised.
**NOTICE**
- This tool has been test with a Magento Commerce 2.2.* version.
- This tool has not been tested with a split database configuration.
- This tool is written in MariaDB dialect.

## How to use

Expand Down
16 changes: 8 additions & 8 deletions scripts/catalogrule.sql
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,24 @@ WHERE 1;

-- Customer group
ALTER TABLE `catalogrule_customer_group`
DROP FOREIGN KEY IF EXISTS `CATALOGRULE_CUSTOMER_GROUP_ROW_ID_CATALOGRULE_ROW_ID`,
DROP FOREIGN KEY `CATALOGRULE_CUSTOMER_GROUP_ROW_ID_CATALOGRULE_ROW_ID`,
DROP PRIMARY KEY,
ADD PRIMARY KEY (`rule_id`,`customer_group_id`),
DROP COLUMN IF EXISTS `row_id`;
DROP COLUMN `row_id`;

-- Website
ALTER TABLE `catalogrule_website`
DROP FOREIGN KEY IF EXISTS `CATALOGRULE_WEBSITE_ROW_ID_CATALOGRULE_ROW_ID`,
DROP FOREIGN KEY `CATALOGRULE_WEBSITE_ROW_ID_CATALOGRULE_ROW_ID`,
DROP PRIMARY KEY,
ADD PRIMARY KEY (`rule_id`,`website_id`),
DROP COLUMN `row_id`;

-- Catalogrule
ALTER TABLE `catalogrule`
DROP FOREIGN KEY IF EXISTS `CATALOGRULE_RULE_ID_SEQUENCE_CATALOGRULE_SEQUENCE_VALUE`,
DROP COLUMN IF EXISTS `row_id`,
DROP COLUMN IF EXISTS `created_in`,
DROP COLUMN IF EXISTS `updated_in`,
DROP FOREIGN KEY `CATALOGRULE_RULE_ID_SEQUENCE_CATALOGRULE_SEQUENCE_VALUE`,
DROP COLUMN `row_id`,
DROP COLUMN `created_in`,
DROP COLUMN `updated_in`,
ADD PRIMARY KEY (`rule_id`),
MODIFY COLUMN `rule_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Entity ID';

Expand All @@ -63,4 +63,4 @@ ALTER TABLE `catalogrule_website`
-- Drop sequence --
-- ----------------

DROP TABLE IF EXISTS `sequence_catalogrule`;
DROP TABLE `sequence_catalogrule`;
44 changes: 22 additions & 22 deletions scripts/category.sql
Original file line number Diff line number Diff line change
Expand Up @@ -47,45 +47,45 @@ WHERE 1;

-- Datetime
ALTER TABLE `catalog_category_entity_datetime`
DROP FOREIGN KEY IF EXISTS `CAT_CTGR_ENTT_DTIME_ROW_ID_CAT_CTGR_ENTT_ROW_ID`,
DROP INDEX IF EXISTS `CATALOG_CATEGORY_ENTITY_DATETIME_ENTITY_ID_ATTRIBUTE_ID_STORE_ID`,
DROP FOREIGN KEY `CAT_CTGR_ENTT_DTIME_ROW_ID_CAT_CTGR_ENTT_ROW_ID`,
DROP INDEX `CATALOG_CATEGORY_ENTITY_DATETIME_ENTITY_ID_ATTRIBUTE_ID_STORE_ID`,
ADD CONSTRAINT `CATALOG_CATEGORY_ENTITY_DATETIME_ENTITY_ID_ATTRIBUTE_ID_STORE_ID` UNIQUE KEY (`entity_id`,`attribute_id`,`store_id`),
DROP COLUMN IF EXISTS `row_id`;
DROP COLUMN `row_id`;

-- Decimal
ALTER TABLE `catalog_category_entity_decimal`
DROP FOREIGN KEY IF EXISTS `CAT_CTGR_ENTT_DEC_ROW_ID_CAT_CTGR_ENTT_ROW_ID`,
DROP INDEX IF EXISTS `CATALOG_CATEGORY_ENTITY_DECIMAL_ENTITY_ID_ATTRIBUTE_ID_STORE_ID`,
DROP FOREIGN KEY `CAT_CTGR_ENTT_DEC_ROW_ID_CAT_CTGR_ENTT_ROW_ID`,
DROP INDEX `CATALOG_CATEGORY_ENTITY_DECIMAL_ENTITY_ID_ATTRIBUTE_ID_STORE_ID`,
ADD CONSTRAINT `CATALOG_CATEGORY_ENTITY_DECIMAL_ENTITY_ID_ATTRIBUTE_ID_STORE_ID` UNIQUE KEY (`entity_id`,`attribute_id`,`store_id`),
DROP COLUMN IF EXISTS `row_id`;
DROP COLUMN `row_id`;

-- Int
ALTER TABLE `catalog_category_entity_int`
DROP FOREIGN KEY IF EXISTS `CAT_CTGR_ENTT_INT_ROW_ID_CAT_CTGR_ENTT_ROW_ID`,
DROP INDEX IF EXISTS `CATALOG_CATEGORY_ENTITY_INT_ENTITY_ID_ATTRIBUTE_ID_STORE_ID`,
DROP FOREIGN KEY `CAT_CTGR_ENTT_INT_ROW_ID_CAT_CTGR_ENTT_ROW_ID`,
DROP INDEX `CATALOG_CATEGORY_ENTITY_INT_ENTITY_ID_ATTRIBUTE_ID_STORE_ID`,
ADD CONSTRAINT `CATALOG_CATEGORY_ENTITY_INT_ENTITY_ID_ATTRIBUTE_ID_STORE_ID` UNIQUE KEY (`entity_id`,`attribute_id`,`store_id`),
DROP COLUMN IF EXISTS `row_id`;
DROP COLUMN `row_id`;

-- Text
ALTER TABLE `catalog_category_entity_text`
DROP FOREIGN KEY IF EXISTS `CAT_CTGR_ENTT_TEXT_ROW_ID_CAT_CTGR_ENTT_ROW_ID`,
DROP INDEX IF EXISTS `CATALOG_CATEGORY_ENTITY_TEXT_ENTITY_ID_ATTRIBUTE_ID_STORE_ID`,
DROP FOREIGN KEY `CAT_CTGR_ENTT_TEXT_ROW_ID_CAT_CTGR_ENTT_ROW_ID`,
DROP INDEX `CATALOG_CATEGORY_ENTITY_TEXT_ENTITY_ID_ATTRIBUTE_ID_STORE_ID`,
ADD CONSTRAINT `CATALOG_CATEGORY_ENTITY_TEXT_ENTITY_ID_ATTRIBUTE_ID_STORE_ID` UNIQUE KEY (`entity_id`,`attribute_id`,`store_id`),
DROP COLUMN IF EXISTS `row_id`;
DROP COLUMN `row_id`;

-- Varchar
ALTER TABLE `catalog_category_entity_varchar`
DROP FOREIGN KEY IF EXISTS `CAT_CTGR_ENTT_VCHR_ROW_ID_CAT_CTGR_ENTT_ROW_ID`,
DROP INDEX IF EXISTS `CATALOG_CATEGORY_ENTITY_VARCHAR_ENTITY_ID_ATTRIBUTE_ID_STORE_ID`,
DROP FOREIGN KEY `CAT_CTGR_ENTT_VCHR_ROW_ID_CAT_CTGR_ENTT_ROW_ID`,
DROP INDEX `CATALOG_CATEGORY_ENTITY_VARCHAR_ENTITY_ID_ATTRIBUTE_ID_STORE_ID`,
ADD CONSTRAINT `CATALOG_CATEGORY_ENTITY_VARCHAR_ENTITY_ID_ATTRIBUTE_ID_STORE_ID` UNIQUE KEY (`entity_id`,`attribute_id`,`store_id`),
DROP COLUMN IF EXISTS `row_id`;
DROP COLUMN `row_id`;

-- Entity
ALTER TABLE `catalog_category_entity`
DROP FOREIGN KEY IF EXISTS `CAT_CTGR_ENTT_ENTT_ID_SEQUENCE_CAT_CTGR_SEQUENCE_VAL`,
DROP COLUMN IF EXISTS `row_id`,
DROP COLUMN IF EXISTS `created_in`,
DROP COLUMN IF EXISTS `updated_in`,
DROP FOREIGN KEY `CAT_CTGR_ENTT_ENTT_ID_SEQUENCE_CAT_CTGR_SEQUENCE_VAL`,
DROP COLUMN `row_id`,
DROP COLUMN `created_in`,
DROP COLUMN `updated_in`,
MODIFY COLUMN `entity_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Entity ID',
ADD PRIMARY KEY (`entity_id`);

Expand All @@ -106,11 +106,11 @@ ALTER TABLE `catalog_category_entity_varchar`
-- ----------------

ALTER TABLE `catalog_category_product`
DROP FOREIGN KEY IF EXISTS `CAT_CTGR_PRD_CTGR_ID_SEQUENCE_CAT_CTGR_SEQUENCE_VAL`,
DROP FOREIGN KEY `CAT_CTGR_PRD_CTGR_ID_SEQUENCE_CAT_CTGR_SEQUENCE_VAL`,
ADD CONSTRAINT `CAT_CTGR_PRD_CTGR_ID_CAT_CTGR_ENTT_ENTT_ID` FOREIGN KEY (`category_id`) REFERENCES `catalog_category_entity` (`entity_id`) ON DELETE CASCADE ON UPDATE RESTRICT;

ALTER TABLE `catalog_url_rewrite_product_category`
DROP FOREIGN KEY IF EXISTS `CAT_URL_REWRITE_PRD_CTGR_CTGR_ID_SEQUENCE_CAT_CTGR_SEQUENCE_VAL`,
DROP FOREIGN KEY `CAT_URL_REWRITE_PRD_CTGR_CTGR_ID_SEQUENCE_CAT_CTGR_SEQUENCE_VAL`,
ADD CONSTRAINT `CAT_URL_REWRITE_PRD_CTGR_CTGR_ID_CAT_CTGR_ENTT_ENTT_ID` FOREIGN KEY (`category_id`) REFERENCES `catalog_category_entity` (`entity_id`) ON DELETE CASCADE ON UPDATE RESTRICT;

DROP TABLE IF EXISTS `sequence_catalog_category`;
DROP TABLE `sequence_catalog_category`;
26 changes: 13 additions & 13 deletions scripts/cms.sql
Original file line number Diff line number Diff line change
Expand Up @@ -40,34 +40,34 @@ WHERE 1;

-- Update the `block_id` relation link for block store
ALTER TABLE `cms_block_store`
DROP FOREIGN KEY IF EXISTS `CMS_BLOCK_STORE_ROW_ID_CMS_BLOCK_ROW_ID`,
DROP FOREIGN KEY `CMS_BLOCK_STORE_ROW_ID_CMS_BLOCK_ROW_ID`,
DROP PRIMARY KEY,
DROP COLUMN IF EXISTS `row_id`,
DROP COLUMN `row_id`,
ADD PRIMARY KEY (`block_id`,`store_id`);

SET FOREIGN_KEY_CHECKS = 0; # Many third party modules refers to the `block_id` column, we prevent blocking.
ALTER TABLE `cms_block`
DROP FOREIGN KEY IF EXISTS `CMS_BLOCK_BLOCK_ID_SEQUENCE_CMS_BLOCK_SEQUENCE_VALUE`,
DROP COLUMN IF EXISTS `row_id`,
DROP COLUMN IF EXISTS `created_in`,
DROP COLUMN IF EXISTS `updated_in`,
DROP FOREIGN KEY `CMS_BLOCK_BLOCK_ID_SEQUENCE_CMS_BLOCK_SEQUENCE_VALUE`,
DROP COLUMN `row_id`,
DROP COLUMN `created_in`,
DROP COLUMN `updated_in`,
ADD PRIMARY KEY (`block_id`),
MODIFY COLUMN `block_id` SMALLINT(6) NOT NULL AUTO_INCREMENT COMMENT 'Entity ID';
SET FOREIGN_KEY_CHECKS = 1;

-- Update the `page_id` relation link for page store
ALTER TABLE `cms_page_store`
DROP FOREIGN KEY IF EXISTS `CMS_PAGE_STORE_ROW_ID_CMS_PAGE_ROW_ID`,
DROP FOREIGN KEY `CMS_PAGE_STORE_ROW_ID_CMS_PAGE_ROW_ID`,
DROP PRIMARY KEY,
DROP COLUMN IF EXISTS `row_id`,
DROP COLUMN `row_id`,
ADD PRIMARY KEY (`page_id`,`store_id`);

SET FOREIGN_KEY_CHECKS = 0; # Many third party modules refers to the `page_id` column, we prevent blocking.
ALTER TABLE `cms_page`
DROP FOREIGN KEY IF EXISTS `CMS_PAGE_PAGE_ID_SEQUENCE_CMS_PAGE_SEQUENCE_VALUE`,
DROP COLUMN IF EXISTS `row_id`,
DROP COLUMN IF EXISTS `created_in`,
DROP COLUMN IF EXISTS `updated_in`,
DROP FOREIGN KEY `CMS_PAGE_PAGE_ID_SEQUENCE_CMS_PAGE_SEQUENCE_VALUE`,
DROP COLUMN `row_id`,
DROP COLUMN `created_in`,
DROP COLUMN `updated_in`,
ADD PRIMARY KEY (`page_id`),
MODIFY COLUMN `page_id` SMALLINT(6) NOT NULL AUTO_INCREMENT COMMENT 'Entity ID';
SET FOREIGN_KEY_CHECKS = 1;
Expand All @@ -84,4 +84,4 @@ ALTER TABLE `cms_page_store`
-- Drop sequence --
-- ----------------

DROP TABLE IF EXISTS `sequence_cms_page`,`sequence_cms_block`;
DROP TABLE `sequence_cms_page`,`sequence_cms_block`;
Loading

0 comments on commit 4d803ef

Please sign in to comment.