Skip to main content

Pyway is a database versioning and migration tool inspired by Flyway

Project description

Pyway Database Version Control

Overview

Pyway is a database versioning and migration tool inspired by Flyway

Download and Install

To install use pip:

$ pip install pyway

Or clone the repo:

$ git clone https://github.com/jasondcamp/pyway.git
$ python -m build

Configuration

Pyway environment variables and command line options

Priority is env variables -> config file -> command args

Env Variable Command Line Description Default
PYWAY_DATABASE_MIGRATION_DIR --database-migration-dir Folder name to migration files resources
PYWAY_SQL_MIGRATION_PREFIX Prefix for version in migration file V
PYWAY_SQL_MIGRATION_SEPARATOR Separator between version and description to the migration file __
PYWAY_SQL_MIGRATION_SUFFIXES Suffix extension for migration files .sql
PYWAY_TABLE --database-table Name of schema history table public.pyway
PYWAY_TYPE --database-type Data Base Management System [postgres, mysql ] required
PYWAY_DATABASE_HOST --database-host Host to connect to the database localhost
PYWAY_DATABASE_PORT --database-port Port to connect to the database 5432
PYWAY_DATABASE_NAME --database-name Name of database to connect postgres
PYWAY_DATABASE_USERNAME --database-username User to use to connect to the database postgres
PYWAY_DATABASE_PASSWORD --database-password Password to use to connect to the database None
PYWAY_CONFIG_FILE -c, --config Configuration file .pyway.conf
--schema-file Used when importing a schema file
--checksum-file Used when updating a checksum - advanced use!

Configuration file

Pyway supports a configuration file with the default file as .pyway.conf. A sample config file is below:

Postgres:

database_type: postgres
database_username: postgres
database_password: 123456
database_host: localhost
database_port: 5432
database_name: postgres
database_migration_dir: schema
database_table: public.pyway

MySQL:

database_type: mysql
database_username: admin
database_password: 123456
database_host: localhost
database_port: 3306
database_name: maindb
database_migration_dir: schema
database_table: pyway

Pyway Files

Files are raw SQL files that are named like the following:

V{major}_{minor}__{description}.sql

Example: V01_01__initial_schema.sql

Note that the description needs to match the word regexp [A-Za-z0-9_]

Usage

Info

Information lets you know where you are. At first glance, you will see which migrations have already been applied, which others are still pending, and whether there is a discrepancy between the checksum of the local file and the database schema table.

$ pyway info

Validate

Validate helps you verify that the migrations applied to the database match the ones available locally. This compares the checksums to validate that what is in the migration on disk is what was committed into the database.

$ pyway validate

Migrate

After validate, it will scan the Database migration dir for available migrations. It will compare them to the migrations that have been applied to the database. If any new migration is found, it will migrate the database to close the gap.

$ pyway migrate

Import

This allows the user to import a schema file into the migration, for example if the base schema has already been applied, then the user can import that file in so they can then apply subsequent migrations. Currently the import looks in the database_migration_dir for the file.

$ pyway import --schema-file V01_01__initial_schema.sql

Checksum

Updates a checksum in the database. This is for advanced use only, as it could put the pyway database out of sync with reality. This is mainly to be used for development, where your pyway file may change because of manual applies or formatting changes. It is meant to get the database in sync with what you believe to be the current state of your system. It should NEVER be used in production, only initial development. If you require schema changes in production, create a new schema and apply that.

$ pyway checksum --checksum-file V01_01__initial_schema.sql

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

pyway-0.3.21.tar.gz (28.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyway-0.3.21-py3-none-any.whl (27.8 kB view details)

Uploaded Python 3

File details

Details for the file pyway-0.3.21.tar.gz.

File metadata

  • Download URL: pyway-0.3.21.tar.gz
  • Upload date:
  • Size: 28.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for pyway-0.3.21.tar.gz
Algorithm Hash digest
SHA256 7742454eeb5b9cb1b97eece5a6a4d45967e67aa73e937ed125b9b8e155d5c78b
MD5 1c0cff578b31106a084cd4305b9e6a0d
BLAKE2b-256 08cad2345dac13e83365b18d8fffc4cc9f469a2d982a3ea911875909959594d7

See more details on using hashes here.

File details

Details for the file pyway-0.3.21-py3-none-any.whl.

File metadata

  • Download URL: pyway-0.3.21-py3-none-any.whl
  • Upload date:
  • Size: 27.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for pyway-0.3.21-py3-none-any.whl
Algorithm Hash digest
SHA256 fa62f7941b1892b5d94239f6b56f5a9cf113fd0ac14a7d288600d176ac09778e
MD5 a9e325731eda2f7dcb5b601250b3d04c
BLAKE2b-256 8e0fe18eebd1e281bf5c3b67b5b2e48ed3ac193cacc28f394ad0abfd072037cc

See more details on using hashes here.

Supported by

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