Skip to main content

Package for applying migrations to the postgresql database

Project description

Package for applying migrations to the postgresql database

Lint

Not for production purposes.

Tool to migrate database from files.

Install

$ pip install pgrate

Usage

pgrate -p directorie/to/migrations -d postgres://username:password@localhost:5432/database

OR

pgrate -p directorie/to/migrations -d postgresql://username:password@localhost:5432/database

NOTE Migration name must starts with a number + "_", where number is migration version and ends with *.up.sql example (001_migration_name.up.slq)

Examples

  • Move into working directory and create default migrations folder
$ cd /path/to/project
$ mkdir migrations
  • Creating a migration up and down
-- migrations/001_init.up.sql
CREATE TABLE IF NOT EXISTS users(
  id serial PRIMARY KEY, 
  name VARCHAR(255)
);
-- migrations/001_init.down.sql
DROP TABLE IF EXISTS users;
  • Applying migrations
$ pgrate -p ./migrations -d postgres://username:password@localhost:5432/database
  • Results

Migration schema

current_version is_dirt
1 false
  • Creating a migration up and down with error
-- migrations/002_users.up.sql
CREATE TABLE users(
  id serial PRIMARY KEY, 
  name VARCHAR(255)
);
-- migrations/002_users.down.sql
DROP TABLE IF EXISTS users;
  • Applying migrations
$ pgrate -p ./migrations -d postgres://username:password@localhost:5432/database
  • Results

Console log

asyncpg.exceptions.DuplicateTableError: relation "users" already exists

Migration schema

current_version is_dirt
2 true

Commands

Command Description
'-p'
'--path'
Path to migrations folder
'-d'
'--db-uri'
Database connection URI

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

pgrate-0.1.1-py3-none-any.whl (6.7 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