Code-based scripts and Variables

33 views
Skip to first unread message

Jorge Marques

unread,
Nov 5, 2018, 5:53:08 AM11/5/18
to DbUp Discuss
Good Morning,
how can I access variables within a Code-based scripts?

I want to pass a set of parameters to the "script" in C #, and I do not know how to do it ..

Can anyone help?

thank you

Adam K

unread,
Nov 6, 2018, 9:53:05 AM11/6/18
to DbUp Discuss
Use .WithVariables to push the variables in.
Use if blocks (e.g. IF '$TargetEnvironment$' = 'LOCAL') to branch behavior in the scripts.
We try not to use these too often because you can end up with mismatches in behavior in different environments.

Jorge Marques

unread,
Nov 6, 2018, 10:55:48 AM11/6/18
to DbUp Discuss
My problem is not in using variables in SQL statements, but in C #


   public class CreateTenantBusinessLayer : IScript
    {
        
        public string ProvideScript(Func<IDbCommand> commandFactory)
        {
            if  ('$TargetEnvironment$' == 'LOCAL')
            {

Adam K

unread,
Nov 7, 2018, 9:37:06 AM11/7/18
to DbUp Discuss
You might need to describe what you're trying to do.  In our console app that runs DbUp, we use appsettings, but you could also use command line params.  It really depends on what you're trying to accomplish.
Reply all
Reply to author
Forward
0 new messages