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

Conditionally running scripts in a folder

Open benfoster opened this issue 2 years ago • 3 comments

Hi, thanks for your work on this project.

I wondered if it would be possible to conditionally run the scripts in a folder based on an environment variable? For example, I only to load the DB with test data when running db-up locally.

benfoster avatar Jun 08 '23 14:06 benfoster

Hi,

I'm not fully understand your case. You can use environment variables in config file or scripts. For example, you can use environment variable for connection string:

dbup:
  # other options
  connectionString: $CONNSTR$
SET CONNSTR=your connection string
./dbup upgrade

Could this solve your case?

drwatson1 avatar Jun 12 '23 12:06 drwatson1

Hi, Perhaps I didn't explain well. I have a collection of seed data scripts. I would like to run these after my schema changes, but only in a specific environment. Does that make sense?

benfoster avatar Jun 21 '23 16:06 benfoster

Environment variables can be used almost anywhere in config file, including script folder names.

You may have two or more folders with your seed data scripts, one for each environment. Specify one of them using an environment variable: https://github.com/drwatson1/dbup-cli/wiki#script-selection.

Something like:

  scripts:
# other lines are omitted

    -   folder: $SEED_DATA$           # <<<<< Add this line

Now you can select an appropriate folder just specifying SEED_DATA environment variable.

May be this will work for you?

drwatson1 avatar Jul 08 '23 15:07 drwatson1