Caribou是一个简单的SQLite数据库迁移库,构建于
项目描述
Caribou SQLite迁移
Caribou是一个小型、简单的SQLite数据库迁移库,主要用于Python,主要构建用于管理应用程序多个版本中客户端数据库的演变。
示例
以下是一个简单示例,说明如何使用Caribou来管理您的SQLite模式
创建迁移
使用Caribou的命令行工具创建您的第一个迁移
$ caribou create my_first_migration
created migration ./20091115140758_my_first_migration.py
编辑您的迁移
让我们在升级步骤中创建一个包含数据的表,并在降级步骤中撤销更改。
"""
An example of a Caribou migration file.
"""
def upgrade(connection):
# connection is a plain old sqlite3 database connection
sql = """
create table animals
( name TEXT
, status TEXT
) """
connection.execute(sql)
animals = [ ('caribou', 'least concerned')
, ('bengal tiger', 'threatened')
, ('eastern elk', 'extinct')
]
sql = 'insert into animals values (:1, :2)'
for name, status in animals:
connection.execute(sql, [name, status])
connection.commit()
def downgrade(connection):
connection.execute('drop table animals')
Caribou迁移是灵活的,因为它们是纯Python文件。您可以随意添加日志、DDL事务等。
运行您的迁移
可以使用命令行工具运行Caribou迁移
$ caribou upgrade db.sqlite .
upgrading db [db.sqlite] to most recent version
upgraded [db.sqlite] successfully to version [20091115140758]
# if you want to revert your changes, uses the downgrade command:
$ caribou downgrade db.sqlite . 0
downgrading db [db.sqlite] to version [0]
downgraded [db.sqlite] successfully to version [0]
由于Caribou是为了管理客户端SQLite数据库而构建的,因此它也可以在您的应用程序中程序化地运行
"""
An example illustrating how to run a migration programmatically.
"""
import caribou
db = 'db.sqlite'
migrations_dir = '/path/to/migrations/dir'
version = '20091115140758'
# upgrade to most recent version
caribou.upgrade(db, migrations_dir)
# upgrade to a specific version
caribou.upgrade(db, migrations_dir, version)
# downgrade to a specific version
caribou.downgrade(db, migrations_dir, version)
就这样,您开始滚动。
安装
pip install caribou
许可证
Caribou is in the public domain.
开发
在开始修改Caribou之前,您需要了解的一些事情
单元测试
单元测试套件使用pytest和tox。要安装和运行
pip install tox pytest
tox
附录
还不够吗?
项目详情
下载文件
下载适用于您的平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。
源代码分发
caribou-0.4.1.tar.gz (14.0 kB 查看哈希值)
构建分发
caribou-0.4.1-py2.py3-none-any.whl (7.2 kB 查看哈希值)
关闭
caribou-0.4.1.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 13a66fc9ef9b1c9e9ef220876d59a44ee5eff9e579655252271b7514fc0ad787 |
|
MD5 | cffb9f2bc3d5ba7094e0878090ddc7df |
|
BLAKE2b-256 | 6c74de2c20c5a24811d69a2a6150d5cd841f2af21ffc65ff964a73f46738bb68 |
关闭
caribou-0.4.1-py2.py3-none-any.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 5c7a036584b34021011f1512620152272924e55ca87c7c805073aeef31c5baed |
|
MD5 | 472da6314bf4c4c4b9570e66ebeaf3ba |
|
BLAKE2b-256 | b591795eccdad6abd41b3634502d0971cb696d2e5c9cede67f8b38ebe30d2b1e |