Skip to main content

A simple database migration system for SQLite, based on sqlite-utils

Project description

sqlite-migrate

PyPI Changelog Tests License

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sqlite-migrate-0.1a0.tar.gz (8.0 kB view hashes)

Uploaded Source

Built Distribution

sqlite_migrate-0.1a0-py3-none-any.whl (8.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page