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

Add config option database_dump_file_use_connection_name #1785

Merged
merged 3 commits into from
May 2, 2024

Conversation

jbraband
Copy link
Contributor

@jbraband jbraband commented Apr 29, 2024

Code and tests are added. Documentation update was omitted because a similar config database_dump_file_timestamp_format is not documented. I'm happy to add documentation should that be required for a merge.

This PR adds a config option at config('backup.backup.database_dump_file_use_connection_name') of type boolean, defaulting to null and thus uses the database name as it always has.

This config, if set to true, uses the connection's key from config('database.connections') in the dump file name instead of the database name

Use Case
I have 2 connections defined to the same database, each with different db-dumper options. I have one to dump only the schema (see my PR to spatie/db-dumper#208) and a second to dump the data of the database, minus the data from large tables (large as in disk space) that I can recreate.

As the package stand now, it names the dump files for these 2 connections the same based on the database name and I only get one file in the zipped archive.

With this PR, I now have both files in the zipped archive, one for each connection.

I'm happy to make any recommended modifications or additions!

Edited for grammar and clarity

…the dump fiel with connection name in place of database name
@jbraband jbraband marked this pull request as ready for review April 29, 2024 22:59
/*
* If specified, the database dumped file name will contain the connection name in place of the database name.
*/
'database_dump_file_use_connection_name' => null,
Copy link
Contributor

Choose a reason for hiding this comment

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

since this is a bool value, shoud it be false by default instead of null?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I agree, false would be a better default

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree. Had a thought though to change the config to a string, either 'database' or 'connection' and default it to connection.

I updated to that. It feels better that the 'database' option is visible in the config as default instead of a boolean to change behavior.

I'm happy to change it back to a boolean if that is preferred.

@freekmurze
Copy link
Member

Thanks for this!

Could you also add docs?

@jbraband
Copy link
Contributor Author

jbraband commented May 2, 2024

Thanks for this!

Could you also add docs?

Docs added. I also added docs for database_dump_file_timestamp_format which were missing.

@freekmurze freekmurze merged commit 5a3d7a8 into spatie:main May 2, 2024
6 checks passed
@freekmurze
Copy link
Member

Thanks!

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.

None yet

3 participants