使用git管理sqlite数据库 [英] Manage sqlite database with git

查看:69
本文介绍了使用git管理sqlite数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小项目,指定sqlite作为数据库选择.

I have this small project that specifies sqlite as the database choice.

对于此特定项目,框架为Django,服务器由Heroku托管.为了使数据库正常工作,每当将项目部署到持续集成工具或开发站点时,都必须使用迁移命令和凭据来设置数据库.

For this particular project, the framework is Django, and the server is hosted by Heroku. In order for the database to work, it must be set up with migration commands and credentials whenever the project is deployed to continuous integration tools or development site.

问题是,其中许多环境实际上并未使用源存储库随附的 my_project.sqlite3 文件,我们使用 git 对其进行版本控制.如何将更改合并到已部署的数据库中?设置数据库的脚本是否适合这种情况?同时,值得注意的是,有些安全凭据不应该以未加密的方式出现在脚本中,这使情况变得棘手.

The question is, that many of these environments do not actually use the my_project.sqlite3 file that comes with the source repository, which we version control with git. How do I incorporate changes to the deployed database? Is a script that set up the database suitable for this scenario? Meanwhile, it is worth notice that there are security credentials that should not appear in a script in unencrypted ways, which makes the situation tricky.

推荐答案

其中许多环境实际上并未使用源存储库随附的my_project.sqlite3文件

that many of these environments do not actually use the my_project.sqlite3 file that comes with the source repository

如果您的部署平台不支持您选择的数据库,那么您的开发环境可能应该转移到使用他们支持的数据库之一.可以在开发和生产中运行不同的数据库,但似乎令人头疼.

If your deployment platform does not support your chosen database, then your development environment should probably be moved to using one of the databases they do support. It is possible to run different databases in development and production, but just seems like the source of headaches.

我发现许多文章指出Heroku在生产中不支持SQLite,而是推荐Postgres.

I have found a number of articles that state that Heroku just doesn't support SQLite in production and instead recommends Postgres.

如何将更改合并到已部署的数据库中?设置数据库的脚本是否适合这种情况?

How do I incorporate changes to the deployed database? Is a script that set up the database suitable for this scenario?

我假设您只是从一个数据库中提取数据以提供给另一个数据库,所以是的,只要每次更新代码时该脚本都是一次批处理操作,就可以了.如果要在生产中添加/操作数据,然后将其导出到git,则可能需要其他功能.

I assume that you are just extracting data from one database to give to another, so yes,as long as that script is a one time batch operation each time the code is updated, then it should be fine. You will want something else if you are adding/manipulating data in production and then exporting it to your git.

同时,值得注意的是,有些安全凭据不应该以未加密的方式出现在脚本中

Meanwhile, it is worth notice that there are security credentials that should not appear in a script in unencrypted ways

环境变量应该可以解决这个问题.您将主机设置为具有凭据的环境变量,然后在脚本中检索它们.您正在寻找类似这样的东西:

An environment variable should solve that. You set your host machine to have environment variables with your credentials and then just retrieve them within the script. You are looking to have something like this:

# Set environment vars
os.environ['USER'] = 'username'
os.environ['PASSWORD'] = 'password'

# Get environment vars
USER = os.getenv('USER')
PASSWORD = os.environ.get('PASSWORD')

这篇关于使用git管理sqlite数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆