0

I am using MT v3.0.17 with Automatonymous, I noticed that the table of instance state isn't created if the database already exists. Since I'm directing multiple different automatonymous state machines to the same database, I would like to instruct it to create tables even if database exists.

How can this be done?

Thanks

2 Answers2

0

If you are using Entity Framework, you use migrations to create/update the database and associated tables, as documented by Microsoft:

https://msdn.microsoft.com/en-us/data/dn579398.aspx

If you are using NHibernate, you can use the Schema validation methods, which will verify and update the schema as needed. This is done in the unit tests, as shown:

https://github.com/MassTransit/MassTransit/blob/develop/src/MassTransit.AutomatonymousIntegration.Tests/SqlLiteSessionFactoryProvider.cs#L104

Chris Patterson
  • 28,659
  • 3
  • 47
  • 59
0

Inspired from the unit tests of masstransit itself, we use EF migrations, and explicitly as EF to apply said migrations during start-up

 public static void Main()
    {
        var saga = new MySaga();

        var contextFactory = new SagaWithDependencyContextFactory();

        using (var context = contextFactory.CreateDbContext(Array.Empty<string>()))
        {
            context.Database.Migrate();
        }

        Func<DbContext> sagaDbContextFactory = () => contextFactory.CreateDbContext(Array.Empty<string>());

        var efSagaRepository =
            new EntityFrameworkSagaRepository<MySagaInstanceState>(sagaDbContextFactory);  

        // .. create bus etc..
Carlo V. Dango
  • 13,322
  • 16
  • 71
  • 114