Skip to content

Instantly share code, notes, and snippets.

@nathanwoulfe
Created February 4, 2019 09:43
Show Gist options
  • Save nathanwoulfe/2f25761fb1c9f006cdfa71909c257249 to your computer and use it in GitHub Desktop.
Save nathanwoulfe/2f25761fb1c9f006cdfa71909c257249 to your computer and use it in GitHub Desktop.
Bang some tables into a fresh v8 install. Is this the right way to do it? It smells smelly.
// namespaces and usings omitted for brevity
//
public class WorkflowInstallMigration : Upgrader
{
private readonly MigrationPlan _plan;
private readonly IScopeProvider _scopeProvider;
private readonly IMigrationBuilder _migrationBuilder;
private readonly IKeyValueService _keyValueService;
private readonly ILogger _logger;
public WorkflowInstallMigration(IScopeProvider scopeProvider, IMigrationBuilder migrationBuilder, IKeyValueService keyValueService, ILogger logger)
: base(new MigrationPlan(Constants.Name))
{
_scopeProvider = scopeProvider;
_migrationBuilder = migrationBuilder;
_keyValueService = keyValueService;
_logger = logger;
_plan = new MigrationPlan(Constants.Name);
_plan.From(string.Empty)
.To<WorkflowInstall>("workflow-installed");
}
public void Execute()
{
var upgrader = new Upgrader(_plan);
upgrader.Execute(_scopeProvider, _migrationBuilder, _keyValueService, _logger);
}
}
////////////
public class WorkflowInstall : MigrationBase
{
public WorkflowInstall(IMigrationContext context) : base(context)
{ }
public override void Migrate()
{
Logger.Debug<WorkflowInstall>("Creating Workflow tables");
if (!TableExists(Constants.SettingsTable))
{
Create.Table<WorkflowSettingsPoco>().Do();
}
}
}
// finally, over in the component, I do this in the Initialize method:
var installer = new WorkflowInstallMigration(_scopeProvider, _migrationBuilder, _keyValueService, _logger);
installer.Execute();
@nathanwoulfe
Copy link
Author

Pieced this together from bits in the Upgrader internals, an old post from Stephan, and a bit of trial and error. It still feels wrong though - seems like a lot of boilerplate to simply create a table.

It works, but must be able to be done better?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment