dbup-cli icon indicating copy to clipboard operation
dbup-cli copied to clipboard

Add ConnectionString argument to the CLI when using the Upgrade command

Open KenKingson opened this issue 2 years ago • 1 comments

Hey,

Is adding a command line argument directly to the Upgrade call possible in parallel with using a yml file? (the parameter from the CLI should have a higher priority)

I would like to update several identical (by schema) databases in parallel through PowerShell, but the absence of the ConnectionString parameter in the Upgrade call does not allow me to do this. Could you help me with that?

KenKingson avatar May 15 '23 10:05 KenKingson

Hi,

You can use an environment variable as a connection string, for example:

dbUp:
# other options
  connectionString: $connstr$

Now you have two options - 1) use .env files or 2) set the variable for each process with PowerShell

  1. Use .env files

Create a file for each of your DB, for example:

dbA.env:

connstr=DB A Connection string should be placed here

dbB.env:

connstr=DB B Connection string should be placed here

Then use command argument -e to pass them when running dbup (see upgrade):

Start-Process -FilePath "dbup.exe" -ArgumentList "upgrade", "-e","dbA.env"
Start-Process -FilePath "dbup.exe" -ArgumentList "upgrade", "-e","dbB.env"

See also Using .env files.

This should work for you but you need to have one .env file per DB.

  1. Another way is to specify environment variables directly.

In this case you use exactly two PS1 files for any number of DBs.

Create the first file (run_dbup.ps1) like this:

$env:connstr=$args[0]
dbup upgrade

Then from another file you should call run_dbup.ps1 something like that:

$PSScriptRoot/myScript1.ps1 "DB A connstr"
$PSScriptRoot/myScript1.ps1 "DB B connstr"
$PSScriptRoot/myScript1.ps1 "DB C connstr"

I didn't run these scripts so they can have errors, but I believe you are grasp the idea.

drwatson1 avatar May 27 '23 19:05 drwatson1