问题描述
任何人都可以建议一个好的方法(或工具)版本控制SQLite数据库(仅模式)?我试图版本控制一个SQLite数据库和唯一的选项,我可以找到涉及使用GIT版本控制整个文件,但我不感兴趣的数据在这一点,只是架构的变化。
有任何建议吗?
感谢: - )
我有一个两折的答案。如果你的sqlite足够轻,不经常更新,你可以将它添加到存储库没有太多的影响/问题。
但可读性下降diffs,因为它存储为一个二进制。
sqlite3 git diff
这里是如何获取git来显示差异: p>
git config diff.sqlite3.textconv'sqlite3 $ 1 .dump'
echo'*。 db diff = sqlite3'>>现在,当你的sqlite数据库文件(git rev-parse --show-toplevel)/。gitattributes
$ b git diff 查看更改。
如果您只想看到模式的diff,你只需将 .dump
更改为 .schema
,它只应该执行创建调用并跳过插入。
sqlite3使用clean / smudge转换进出库
如果您希望将db文件推入repository as sql而不是db,你可以在git中使用clean / smudge机制。
我还没试过,但基本上每当你遇到一个文件,它是一个db,git使用 sqlite3 $ 1 .schema
导出提交文件的剥离版本(作为sql命令)。然后,当您从数据库中检出该文件时,将使用 cat $ 1 |将其转换回db。 sqlite3
。
sqlite3始终保留最新的文件
.gitattributes
mysqlite3.db merge = keepTheir
希望有帮助。
Can anyone suggest a good way (or tool) to version control a SQLite database (schema only)? I'm trying to version control a SQLite database and the only option I can find involves using GIT to version control the whole file, but I'm not interested in the data at this point, just the schema changes.
Any suggestions?
Thanks :-)
I have a two fold answer. If your sqlite is light enough and infrequently updated, you can add it into the repository without too many repercussions/issues.
But readablity goes down for diffs since it is stored as a binary.
sqlite3 git diff
Here is how to get git to show you diffs nicely:
https://gist.github.com/peteristhegreat/a028bc3b588baaea09ff67f405af2909
git config diff.sqlite3.textconv 'sqlite3 $1 .dump'
echo '*.db diff=sqlite3' >> $(git rev-parse --show-toplevel)/.gitattributes
Now when your sqlite db file changes you can see the change with git diff
.
If you wanted to only see the diff of the schema, you just change .dump
to .schema
and it should only do the create calls and skip the inserts.
sqlite3 conversion in and out of the repository with clean/smudge
If you want your db file to get pushed into the repository as sql instead of as a db, you can use the clean/smudge mechanisms in git.
https://git-scm.com/book/en/v2/Customizing-Git-Git-Attributes#Keyword-Expansion
https://github.com/gilesbowkett/git-smudge-and-clean
I haven't tried it yet, but basically whenever you run across a file that is a db, git commits the stripped down version of the file (as sql commands) using the sqlite3 $1 .schema
export. And then when you checkout that file from your database, it gets converted back to a db using cat $1 | sqlite3
.
sqlite3 always keep the newest file
Right way of tracking a sqlite3 binary file in git?
.gitattributes
mysqlite3.db merge=keepTheir
Hope that helps.
这篇关于什么是版本控制SQLite数据库(仅模式)的好方法(或工具)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!