Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to version control data stored in mysql

I'm trying to use a simple mysql database but tweak it so that every field is backed up up to an indefinite number of versions. The best way I can illustrate this is by replacing each and every field of every table with a stack of all the values this field has ever had (each of these values should be timestamped). I guess it's kind of like having customized version control for all my data..

Any ideas on how to do this?

like image 674
Shawn Avatar asked May 01 '10 22:05

Shawn


People also ask

Can you version control a database?

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.

How do I find the version of MySQL database?

In MySQL Command Line Client, enter the following command: SHOW VARIABLES LIKE 'version'; The MySQL version will be shown instantly.

How do you use SQL version control in database?

Open SQL Server Management Studio and connect to a SQL Server instance. Right-click on your database in the Object Explorer pane and select "Connect to Version Control". This will open the "Connect Database to Version Control" dialog. Copy the https repository path from GitHub and paste it into VersionSQL.


1 Answers

The usual method for "tracking any changes" to a table is to add insert/update/delete trigger procedures on the table and have those records saved in a history table.

For example, if your main data table is "ItemInfo" then you would also have an ItemInfo_History table that got a copy of the new record every time anything changed (via the triggers).

This keeps the performance of your primary table consistent, yet gives you access to the history of any changes if you need it.

Here are some examples, they are for SQL Server but they demonstrate the logic:

My Repository table My Repository History table My Repository Insert trigger procedure My Repository Update trigger procedure

like image 70
Ron Savage Avatar answered Sep 27 '22 21:09

Ron Savage