什么是版本控制 SQLite 数据库(仅模式)的好方法(或工具)?

What#39;s a good way (or tool) to version control a SQLite database (schema only)?(什么是版本控制 SQLite 数据库(仅模式)的好方法(或工具)?)

本文介绍了什么是版本控制 SQLite 数据库(仅模式)的好方法(或工具)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以提出一个好的方法(或工具)来控制 SQLite 数据库(仅模式)吗?我正在尝试对 SQLite 数据库进行版本控制,我能找到的唯一选择是使用 GIT 对整个文件进行版本控制,但我现在对数据不感兴趣,只是架构发生了变化.

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.

有什么建议吗?

谢谢:-)

推荐答案

我有两个答案.如果您的 sqlite 足够轻巧且不经常更新,则可以将其添加到存储库中而不会产生太多影响/问题.

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.

这里是如何让 git 很好地显示差异:

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

现在,当您的 sqlite db 文件发生更改时,您可以通过 git diff 看到更改.

Now when your sqlite db file changes you can see the change with git diff.

如果您只想查看模式的差异,只需将 .dump 更改为 .schema,它应该只执行创建调用并跳过插入.

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.

如果您希望您的 db 文件以 sql 而不是 db 的形式推送到存储库中,您可以使用 git 中的 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

我还没有尝试过,但基本上每当你遇到一个 db 文件时,git 都会使用 sqlite3 $1 .schema 出口.然后,当您从数据库中签出该文件时,它会使用 cat $1 | 转换回数据库.sqlite3.

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二进制文件的正确方法混帐?

.gitattributes

mysqlite3.db merge=keepTheir

希望对您有所帮助.

这篇关于什么是版本控制 SQLite 数据库(仅模式)的好方法(或工具)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:什么是版本控制 SQLite 数据库(仅模式)的好方法(或工具)?

基础教程推荐