DbUp variable substitution seemingly not working

69 Views Asked by At

I have configured the following upgrader:

var upgrader =
DbUp.DeployChanges.To
    .SqlDatabase(new MicrosoftDataSqlClientConnectionManager(connection))
    .WithScriptsEmbeddedInAssembly(ThisAssembly, filter: scriptName => performRegex(scriptName).Success)
    .WithVariablesEnabled()
    .WithVariables(new System.Collections.Generic.Dictionary<string, string>
    {
        {"UsersMetaDataConstraintName", usersMetaDataConstraintName ?? string.Empty}
    })
    .LogToConsole()
    .Build();

With an SQL script such as:

IF (LEN('$UsersMetaDataConstraintName$') > 0)
BEGIN
  ALTER TABLE UsersMetadata DROP CONSTRAINT $UsersMetaDataConstraintName$
  GO
END

ALTER TABLE UsersMetadata ALTER COLUMN UserId NCHAR(6) NOT NULL;
GO

ALTER TABLE UsersMetadata ADD CONSTRAINT PK_UserId PRIMARY KEY (UserId)
GO

I can see from the upgrader results that the variable substitution doesn't even take place, it just appears to have the $UsersMetaDataConstraintName$ in it.

0

There are 0 best solutions below