Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automated generation of database change scripts

I'm looking for a way to automated the generation of change scripts for our databases.

Currently we use Visual Studio 2008 database edition, which has the Schema Compare option, but I don't see a way to automated those actions.

What I'd like to do is create an old and a new database during my daily builds and have schema compare generate a change script for the differences between those two. (Differences in schema and procedures, lookup tables can be dropped and recreated without problems)

Does anyone know of a solution for, or am I going to write miles of scripts to get this going?

Using any paid products besides the Microsoft tooling is not an option here...

Update based on feedback:

  • I have various databases of various sizes, but all changes will happen in a controlled manner while being aware of data already present.
  • Only "easy" changes should be taken care of automagically, i'm thinking addition of columns and tables (very common). Columns may never be removed (so the tool/script may protest if this happens)
like image 508
thijs Avatar asked Feb 12 '10 16:02

thijs


People also ask

Can you automate SQL scripts?

SQL queries are very powerful by themselves, but by automating queries as part of your data flow, you will unlock tons of potential in your data. In this use case, we will explore using the SQL Runner App to automate, insert and update queries.

How do I automate a script in SQL Server?

Using the Generate and Publish Scripts Wizard. In Object Explorer, expand the node for the instance containing the database to be scripted. Point to Tasks, and then select Generate Scripts.

What is SQL change automation?

SQL Change Automation generates numerically ordered SQL migration scripts that sit inside your Visual Studio project and take your schema from one version to the next. You can add these migration scripts to version control, use them to build and release, and automate database deployments, all in one process.


2 Answers

Similar to what @Anton Gogolev is doing, we are using a tool that allows you to write migrations in XML files. The tool we use is called Liquibase and it supports many different DBMS flavors. Not only do we use it internally on our developer schemas, we also use it externally during the upgrade installation that the customer runs.

like image 151
shoover Avatar answered Sep 21 '22 20:09

shoover


Hope I can still help:

You should be able to do this with any good database comparison tool that supports command line interface. In that case you would have to create a simple bat script and add it to task scheduler.

I know ApexSQL Diff supports this functionality and I’m pretty sure SQL Compare from Red Gate has the same option in pro version.

like image 42
Chaz Gardyner Avatar answered Sep 20 '22 20:09

Chaz Gardyner