Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pyway

Package Overview
Dependencies
Maintainers
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pyway

Pyway is a database versioning and migration tool inspired by Flyway

  • 0.3.32
  • PyPI
  • Socket score

Maintainers
2

Pyway Database Version Control

Overview

Pyway is a database versioning and migration tool inspired by Flyway

Supported Databases

  • MySQLd Commercial (Version 8+)
  • MariaDB (Version 10+)
  • PostgreSQL
  • DuckDB (Version 0.10+)
  • SQLite 3

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 VariableCommand LineDescriptionDefault
PYWAY_DATABASE_MIGRATION_DIR--database-migration-dirFolder name to migration filesresources
PYWAY_SQL_MIGRATION_PREFIXPrefix for version in migration fileV
PYWAY_SQL_MIGRATION_SEPARATORSeparator between version and description to the migration file__
PYWAY_SQL_MIGRATION_SUFFIXESSuffix extension for migration files.sql
PYWAY_TABLE--database-tableName of schema history tableNone
PYWAY_TYPE--database-typeData Base Management System [postgres, mysql, duckdb, sqlite ]None required
PYWAY_DATABASE_HOST--database-hostHost to connect to the databaseNone
PYWAY_DATABASE_PORT--database-portPort to connect to the databaseNone
PYWAY_DATABASE_NAME--database-nameName of database to connectNone
PYWAY_DATABASE_USERNAME--database-usernameUser to use to connect to the databaseNone
PYWAY_DATABASE_PASSWORD--database-passwordPassword to use to connect to the databaseNone
PYWAY_CONFIG_FILE-c, --configConfiguration file.pyway.conf
--schema-fileUsed when importing a schema file
--checksum-fileUsed 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. Major/minor versioning and semantic versioning is supported.

V{major}_{minor}_({patch})__{description}.sql

Example: V01_01__initial_schema.sql

Example: V01_01_01__initial_schema.sql

The description needs to match the word regexp [A-Za-z0-9_]. It also supports 2 digits per version component, so 99.99.99 is the maximum version allowed.

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

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc