Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Verify database changes (version-control)

I have read lots of posts about the importance of database version control. However, I could not find a simple solution how to check if database is in state that it should be.

For example, I have a databases with a table called "Version" (version number is being stored there). But database can be accessed and edited by developers without changing version number. If for example developer updates stored procedure and does not update Version database state is not in sync with version value.

How to track those changes? I do not need to track what is changed but only need to check if database tables, views, procedures, etc. are in sync with database version that is saved in Version table.

Why I need this? When doing deployment I need to check that database is "correct". Also, not all tables or other database objects should be tracked. Is it possible to check without using triggers? Is it possible to be done without 3rd party tools? Do databases have checksums?

Lets say that we use SQL Server 2005.

Edited:

I think I should provide a bit more information about our current environment - we have a "baseline" with all scripts needed to create base version (includes data objects and "metadata" for our app). However, there are many installations of this "base" version with some additional database objects (additional tables, views, procedures, etc.). When we make some change in "base" version we also have to update some installations (not all) - at that time we have to check that "base" is in correct state.

Thanks

like image 300
Sazug Avatar asked Oct 07 '09 22:10

Sazug


People also ask

What is database version control?

Database version control is the practice of tracking every change made to the database by every team member. Like application version control, database version control acts as a single source of truth. It empowers you with complete visibility, traceability, and continuous monitoring of the changes in your database.

Can Git track database changes?

As you modify and redistribute your database, it is important to keep track of changes using a version control system (or VCS). One of the most popular open source VCSs is Git, which allows the programmers to easily track changes over time, preventing costly mistakes.


1 Answers

You seem to be breaking the first and second rule of "Three rules for database work". Using one database per developer and a single authoritative source for your schema would already help a lot. Then, I'm not sure that you have a Baseline for your database and, even more important, that you are using change scripts. Finally, you might find some other answers in Views, Stored Procedures and the Like and in Branching and Merging.

Actually, all these links are mentioned in this great article from Jeff Atwood: Get Your Database Under Version Control. A must read IMHO.

like image 115
Pascal Thivent Avatar answered Sep 19 '22 07:09

Pascal Thivent