Skip to content
This repository has been archived by the owner on Jan 2, 2020. It is now read-only.

Database dump is not deleted after test is finish #227

Open
killua99 opened this issue Dec 19, 2018 · 5 comments
Open

Database dump is not deleted after test is finish #227

killua99 opened this issue Dec 19, 2018 · 5 comments
Assignees
Milestone

Comments

@killua99
Copy link

I'm finding myself delete dump databases after each test run, I thought it would be deleted after each test or having a flag to confirm I want to delete a dump.

The case is, now it generate a dump file each test I run, sometimes you have to run several tests to achieve a feature and more when it has several scenarios.

Would be a good idea, to think about this two options.

One define a database to be the restore point, so we have an option like:

database:
  restore_after_test: true
  backup_path: /path/to/the/dump.sql

That if you give a SQL file will be use for all restores points. But if we have this setting.

database:
  restore_after_test: true
  backup_path: /path/to/store/tmp/database

Is a folder where the test will dump the database and after the test is finish, it will clear the database.

The difference are on, the first one when we give the database file it wont delete it, the second one when is a path that will assume is a tmp dump and it will be deleted after that.

Sorry if this issue is wrong target or so I was seeking for help but it could also be a feature request?

Thanks for this extension btw!

@paulgibbs
Copy link
Owner

paulgibbs commented Dec 20, 2018

Hi @killua99
Thanks for trying WordHat, and sharing your feedback. I appreciate it!

From the documentation for this setting:

If restore_after_test is true, and the (backup_path) value is a file path, WordHat will use that as the back up to restore the database from.
If the path is a directory, then before any tests are run, WordHat will generate a database back up and store it here.
If the path has not been set, WordHat will choose its own temporary folder.

So your first suggestion (giving it a SQL dump) should already work. I would recommend this approach for any significant use of WordHat that makes changes to the WordPress site's database, because exporting the database is slow.
You'll want to tag any Feature or Scenario that makes a database with the @db annotation, otherwise the DB restore won't be triggered.

If I remember correctly, if WordHat exports the database itself, it does not delete the .sql after the run. We could make a change to have it delete it, what do you think?

I am not keen on clearing the database at the end - what I think you're getting at here is making sure it restores to its initial state (i.e. before WordHat) run, which the current implementation should be doing.

@killua99
Copy link
Author

Hi @paulgibbs thanks for answering,

Correct idk if I complicated or over wrote what my main point was.

The main point of this is, the dump from temporary database is not been deleted.

Could be good to have an extra option that by default could be something like:

database:
  restore_after_test: true
  backup_path: /path/to/store/tmp/database
  delete_tmp_db: true

The name of it, could be talk later, just throwing ideas.

So is a default value to true, that always delete the tmp_db, how should we know is a tmp db? we don't pass a my-dump-file-33333.sql file, we check we don't pass a sql file, if is just a path, then we will clear the dump after all the test are done.

This could improve maintaining local development clean, I found myself like with 10 dumps on my tmp folder 😊 each dump was close to 80 MB.

The feature of giving a direct dump is awesome, great, but sometimes we need it to be fresh dump, and we don't want to generate a fresh dump each day or so.

So TL:DR Let's build the feature to delete the tmp dump after all test are done. 👍🏽

@paulgibbs
Copy link
Owner

👍

@paulgibbs paulgibbs added this to the 3.1 milestone Dec 20, 2018
@paulgibbs paulgibbs modified the milestones: 3.1, Next Release Dec 28, 2018
@paulgibbs
Copy link
Owner

I've been trying to figure out a good way to build this. It's easy-ish to do with the AfterSuite hook and the WP-PHP driver, but harder with WP-CLI (in case of somehow deleting a remote file -- wp eval is probably the solution, but I don't know how it fits into the design of the DatabaseContext, it seems a bit of a kludge).

@killua99
Copy link
Author

I'll try to give some thought to this too. I didn't leave :)

@paulgibbs paulgibbs self-assigned this Aug 20, 2019
paulgibbs added a commit that referenced this issue Oct 20, 2019
If WordHat is configured to generate a DB dump during its run, WordHat was
leaving alot of files littering up PHP's temporary folder. Sorry!

See #227
paulgibbs added a commit that referenced this issue Oct 20, 2019
If WordHat is configured to generate a DB dump during its run, WordHat was
leaving alot of files littering up PHP's temporary folder. Sorry!

See #227
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants