Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Database Rollback not working M2.3.0 #21151

Merged
merged 2 commits into from
Mar 2, 2019
Merged

Database Rollback not working M2.3.0 #21151

merged 2 commits into from
Mar 2, 2019

Conversation

Stepa4man
Copy link
Contributor

@Stepa4man Stepa4man commented Feb 12, 2019

Provided support MySQL views

Description (*)

DB backup didn't differentiate tables and views

Fixed Issues

  1. magento-engcom/msi#1988 Database Rollback not working M2.3.0

Manual testing scenarios (*)

  1. create any view in magento db
  2. bin/magento setup:backup --db
  3. bin/magento setup:rollback --db-file=db_backup_file.sql -n

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

@magento-engcom-team
Copy link
Contributor

Hi @Stepa4man. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento-engcom-team give me test instance - deploy test instance based on PR changes
  • @magento-engcom-team give me 2.3-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Assistant documentation

@osrecio osrecio self-assigned this Feb 12, 2019
* @param Helper|null $helper
*/
public function __construct(
\Magento\Backup\Model\ResourceModel\Db $resourceDb,
\Magento\Framework\App\ResourceConnection $resource,
GetListTables $getListTables = null,
Copy link
Member

@osrecio osrecio Feb 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be added to end of the construct Backward Compatibility (Adding a constructor parameter)

return $this->resource->getConnection('backup')->fetchCol(
"SHOW FULL TABLES WHERE `Table_type` = ?",
self::TABLE_TYPE
self::TABLE_TYPE
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate constant... Delete one please

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like github's suggested change doesn't work properly...

Copy link
Member

@osrecio osrecio Feb 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is a BETA feature. Maybe sometimes doesn't work properly. Sorry

private function getShowCreateView($viewName)
{
$quotedViewName = $this->getConnection()->quoteIdentifier($viewName);
$query = 'SHOW CREATE VIEW ' . $quotedViewName;
Copy link
Contributor

@maghamed maghamed Feb 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

creating View we have to use this syntax

                SQL SECURITY INVOKER

the same we do in MSI - https://github.com/magento-engcom/msi/blob/2.3-develop/app/code/Magento/InventoryCatalog/Setup/Patch/Schema/CreateLegacyStockStatusView.php#L69

https://dev.mysql.com/doc/refman/5.6/en/stored-programs-security.html

For a stored routine or view, use SQL SECURITY INVOKER in the object definition when possible so that it can be used only by users with permissions appropriate for the operations performed by the object.

In opposite case, MySQL user working with Magento would not be possible to invoke the View after creation.
This is especially affect our Cloud deployment

Copy link
Contributor Author

@Stepa4man Stepa4man Feb 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maghamed

  1. If this VIEW was created with SQL SECURITY INVOKER declaration - SHOW CREATE VIEW will show SQL statement with this declaration also.
    image

  2. If no - then with SQL SECURITY DEFINER (in this example inventory_stock_2 is also VIEW and was created without SQL SECURITY INVOKER declaration)
    image

So it's ok with the current implementation

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, we already use SQL SECURITY INVOKER at the time of View creation on MSI, so that backup with just pick this setting and at the time of DB restore we keep that setting

*/
class GetListTables
{
const TABLE_TYPE = 'BASE TABLE';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use private constants to prevent polluting public contract with excessive obligations

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

*/
class GetListViews
{
const TABLE_TYPE = 'VIEW';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use private constant instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Copy link
Contributor

@maghamed maghamed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Stepa4man could you please apply requested changes asap.

We really want to include this PR into Magento 2.3.1 which is being prepared and assembled literally now

@magento-cicd2
Copy link
Contributor

magento-cicd2 commented Feb 27, 2019

CLA assistant check
All committers have signed the CLA.

@Stepa4man Stepa4man added the partners-contribution Pull Request is created by Magento Partner label Mar 1, 2019
@magento-engcom-team magento-engcom-team merged commit b11652b into magento:2.3-develop Mar 2, 2019
@ghost
Copy link

ghost commented Mar 2, 2019

Hi @Stepa4man, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants