rumburak
rumburak

Reputation: 1137

How to automate deployment of entity model changes to database?

Currently I use Visual Studio Database Project, so I can deploy changes to database with one click and keep data in database.

Now I want to be able to create model in Entity Framework and deploy with one click.

So I got sql script to create database from Entity Framework. I can run this script to create database, but I want to keep my data in database.

Is there any way to do that ? Any tool that will do that ? Should I generate it on my own with T4 ?

I use CI so I need to be able to deploy often. I want something similar to Visual Studio Database Project deployment, but with Entity Framework generated database.

Upvotes: 2

Views: 3141

Answers (2)

rumburak
rumburak

Reputation: 1137

To be able to generate Visual Studio Database Project from Entity Framework Model You need to install Entity Designer Database Generation Power Pack.

You need to add Database Project to Your solution and then create edmx model with the same name. Then right click on edmx workspace and select Generate Database from Model and from generation menu Sync Database Project.

You can then deploy this Sql project from Visual Studio to Sql Server.

Upvotes: 0

Mark O'Connor
Mark O'Connor

Reputation: 77971

Liquibase is a database change management tool. It's implemented in Java but a command-line version is available to control your database upgrades (.NET version is under development).

If you need some modelling tool support then Power architect can be used with liquibase.

The problems associated with managing database schema upgrades are subtle. For some background reading I would recommend:

Update

Create a file called liquibase.properties to hold the database details:

url=jdbc:sqlserver://localhost:1433;databaseName=test
username=myuser
password=mypass
driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
classpath=C:\\Program Files\\Microsoft SQL Server 2005 JDBC Driver\\sqljdbc_1.2\\enu\\sqljdbc.jar
changeLogFile=database-changelog.xml

When using liquibase against an existing database you can run the following commands:

liquibase generateChangeLog
liquibase changelogSync

The first command will create an XML file called database-changelog.xml containing the extracted data model.
The second command is optional, but useful if you want to apply new changes to the current database. It marks the extracted changesets as already executed in the database.

Now that you have a starting point, you can proceed to add new changesets to the database-changelog.xml file. To apply these new changes just run the following command:

liquibase update

This is the same command that you use for brand new databases. During an update operation liquibase will compare the changesets in the XML file to the changesets already applied to the target database.

For more advanced usecases I suggest reading the liquibase documentation and the following answer may also help:

Upvotes: 2

Related Questions