Skip to main content

Write migrations in SQL

Project description

SQL-migrate

SQL is a fantastic language — one of the most successful programming languages in the world.

We can use SQL to manage the schema of our database and migrate data. We believe this is better than trying to replace SQL with a bespoke DSL for migrations.

Managing the database schema of an app in development, however, can be challenging. We need some assistance to manage the complexity:

  • Generate migration files for upward and reverse migrations.
  • Track migration dependencies: ensure that migrations are run in the correct order.
  • Merge migrations from multiple branches: Ensure that schema changes in two or more different branches do not conflict and are resolved satisfactorily.

Behold SQL-migrate:

  • Create migrations
    • automatic migration names based on either timestamp (default, like Diesel) or sequence number (option, like Django).
    • optional descriptive label added to the migration filenames
    • configurable to use a single folder (like Django) or subfolders (like Diesel)
    • three files per migration:
      • NAME.up.sql (or NAME/up.sql) – the SQL script to do the upward migration
      • NAME.dn.sql (or NAME/dn.sql) – the SQL script to do the downward migration
      • NAME.conf.yaml (or NAME/conf.yaml) – configuration for the migration. For now, this includes:
        • the "name" of the migration
        • any "description" that the author has chosen to include
        • a list of the migration's "base" dependencies (so that an DAG of migrations can be modeled to ensure that migrations are applied correctly.)
        • a list of "up" SQL scripts in this migration (default *up.sql)
        • a list of "dn" SQL scripts in this migration (default *dn.sql)
    • support for COPY from an external file for easily loading / updating data.
    • support from COPY from the results of a query to ease bulk data migration.
  • Apply migrations:
    • Creates a migrations table to track which migrations were applied and when.
    • Ensures that migrations are applied in dependency-order (which is not necessarily the same as filesystem order).
    • Disallows migrating a database if there are unmerged branches – ensure that branch conflicts have been resolved in a merge before continuing.
    • Each migration is run within its own transaction, treating it as a unified changeset. It's all or nothing with a given migration.
  • Merge migrations:
    • When creating a new migration where there are unmerged branches, creates a new migration that has the tip of each branch as a dependency, and prompts the user to review the migrations to ensure that conflicts are resolved.

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

sql-migrate-0.1.0.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

sql_migrate-0.1.0-py2.py3-none-any.whl (8.0 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file sql-migrate-0.1.0.tar.gz.

File metadata

  • Download URL: sql-migrate-0.1.0.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

File hashes

Hashes for sql-migrate-0.1.0.tar.gz
Algorithm Hash digest
SHA256 93827526c8bd9710fe41f06f8460d00aa2670d6b5b4cd571b949124a991ac9ac
MD5 15cde84ab158163f676ba936d9de1205
BLAKE2b-256 1a939ff383fa03560f04acd96b549ccb3b6aedff179e37373c1306608fe33e9b

See more details on using hashes here.

File details

Details for the file sql_migrate-0.1.0-py2.py3-none-any.whl.

File metadata

  • Download URL: sql_migrate-0.1.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

File hashes

Hashes for sql_migrate-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 6ccd03c2bcd9473bed2cec9c30e1723ab333ff70f5ab9458634d681ad84f8db1
MD5 aff0090cb1190b1ca0f8fade3c71ea10
BLAKE2b-256 f9e85edf393a65b2b14d93a7f02aa2641d3060a21f567ab47e3c16cfc4c4a332

See more details on using hashes here.

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