aspnet / WebHooks

[Archived] Libraries to create and consume web hooks on ASP.NET Core. Project moved to https://github.com/aspnet/AspLabs
Apache License 2.0
627 stars 439 forks source link

Deployment - How to MigrateDatabaseToLatestVersion? #54

Closed vindberg closed 8 years ago

vindberg commented 8 years ago

Hi, im trying to deploy this in production and having several code-first dbcontexts/migration configurations in my solution im not able to get the Webhooks.Custom.SqlStorage to initiate its migration. Tried adding this to my TestProject.Database Web.config:

  <entityFramework>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
    <context type="Microsoft.AspNet.WebHooks.WebHookStoreContext, Microsoft.AspNet.WebHooks.Custom.SqlStorage">
              <databaseInitializer type="System.Data.Entity.MigrateDatabaseToLatestVersion`2[[Microsoft.AspNet.WebHooks.WebHookStoreContext, Microsoft.AspNet.WebHooks.Custom.SqlStorage], [TestProject.Database.Migrations.Webhooks.Configuration, TestProject.Database]], EntityFramework, PublicKeyToken=b77a5c561934e089">
                  <parameters>
                      <parameter value="MS_SqlStoreConnectionString" />
                  </parameters>
              </databaseInitializer>
          </context>
      </contexts>
  </entityFramework>

Im not receiving any errors and it doesn't help to put Database.SetInitializer in the Startup class. Any ideas are most welcome :)

Thanks.

HenrikFrystykNielsen commented 8 years ago

Can you initialize the DB separately (maybe in a project with only the one context) and not from your prod deployment?

vindberg commented 8 years ago

Hi Henrik, I have read on stackoverflow that it might be required to separate multiple migration configurations into individual projects (dlls) for it to work. I will try with the webhook sqlstorage - if that is what you mean?

Thanks.

HenrikFrystykNielsen commented 8 years ago

yes, exactly!

vindberg commented 8 years ago

Its working now. I did not have to move it into its own project, but added this in startup: new Microsoft.AspNet.WebHooks.WebHookStoreContext().Database.Initialize(false); And this in web.config:

  <entityFramework>
      <contexts>
          <context type="Microsoft.AspNet.WebHooks.WebHookStoreContext, Microsoft.AspNet.WebHooks.Custom.SqlStorage">
              <databaseInitializer type="System.Data.Entity.MigrateDatabaseToLatestVersion`2[[Microsoft.AspNet.WebHooks.WebHookStoreContext, Microsoft.AspNet.WebHooks.Custom.SqlStorage], [TestProject.Web.Migrations.WebhookConfiguration.Configuration, TestProject.Web]], EntityFramework, PublicKeyToken=b77a5c561934e089">
                  <parameters>
                      <parameter value="Identity_DatabasePublish" />
                  </parameters>
              </databaseInitializer>
          </context>
      </contexts>
  </entityFramework>

Have a good day.