Caribou is a simple SQLite database migrations library, built
Project description
Caribou SQLite Migrations
Caribou is a small, simple SQLite database migrations library for Python, built primarily to manage the evoluton of client side databases over multiple releases of an application.
Example
Here is a simple example illustrating how to use Caribou to manage your SQLite schema:
Create a Migration
Use Caribou's command line tool to create your first migration:
$ caribou create my_first_migration
created migration ./20091115140758_my_first_migration.py
Edit Your Migration
Let's create a table with some data in the upgrade step and reverse the changes in the downgrade step.
"""
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 migrations are flexible because they are plain Python files. Feel free to add logging, DDL transactions, anything at all.
Run Your Migration:
Caribou migrations can be run with the command line tool:
$ caribou upgrade my_sqlite_db .
upgrading db [my_sqlite_db] to most recent version
upgraded [my_sqlite_db] successfully to version [20091115140758]
# if you want to revert your changes, uses the downgrade command:
$ caribou downgrade my_sqlite_db . 0
downgrading db [my_sqlite_db] to version [0]
downgraded [my_sqlite_db] successfully to version [0]
Since Caribou is built to manage client side SQLite databases, it can also be run programmatically from within your application:
"""
An example illustrating how to run a migration programmatically.
"""
import caribou
db_path = 'my_sqlite_db'
migrations_path = '/path/to/migrations/dir'
version = '20091115140758'
# upgrade to most recent version
caribou.upgrade(db_path, migrations_path)
# upgrade to a specific version
caribou.upgrade(db_path, migrations_path, version)
# downgrade to a specific version
caribou.downgrade(db_path, migrations_path, version)
That's it. You're rolling.
Installation
pip install caribou
Licence
Caribou is in the public domain.
Development
Things to know, before you start hacking Caribou:
Unit Tests
The unit test suite uses pytest and tox. To install and run:
pip install tox pytest
tox
Appendix
Haven't got enough?
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file caribou-0.4.0.tar.gz
.
File metadata
- Download URL: caribou-0.4.0.tar.gz
- Upload date:
- Size: 13.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c824285c1582d600c36058aef22ccda0cdbdd44e7e93a74429a3b1ec7382413 |
|
MD5 | 446fb71df6a1f19a780f35dbc3ff72db |
|
BLAKE2b-256 | a0b8657ea5fb94a93c6fc14ab8cb1e8b036b1ef5ee5c722a852edfd759cd1ecd |
File details
Details for the file caribou-0.4.0-py2.py3-none-any.whl
.
File metadata
- Download URL: caribou-0.4.0-py2.py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 934f1ea8c3340d6fab408f569774dbffdd2deac89109292a6389bd7cbc0f003e |
|
MD5 | a43ff85bc8605951615ffd936ffabad5 |
|
BLAKE2b-256 | 08cf0b3a0740ce4ee330c69836ff0ab5fae9574b429de221d25cbdafc88fc527 |