Automatically create database


#1

How can I have the Hangfire database created automatically? I know it will create the schema & tables, but I’d like the database itself to be created if it doesn’t exist. This removes a manual step as part of deployments.


#2

If you are using Entity Framework you can use Database.Migrate() in your DbContext.


#3

Thanks for the response @Mercury.

Is the Hangfire DbContext exposed? What namespace is it in? Or are you suggesting creating a “dummy” DbContext specifically to be able to call Migrate?


#4

@alelefant Did you ever figure this problem out? If so, what was your solution?


#5

@Matt_Alexander Nope. It doesn’t seem like there’s a configurable way of doing this without rolling something yourself. We ended up creating the database manually.


#6

Thanks @alelefant that’s what I ended up doing to.