cli
cli copied to clipboard
[Feature Request] Ability for --delete-existing-rows and --skip-schema-files flags when using restore-dump
Currently, when making use of the restore-dump
sub-command there is not an easy way for the *-schema.sql
files to be skipped entirely, which would be separate from the recent --overwrite-tables
flag that was recently added in, which primarily allows for existing tables to be dropped and then created again, which does not work if the branch is a production one.
A database dump generated by pscale database dump ...
will generally include several files ending in -schema.sql
so making use of the proposed new --skip-schema-files
flag would simply add in a file filter excluding those files from being processed when making use of restore-dump
.
To test a similar effect, you can simply manually remove any files ending in -schema.sql
from your database dump folder and this would allow only the files containing the rows to insert to be processed.
Separately, the proposed --delete-existing-rows
flag would go hand in hand with this option since it would help automate the loop for users where a DELETE
query must be repeated with a LIMIT
clause until the table is empty that we have as an alternative to using TRUNCATE
when working with production branches. Additionally, this flag could possibly be made aware of whether a branch is a development or production one and use TRUNCATE
or the DELETE
loop with LIMIT
clause depending on what's more appropriate.
Both of the requests above used together would help enable users to use restore-dump
against a production branch and make it easier to restore a database dump from a primary production branch into a secondary staging / development branch that happens to also be a production one.
Example usage:
pscale database restore-dump <DATABASE_NAME> <BRANCH_NAME> --dir="/path/to/database/dump" --delete-existing-rows --skip-schema-files --org=<ORGANIZATION_NAME>
There is some risk with exposing flags like the ones proposed here for users, but used appropriately and with care, it should provide useful functionality simplifying the work users may have to go through in order to restore data from a database dump into a production branch if they were available.