-
Notifications
You must be signed in to change notification settings - Fork 541
Closed
Labels
enhancementNew feature or requestNew feature or request
Milestone
Description
The only way to include an IScript instance I was able to find is by using the extension method WithScriptsAndCodeEmbeddedInAssembly. I needed a little more control and did not want to include the CodeEmbedded part, so I made my own provider. Perhaps this can be included in DbUp in some way?
internal class ScriptInstanceProvider : IScriptProvider
{
private readonly IScript _script;
/// <summary>
/// Provider used to directly include an IScript instance during migrations
/// </summary>
/// <param name="script">The IScript instance to include</param>
public ScriptInstanceProvider(IScript script)
{
_script = script ?? throw new ArgumentNullException(nameof(script));
}
public IEnumerable<SqlScript> GetScripts(IConnectionManager connectionManager)
{
return connectionManager.ExecuteCommandsWithManagedConnection(dbCommandFactory =>
new SqlScript[] {
new LazySqlScript(_script.GetType().FullName + ".cs", () => _script.ProvideScript(dbCommandFactory))
}
);
}
}It's really easy to use:
DeployChanges.To.SqlDatabase(connectionString)
.WithScripts(new ScriptInstanceProvider(new MyScript()))
.Build()
.PerformUpgrade();Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request