Skip to content

Commit

Permalink
Merge pull request #689 from M0rgan01/fix/sql
Browse files Browse the repository at this point in the history
Update missing SQL compare to a fresh install
  • Loading branch information
M0rgan01 committed May 13, 2024
2 parents 16f65e3 + 8f414ea commit dd9afb1
Show file tree
Hide file tree
Showing 10 changed files with 140 additions and 10 deletions.
67 changes: 67 additions & 0 deletions upgrade/php/add_missing_unique_key_from_authorization_role.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/

// Allows you to catch up on a forgotten uniqueness constraint on the roles
function add_missing_unique_key_from_authorization_role()
{
// Verify if we need to create unique key
$keys = Db::getInstance()->executeS(
'SHOW KEYS FROM ' . _DB_PREFIX_ . "authorization_role WHERE Key_name='slug'"
);

if (!empty($keys)) {
return;
}

// We recover the duplicates that we want to keep
$duplicates = Db::getInstance()->executeS(
'SELECT MIN(id_authorization_role) AS keep_ID, slug FROM ' . _DB_PREFIX_ . 'authorization_role GROUP BY slug HAVING COUNT(*) > 1'
);

if (empty($duplicates)) {
return;
}

foreach ($duplicates as $duplicate) {
// We recover the duplicates that we want to remove
$elementsToRemoves = Db::getInstance()->executeS(
'SELECT id_authorization_role FROM ' . _DB_PREFIX_ . "authorization_role WHERE slug = '" . $duplicate['slug'] . "' AND id_authorization_role != " . $duplicate['keep_ID']
);

foreach ($elementsToRemoves as $elementToRemove) {
// We update the access table which may have used a duplicate role
Db::getInstance()->execute(
'UPDATE ' . _DB_PREFIX_ . "access SET id_authorization_role = '" . $duplicate['keep_ID'] . "' WHERE id_authorization_role = " . $elementToRemove['id_authorization_role']
);
// We remove the role
Db::getInstance()->delete('authorization_role', '`id_authorization_role` = ' . (int) $elementToRemove['id_authorization_role']);
}
}

Db::getInstance()->execute(
'ALTER TABLE ' . _DB_PREFIX_ . 'authorization_role ADD UNIQUE KEY `slug` (`slug`)'
);
}
9 changes: 7 additions & 2 deletions upgrade/sql/1.7.1.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ ALTER TABLE `PREFIX_product_shop` CHANGE `redirect_type` `redirect_type`
ENUM('','404','301-product','302-product','301-category','302-category')
CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '';

ALTER TABLE `PREFIX_product` CHANGE `id_product_redirected` `id_type_redirected` INT(10) NOT NULL DEFAULT '0';
ALTER TABLE `PREFIX_product_shop` CHANGE `id_product_redirected` `id_type_redirected` INT(10) NOT NULL DEFAULT '0';
ALTER TABLE `PREFIX_product` CHANGE `id_product_redirected` `id_type_redirected` INT(10) UNSIGNED NOT NULL DEFAULT '0';
ALTER TABLE `PREFIX_product_shop` CHANGE `id_product_redirected` `id_type_redirected` INT(10) UNSIGNED NOT NULL DEFAULT '0';

INSERT INTO `PREFIX_hook` (`id_hook`, `name`, `title`, `description`, `position`) VALUES
(NULL, 'filterCmsContent', 'Filter the content page', 'This hook is called just before fetching content page', '1'),
Expand Down Expand Up @@ -104,6 +104,11 @@ ALTER TABLE `PREFIX_shop` CHANGE `id_shop_group` `id_shop_group` INT(11) NOT NUL
ALTER TABLE `PREFIX_shop_group` CHANGE `id_shop_group` `id_shop_group` INT(11) NOT NULL AUTO_INCREMENT;

ALTER TABLE `PREFIX_tab` CHANGE `id_tab` `id_tab` INT(11) NOT NULL AUTO_INCREMENT;
ALTER TABLE `PREFIX_tab` CHANGE `active` `active` TINYINT(1) NOT NULL;
ALTER TABLE `PREFIX_tab` CHANGE `hide_host_mode` `hide_host_mode` TINYINT(1) NOT NULL;
ALTER TABLE `PREFIX_tab` CHANGE `icon` `icon` VARCHAR(32) DEFAULT NULL;

ALTER TABLE `PREFIX_tab_lang` CHANGE `id_tab` `id_tab` INT(11) NOT NULL;
ALTER TABLE `PREFIX_tab_lang` CHANGE `id_lang` `id_lang` INT(11) NOT NULL;

/* PHP:add_missing_unique_key_from_authorization_role(); */;
5 changes: 5 additions & 0 deletions upgrade/sql/1.7.2.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ ALTER TABLE `PREFIX_supply_order_detail` CHANGE `isbn` `isbn` VARCHAR(32) NULL D
ALTER TABLE `PREFIX_stock_available` ADD `physical_quantity` INT NOT NULL DEFAULT '0' AFTER `quantity`;
ALTER TABLE `PREFIX_stock_available` ADD `reserved_quantity` INT NOT NULL DEFAULT '0' AFTER `physical_quantity`;
ALTER TABLE `PREFIX_stock_mvt` CHANGE `id_stock` `id_stock` INT(11) UNSIGNED NOT NULL COMMENT 'since ps 1.7 corresponding to id_stock_available';
ALTER TABLE `PREFIX_stock_mvt` CHANGE `employee_lastname` `employee_lastname` varchar(32) DEFAULT NULL;
ALTER TABLE `PREFIX_stock_mvt` CHANGE `employee_firstname` `employee_firstname` varchar(32) DEFAULT NULL;
ALTER TABLE `PREFIX_stock_mvt` CHANGE `sign` `sign` smallint(6) NOT NULL DEFAULT '1';

UPDATE `PREFIX_configuration` SET `value` = 0 WHERE `name` = "PS_ADVANCED_STOCK_MANAGEMENT";
/* PHP:add_new_status_stock(); */;

ALTER TABLE `PREFIX_carrier_lang` CHANGE `delay` `delay` varchar(512) DEFAULT NULL;
4 changes: 2 additions & 2 deletions upgrade/sql/1.7.5.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ ALTER TABLE `PREFIX_customer`
CHANGE `passwd` `passwd` VARCHAR(255) NOT NULL;

ALTER TABLE `PREFIX_manufacturer_lang`
CHANGE `meta_title` `meta_title` VARCHAR(255) NOT NULL,
CHANGE `meta_title` `meta_title` VARCHAR(255) DEFAULT NULL,
CHANGE `meta_description` `meta_description` VARCHAR(512) DEFAULT NULL;

ALTER TABLE `PREFIX_employee`
Expand Down Expand Up @@ -73,7 +73,7 @@ ALTER TABLE `PREFIX_warehouse`
CHANGE `reference` `reference` varchar(64) DEFAULT NULL;

ALTER TABLE `PREFIX_stock`
CHANGE `reference` `reference` varchar(64) DEFAULT NULL;
CHANGE `reference` `reference` varchar(64) NOT NULL;

ALTER TABLE `PREFIX_supply_order_detail`
CHANGE `reference` `reference` varchar(64) NOT NULL,
Expand Down
2 changes: 1 addition & 1 deletion upgrade/sql/1.7.6.0.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
SET SESSION sql_mode = '';
SET NAMES 'utf8';

ALTER TABLE `PREFIX_currency` ADD `numeric_iso_code` varchar(3) NOT NULL DEFAULT '0' AFTER `iso_code`;
ALTER TABLE `PREFIX_currency` ADD `numeric_iso_code` varchar(3) DEFAULT NULL AFTER `iso_code`;
ALTER TABLE `PREFIX_currency` ADD `precision` int(2) NOT NULL DEFAULT 6 AFTER `numeric_iso_code`;
ALTER TABLE `PREFIX_currency` ADD KEY `currency_iso_code` (`iso_code`);

Expand Down
2 changes: 1 addition & 1 deletion upgrade/sql/1.7.7.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ ALTER TABLE `PREFIX_order_payment` CHANGE `amount` `amount` DECIMAL(20, 6) NOT N

/* attribute_impact price */
UPDATE `PREFIX_attribute_impact` SET `price` = RIGHT(`price`, 17) WHERE LENGTH(`price`) > 17;
ALTER TABLE `PREFIX_attribute_impact` CHANGE `price` `price` DECIMAL(20, 6) NOT NULL DEFAULT '0.000000';
ALTER TABLE `PREFIX_attribute_impact` CHANGE `price` `price` DECIMAL(20, 6) NOT NULL;

/* cart_rule minimum_amount & reduction_amount */
UPDATE `PREFIX_cart_rule` SET `minimum_amount` = RIGHT(`minimum_amount`, 17) WHERE LENGTH(`minimum_amount`) > 17;
Expand Down
6 changes: 4 additions & 2 deletions upgrade/sql/1.7.8.0.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
SET SESSION sql_mode='';
SET NAMES 'utf8mb4';

DROP TABLE IF EXISTS `PREFIX_order_slip_detail_tax`;

INSERT INTO `PREFIX_hook` (`id_hook`, `name`, `title`, `description`, `position`) VALUES
(NULL, 'actionPresentCart', 'Cart Presenter', 'This hook is called before a cart is presented', '1'),
(NULL, 'actionPresentOrder', 'Order footer', 'This hook is called before an order is presented', '1'),
Expand Down Expand Up @@ -170,8 +172,8 @@ ALTER TABLE `PREFIX_product` MODIFY COLUMN `redirect_type` ENUM(
) NOT NULL DEFAULT '404';

ALTER TABLE `PREFIX_product` ADD `product_type` ENUM(
'standard', 'pack', 'virtual', 'combinations'
) NOT NULL DEFAULT 'standard';
'standard', 'pack', 'virtual', 'combinations', ''
) NOT NULL DEFAULT '';

/* First set all products to standard type, then update them based on cached columns that identify the type */
UPDATE `PREFIX_product` SET `product_type` = "standard";
Expand Down
6 changes: 4 additions & 2 deletions upgrade/sql/8.0.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ SET NAMES 'utf8mb4';
DROP TABLE IF EXISTS `PREFIX_referrer`;
DROP TABLE IF EXISTS `PREFIX_referrer_cache`;
DROP TABLE IF EXISTS `PREFIX_referrer_shop`;
DROP TABLE IF EXISTS `PREFIX_attribute_impact`;

/* Remove page Referrers */
## Remove Tabs
Expand Down Expand Up @@ -191,8 +192,8 @@ ALTER TABLE `PREFIX_product` MODIFY COLUMN `redirect_type` ENUM(
'404', '410', '301-product', '302-product', '301-category', '302-category'
) NOT NULL DEFAULT '404';
ALTER TABLE `PREFIX_product_shop` MODIFY COLUMN `redirect_type` ENUM(
'404', '410', '301-product', '302-product', '301-category', '302-category'
) NOT NULL DEFAULT '404';
'', '404', '410', '301-product', '302-product', '301-category', '302-category'
) NOT NULL DEFAULT '';

ALTER TABLE `PREFIX_tab` ADD route_name VARCHAR(256) DEFAULT NULL;

Expand Down Expand Up @@ -237,3 +238,4 @@ UPDATE `PREFIX_carrier` SET `name` = 'Click and collect' WHERE `name` = '0';
/* Remove deprecated columns */
/* PHP:drop_column_if_exists('product_attribute', 'location'); */;
/* PHP:drop_column_if_exists('product_attribute', 'quantity'); */;
/* PHP:drop_column_if_exists('orders', 'shipping_number'); */;
29 changes: 29 additions & 0 deletions upgrade/sql/8.1.7-catchup.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* script intended for catching up with requests forgotten since 1.7 */

/* 1.7.1.0 */
ALTER TABLE `PREFIX_product` CHANGE `id_type_redirected` `id_type_redirected` INT(10) UNSIGNED NOT NULL DEFAULT '0';
ALTER TABLE `PREFIX_product_shop` CHANGE `id_type_redirected` `id_type_redirected` INT(10) UNSIGNED NOT NULL DEFAULT '0';

ALTER TABLE `PREFIX_tab` CHANGE `active` `active` TINYINT(1) NOT NULL;
ALTER TABLE `PREFIX_tab` CHANGE `icon` `icon` VARCHAR(32) DEFAULT NULL;

/* PHP:add_missing_unique_key_from_authorization_role(); */;

/* 1.7.2.0 */
ALTER TABLE `PREFIX_stock_mvt` CHANGE `sign` `sign` SMALLINT(6) NOT NULL DEFAULT '1';
ALTER TABLE `PREFIX_carrier_lang` CHANGE `delay` `delay` VARCHAR(512) DEFAULT NULL;

/* 1.7.5.0 */
ALTER TABLE `PREFIX_manufacturer_lang` CHANGE `meta_title` `meta_title` VARCHAR(255) DEFAULT NULL;
UPDATE `PREFIX_stock` SET `reference` = '' WHERE `reference` IS NULL;
ALTER TABLE `PREFIX_stock` CHANGE `reference` `reference` VARCHAR(64) NOT NULL;

/* 1.7.6.0 */
ALTER TABLE `PREFIX_currency` CHANGE `numeric_iso_code` `numeric_iso_code` VARCHAR(3) DEFAULT NULL AFTER `iso_code`;

/* 1.7.8.0 */
DROP TABLE IF EXISTS `PREFIX_order_slip_detail_tax`;

/* 8.0.0 */
DROP TABLE IF EXISTS `PREFIX_attribute_impact`;
/* PHP:drop_column_if_exists('orders', 'shipping_number'); */;
20 changes: 20 additions & 0 deletions upgrade/sql/9.0.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,23 @@ ALTER TABLE `PREFIX_order_detail` MODIFY COLUMN `product_ean13` VARCHAR(20);
ALTER TABLE `PREFIX_product_attribute` MODIFY COLUMN `ean13` VARCHAR(20);
ALTER TABLE `PREFIX_stock` MODIFY COLUMN `ean13` VARCHAR(20);
ALTER TABLE `PREFIX_supply_order_detail` MODIFY COLUMN `ean13` VARCHAR(20);

/* Change all empty string to 'default' */
UPDATE `PREFIX_product` SET `redirect_type` = 'default' WHERE `redirect_type` = '';
UPDATE `PREFIX_product_shop` SET `redirect_type` = 'default' WHERE `redirect_type` = '';

ALTER TABLE `PREFIX_product` MODIFY COLUMN `redirect_type` ENUM(
'404','410','301-product','302-product','301-category','302-category','200-displayed','404-displayed','410-displayed','default'
) NOT NULL DEFAULT 'default';
ALTER TABLE `PREFIX_product_shop` MODIFY COLUMN `redirect_type` ENUM(
'404','410','301-product','302-product','301-category','302-category','200-displayed','404-displayed','410-displayed','default'
) NOT NULL DEFAULT 'default';


/* Fixing duplicates for table "accessory" where can be duplicate records from older version of PrestaShop, because of missing PRIMARY index */
CREATE TABLE `PREFIX_accessory_tmp` SELECT DISTINCT `id_product_1`, `id_product_2` FROM `PREFIX_accessory`;
ALTER TABLE `PREFIX_accessory_tmp` ADD CONSTRAINT accessory_product PRIMARY KEY (`id_product_1`, `id_product_2`);
DROP TABLE `PREFIX_accessory`;
RENAME TABLE `PREFIX_accessory_tmp` TO `PREFIX_accessory`;

ALTER TABLE `PREFIX_stock_mvt` MODIFY `id_supply_order` INT(11) DEFAULT '0';

0 comments on commit dd9afb1

Please sign in to comment.