Question

I have copied the database and launched the website. Now that I add a feature (for example a new property in a Model which leads to a column being created in a certain table), I copy the files to the server and the website gets updated. However, how should I approach the updates of sql server. I know I can generate scripts by using -Script in Update-Database command, but, what if I forget to do that. Can I somehow review scripts of older migrations so I can run them in my server?

Was it helpful?

Solution

If you are using Entity Framework Migrations you can simply use the Database Initializer MigrateDatabaseToLatestVersion. On your development machine you perform all your work with the migrations, testing, etc, and when you are happy with the result, send the working Migrations to the server with your updated code base, then restart the server. The context does the rest.

If you are deploying your application you may want it to automatically upgrade the database (by applying any pending migrations) when the application launches. You can do this by registering the MigrateDatabaseToLatestVersion database initializer. A database initializer simply contains some logic that is used to make sure the database is setup correctly. This logic is run the first time the context is used within the application process (AppDomain).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top