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

Separate db tool and db backup/restore services for version 2.x #398

Merged
merged 16 commits into from
Mar 6, 2018

Conversation

alekseytupichenkov
Copy link
Contributor

Provide services for backup/restore different database and refactoring code

@alekseytupichenkov
Copy link
Contributor Author

alekseytupichenkov commented Feb 14, 2018

@alexislefebvre
Also, I have suggestion, maybe need remove liip_functional_test.cache_sqlite_db at all? Currently we have liip_functional_test.cache_db.* to make this

@alexislefebvre
Copy link
Collaborator

There is a conflict since #393 has been merged, sorry.

Thanks for the amazing work, it looks really nice!

I think that we can drop liip_functional_test.cache_sqlite_db if you added a replacement, we don't need to keep a BC parameter on the 2.x branch.


$executor->getReferenceRepository()->save($this->getBackupName());

exec("mysqldump -h $dbHost -u $dbUser -p$dbPass $dbName > {$this->getBackupName()}");
Copy link
Collaborator

Choose a reason for hiding this comment

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

If the MySQL database is in a Docker container, this command won't work?

Copy link

Choose a reason for hiding this comment

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

I use docker too, it will works fine if you install mysql-client in container with symfony app :)

@ghost
Copy link

ghost commented Feb 16, 2018

I'll resolve conflicts in this weekend

alekseytupichenkov added 4 commits February 18, 2018 17:21
@alekseytupichenkov
Copy link
Contributor Author

@alexislefebvre done :)
Also updated pr for 1.9.x

@alexislefebvre
Copy link
Collaborator

Can you please explain why you call mysqldump? I don't understand why you chose to rely on a CLI command, the current version of bundle only rely on PHP code and I prefer this option personnally.

Otherwise, this PR is really good.

@Jean85 @lsmith77 Could you please give your opinion about this PR ? Thanks.

@alekseytupichenkov
Copy link
Contributor Author

I use mysqldump only to create sql dump file, I didn't find this functional in Doctrine. Maybe someone can help with this?
However, MysqlCustomDatabaseBackup.php just an example for how it can work, anyone can create their own service for make backup/restore using their tools

@alexislefebvre
Copy link
Collaborator

README.md Outdated
# app/config/config_test.yml
liip_functional_test:
cache_db:
sqlite: liip_functional_test.database_backup.sqllite
Copy link
Contributor

Choose a reason for hiding this comment

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

sqlite ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it's typo

@@ -31,6 +31,15 @@ public function getConfigTreeBuilder(): TreeBuilder
$rootNode
->children()
->booleanNode('cache_sqlite_db')->defaultFalse()->end()
->arrayNode('cache_db')
Copy link
Contributor

Choose a reason for hiding this comment

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

should we then remove cache_sqlite_db ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I'll remove it.
#398 (comment)

$em = $executor->getReferenceRepository()->getManager();
self::$metadata = $em->getMetadataFactory()->getLoadedMetadata();

exec("mysqldump -h $dbHost -u $dbUser -p$dbPass --no-create-db $dbName > {$this->getBackupName()}");
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@alexislefebvre @lsmith77
About #398 (comment), it's not suit, this method save only reference data, but I need save database data (sql with inserts data per each table)

Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed ..

Generally I think if we have to use a CLI command, then its not really a good fit for this Bundle, since it will not be applicable in too many cases.

This library here might help however https://github.com/portphp/doctrine

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm... I added mysql class just for example
I can use portphp/doctrine or something else, it will be interesting for me, but I have fears about performance and additional vendor...

Currently I rename service mysql_custom -> mysql_example and add attention block from readme

As a proposal, mysql (and other) can be implemented by a separate repo in github, what do you think about it? @alexislefebvre @lsmith77

Copy link
Collaborator

Choose a reason for hiding this comment

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

@alekseytupichenkov

About #398 (comment), it's not suit, this method save only reference data, but I need save database data (sql with inserts data per each table)

The method works on the current version of this bundle. I'm sorry but I don't understand why you don't use it in this PR. Could you please explain why you chose to perform a full export instead of using only the reference data?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@alexislefebvre I save reference too
https://github.com/liip/LiipFunctionalTestBundle/pull/398/files#diff-f2e540017ed6e7479f8d4a4b1e17a480R82

But it's not enough, I need backup both, DB and reference.
In case of SQLite, to copy DB enough copy just file, in case of MySql we can't just copy files, need make backup, for make backup I use mysqldump because Doctrine can't do it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lsmith77 about https://github.com/portphp/doctrine

This lib really cool, but still not suitable, this lib saves only entities, but I need dump full db.
For example, after loading fixtures I can have some additional data, by reason to Doctrine lifecycle methods or DB triggers

I found some PHP libs to make backup like https://github.com/backup-manager/backup-manager or https://github.com/spatie/db-dumper
But they all use mysqldump too

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for your explanation, I was confused by the fact that SQLite and MySQL need different ways to perform backups. I understand now. Thanks.

@lsmith77
Copy link
Contributor

didn't do a detailed code review .. but yes splitting this out is very good and fits our goals from #392

alekseytupichenkov added 5 commits February 20, 2018 09:02
@alexislefebvre
Copy link
Collaborator

alexislefebvre commented Feb 26, 2018

It looks like mysql dumps are causing headaches: https://github.com/liip/LiipFunctionalTestBundle/pull/398/files/831b101c3d9f752c5dfa3eb38799e7d5cf260fb2#r169751346

We may merge this PR without the MySQL backup and add it later in another PR? Do you agree @alekseytupichenkov? If it's OK for you, you can finalize this PR, move the changes to another branch and open another PR.

@alexislefebvre alexislefebvre mentioned this pull request Feb 26, 2018
12 tasks
@ghost
Copy link

ghost commented Feb 27, 2018

@alexislefebvre Yeah, it's ok, I'll make new PR soon

@alexislefebvre alexislefebvre removed the RFC label Mar 2, 2018
alekseytupichenkov added 2 commits March 3, 2018 15:33
rename method getBackupName -> getBackupFilePath
update readme
@alekseytupichenkov
Copy link
Contributor Author

@alexislefebvre done, also made same in #397

Copy link
Collaborator

@alexislefebvre alexislefebvre left a comment

Choose a reason for hiding this comment

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

Thanks for the amazing work!

@alekseytupichenkov
Copy link
Contributor Author

Added separate PRs with database cache services (mysql and mongodb)

@lsmith77
Copy link
Contributor

lsmith77 commented Mar 5, 2018

only did a very quick review but looks great!

one thing to note in general, we probably should create an UPGRADING.md file to document all the BC breaks and how to migrate existing code to the new version.

@lsmith77
Copy link
Contributor

lsmith77 commented Mar 6, 2018

ah .. totally overlooked we already have such a file. thank you for adding .. all good from my side then.

@lsmith77 lsmith77 merged commit 321db83 into liip:2.x Mar 6, 2018
@lsmith77
Copy link
Contributor

lsmith77 commented Mar 6, 2018

really awesome work .. and thank you very much for being so receptive on the feedback you got.

@alexislefebvre
Copy link
Collaborator

Thanks @alekseytupichenkov for the amazing work and @lsmith77 for the review and merge. 🎉

I published a new release with these changes: https://github.com/liip/LiipFunctionalTestBundle/releases/tag/2.0.0-alpha4

@soullivaneuh
Copy link
Contributor

This PR cause troubles on some configurations. Please see #423.

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

Successfully merging this pull request may close these issues.

4 participants