开发者

Does any database support revision control on its command line interface?

开发者 https://www.devze.com 2023-02-16 15:31 出处:网络
Does any database support revision control on its command line interface? So for instance, I\'m at the mysql> command prompt. I\'m going to add a column to a table. I type

Does any database support revision control on its command line interface?

So for instance, I'm at the mysql> command prompt. I'm going to add a column to a table. I type ALTER TABLE X ADD COLUMN Y bigint; and then the database prompts me: "OK. Check these changes in using git?" I respond yes, and it prints out the revision number for the schema.

(No need for a mysqldump to get the schema, removing the data, and checkin at the bash command line.)

At another time, I decide to check in all of my data as well. So I type something like CHECKIN SNAPSHOT TABLE X

Seems like a common sense approach to me, but has anyone modified a database to support such behavior?

开发者_运维百科

Thanks


Well, for one thing, checking in one table makes no sense; its a relational database for a reason; you can't just roll back one table to a previous state and expect that to be OK.

Instead, you can roll back the entire database to a previous state. The database world calls this "point in time recovery"; and you can do it in MySQL with a combination of a full backup and replication logs.

I have no idea why you'd want to store your backups in git.


What you're looking I believe are "migrations". These are usually done at the code level rather than at the database level. Rails supports migrations, Django does with South, I'm sure there's others out there as well.

These migrations are just code files (either in the programming language of choice, or sql scripts) that can be checked in.

The usual case is Schema migrations that don't migrate data but some (most?) allow you to write custom code to do so if you wish.

Generally speaking you wouldn't want to version control data, but there are exceptions when some of the data is part of the logic, but you generally want to separate the type of data that you consider part of the functionality and the parts that you don't.

If you want to store everything, that's just called backing up. Those generally don't do into version control just because of the size. Either it's in a binary format that doesn't diff well, or it's many times larger than it needs to be in a text format. If you need to diff the data, there are tools for that as well.

0

精彩评论

暂无评论...
验证码 换一张
取 消