A simple database migration system for SQLite, based on sqlite-utils
Project description
sqlite-migrate
A simple database migration system for SQLite, based on sqlite-utils
This project is an early alpha. Expect breaking changes.
Installation
This tool works as a plugin for sqlite-utils. First install that:
pip install sqlite-utils
Then install this plugin like so:
sqlite-utils install sqlite-migrate
Usage
This tool works against migration files. A migration file looks like this:
from sqlite_migrate import Migrations
# Pick a unique name here - it must not clash with other migration sets that
# the user might run against the same database.
migration = Migrations("myapp")
# Use this decorator against functions that implement migrations
@migration()
def m001_create_table(db):
# db is a sqlite-utils Database instance
db["creatures"].create(
{"id": int, "name": str, "species": str},
pk="id"
)
@migration()
def m002_add_weight(db):
# db is a sqlite-utils Database instance
db["creatures"].add_column("weight", float)
Running this command will execute those migrations in sequence against the specified database file:
sqlite-utils migrate creatures.db
Running it multiple times will have no additional affect, unless you add more migration functions to the file.
Here is documentation on the Database instance passed to each migration function.
Project details
Release history Release notifications | RSS feed
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
Hashes for sqlite_migrate-0.1a0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a79cd1472a806a5edf15b10d32477c25e55e8d123e5ee13d741fb88cb8b528a4 |
|
MD5 | 6115f143f03d86327527824b8c460546 |
|
BLAKE2b-256 | 33b12c8991da271d0dcb05ceafb079ab90540c5b4d39c070328f64e0893a0f09 |