Add db metadata to storage path
As discussed in #56, we'll be adding the Database name in the storage path to logically separate dumps without the need to change storage configuration when pointing Greenmask to different databases.
This will impact the commands below that will need to be adapted:
- Dump
- Restore
- Validate
- Show dump
- List dump
Concerns:
- What if the user have two different database hosts in the cloud with the same database name? (i.e. two RDS instances, one for dev and another one for production, but both have a
greenmaskdatabase)- should the dbhost also be used in the path or will the user need to address that himself by adjusting a path/prefix value?
- What if the config is defined like
dbname: "host=localhost port=50022 user=foobar dbname=foobar"?- should we disallow the dbname config to be declared like that or just parse the value?
- Well we could suggest in the documentation using the
prefixparameter in the storage to isolate them. Or we could add one more level with the hostname provided--original-hostname. But I think it is redundant, a simple recommendation in the doc is enough. What if we are usinglocalhostor UNIX socket in the connection string? I believe the simple doc recommendation is our choice. - The simplest way to do so is to execute a query
select current_database();, store the result, and apply it later
- Gotcha, makes sense!
- How should I that be implemented so it can be used by the commands adapted to solve this issue? Should this query be added to
internal/db/postgres/contextor something like that?
@joao-zanutto
How should I that be implemented so it can be used by the commands adapted to solve this issue? Should this query be added to internal/db/postgres/context or something like that?
Right, all should be done in the RuntimeContext object. Create a new function let's say gatherCurrentDatabase and a new attribute DatabaseName. Assign the gathered database name to the RuntimeContext