Skip to content

Commit

Permalink
Adding missing SQL compare to a fresh install
Browse files Browse the repository at this point in the history
  • Loading branch information
M0rgan01 committed Apr 23, 2024
1 parent ecf0ea9 commit e766f12
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 8 deletions.
56 changes: 56 additions & 0 deletions upgrade/php/remove_duplicates_from_authorization_role.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?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 remove_duplicates_from_authorization_role()
{

// 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(_DB_PREFIX_ . 'authorization_role', '`id_authorization_role` = ' . $elementToRemove['id_authorization_role']);
}
}
}
8 changes: 6 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 @@ -107,3 +107,7 @@ ALTER TABLE `PREFIX_tab` CHANGE `id_tab` `id_tab` INT(11) NOT NULL AUTO_INCREMEN

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:remove_duplicates_from_authorization_role(); */;

ALTER TABLE `PREFIX_authorization_role` ADD UNIQUE KEY `slug` (`slug`);
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;
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'); */;
7 changes: 7 additions & 0 deletions upgrade/sql/8.1.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ ALTER TABLE `PREFIX_product_shop` MODIFY COLUMN `redirect_type` ENUM(
UPDATE `PREFIX_product` SET `redirect_type` = 'default' WHERE `redirect_type` = '404' OR `redirect_type` = '' OR `redirect_type` IS NULL;
UPDATE `PREFIX_product_shop` SET `redirect_type` = 'default' WHERE `redirect_type` = '404' OR `redirect_type` = '' OR `redirect_type` IS NULL;

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';

/* Update feature flags */
/* PHP:ps_810_update_product_page_feature_flags(); */;

Expand Down
29 changes: 29 additions & 0 deletions upgrade/sql/8.1.6-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';
/* PHP:remove_duplicates_from_authorization_role(); */;
ALTER TABLE `PREFIX_authorization_role` ADD UNIQUE KEY `slug` (`slug`);

/* 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.6.0 */
ALTER TABLE `PREFIX_currency` ADD `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'); */;

/* 8.1.0 */
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';

0 comments on commit e766f12

Please sign in to comment.