Create "Update Scripts" for a database project?
As I release versions of software and branch versions for each release, how can I easily generate update/patch scripts for the versions? I can't open the database projects and compare them because they are named the same and visual studio doesn't like that.
The next idea I had was deploying lower version to a database and then generating a change script by opening up the next version of the software. This seems like it would be a bit tedious.
Also, how would one go about integrating this into a setup project instead o开发者_如何学JAVAf a manual process?
Even if you were using the new Entity Framework you still can't get Visual Studio etc to track changes in a database schema automatically for you, you'd have to track the changes between versions manually and apply them (usually when the upgraded app runs for the first time).
I would suggest...
- Adding a version identifier to your database schema in some table.
- Tracking all database schema changes between versions, if you use MySQL for example, then Toad will make a repository (SVN for example) commit every time you make a schema change, which makes logging changes easier.
- When you deploy a new version, tally up all your schema changes and mark them as the change set from version Y to version Z.
- When your app runs for first time (so not with the setup program but with the app itself), lookup the version in the schema, and apply each update script until you reach the version of the app. So if the app runs and discovers schema X, it'll run script Y and then script Z.
This is how most apps run, wordpress, blogengine.net for example; all run in this mannor, when releasing they provide one script to create the schema from scratch, and another to update it from the last released version.
精彩评论