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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file sqlite-migrate-0.1a0.tar.gz.

File metadata

  • Download URL: sqlite-migrate-0.1a0.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for sqlite-migrate-0.1a0.tar.gz
Algorithm Hash digest
SHA256 85f5c889034965aa6b12c2cb736e61b4cf0e9b5f98e09c04e01df9ac53674322
MD5 0ed58bdcf0fe36743e2906e62f1ed463
BLAKE2b-256 1e0a469d068c3c35bcff904024a1f9c696d7dcfe066367d31023a86f6f4a3f01

See more details on using hashes here.

File details

Details for the file sqlite_migrate-0.1a0-py3-none-any.whl.

File metadata

File hashes

Hashes for sqlite_migrate-0.1a0-py3-none-any.whl
Algorithm Hash digest
SHA256 a79cd1472a806a5edf15b10d32477c25e55e8d123e5ee13d741fb88cb8b528a4
MD5 6115f143f03d86327527824b8c460546
BLAKE2b-256 33b12c8991da271d0dcb05ceafb079ab90540c5b4d39c070328f64e0893a0f09

See more details on using hashes here.

Supported by

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