mage2click / docker-magento-mutagen

Mage2click Docker-based development environment for Magento with mutagen.io sync for files on macOS
https://mage2.click
MIT License
68 stars 9 forks source link

Refine statement stripping DEFINER from SQL imports #61

Closed CNanninga closed 5 years ago

CNanninga commented 5 years ago

bin/dbimport includes a statement to strip DEFINER from SQL imports, perhaps only when said statement includes "*".

I've run across an example of a DEFINER in a DB dump that isn't covered by the above. This view definition might be related to M2 multi-source inventory:

CREATE ALGORITHM=UNDEFINED DEFINER=`magento`@`localhost` SQL SECURITY DEFINER VIEW `inventory_stock_1`
AS SELECT
   distinct `legacy_stock_status`.`product_id` AS `product_id`,
   `legacy_stock_status`.`website_id` AS `website_id`,
   `legacy_stock_status`.`stock_id` AS `stock_id`,
   `legacy_stock_status`.`qty` AS `quantity`,
   `legacy_stock_status`.`stock_status` AS `is_salable`,
   `product`.`sku` AS `sku`
FROM (`cataloginventory_stock_status` `legacy_stock_status` join `catalog_product_entity` `product` on((`legacy_stock_status`.`product_id` = `product`.`entity_id`)));

This statement modified from one originally posted by Max might be more robust to handle SQL like the above:

LC_ALL=C sed -E 's/DEFINER[ ]*=[ ]*`[^`]+`@`[^`]+`/DEFINER=CURRENT_USER/g' | docker-compose exec -T db \
    mysql -u"${MYSQL_USER}" -p"${MYSQL_PASSWORD}" "${MYSQL_DATABASE}"
u-maxx commented 5 years ago

Thanks @CNanninga!