Package for applying migrations to the postgresql database
Project description
Package for applying migrations to the postgresql database
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
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pgrate-0.1.1-py3-none-any.whl.
File metadata
- Download URL: pgrate-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
953ecf005723fe05c7c457a6daea5accd18c982938278f21128ddb2174acc9f0
|
|
| MD5 |
ff23b97874e695b4fab674b6c5c4b3e9
|
|
| BLAKE2b-256 |
1e1c7cb81a0e80cb6995578420c1612fe4f74289ca9d5638bb991460ee24b284
|