Skip to main content

PostgreSQL schema versioning tool

Project description

travis-ci.org status

PostgreSQL Schema Versioning Tool

pgv is an open source utility that makes available to support PostgreSQL schemas in a VCS repository.

Overview

pgv helps you if it is needed to:

  • store SQL files in VCS repository;

  • track changes of your database schemas;

  • make possible to apply changes to various databases

    • even if you have just local access to it.

Installation

You can install pgv using pip:

pip install pgv

Usage

So, for example, you want to store database schemas in the git repository repo.git in folder db. First of all, you need to initialize repository:

~:    user$ git clone repo.git
~:    user$ cd repo
repo: user$ pgv init -p db

This command creates simple pgv config pgv.yaml in working directory and folder db:

db/
  schemas/
  scripts/

According to the convention schemas subfolder should contains folders named after desired schemas in database. Files inside these directories should be the SQL scripts, that describes corresponding schema. E.g. you want to create table foo and function bar in schema public:

schemas/
  public/
    tables/
      foo.sql
    functions/
      bar.sql

Scripts subfolder should contains some staff scripts: data fixes, migrations and so on. SQL files in this folder can contains prefix that defines the position on execution flow. E.g. you need to add script that grants access to all objects in the database. It should be executed after all other.

scripts/
  grants_post.sql

Ok, you want to apply committed changes to database. Let’s initialize it:

repo: user$ pgv initdb -d test

Than push changes to database test:

repo: user$ pgv push -c -d test

E.g. you’ve made some checks on test database and you’ve understood that function bar is not needed. Let’s skip it:

repo: user$ pgv show
c2d658898d4a1369c20285464bd5bb95713173f6
  schemas/public/tables/foo.sql
  schemas/public/functions/bar.sql
  scripts/grants_post.sql
repo: user$ pgv skip -f schemas/public/functions/bar.sql c2d658898d4a1369c20285464bd5bb95713173f6
repo: user$ git add db/.skiplist
repo: user$ git commit
repo: user$ pgv show
cdfdbfb2bdcf8ee2dbf190bbf3a73ffbd77bd9b3 [s]
  .skiplist

c2d658898d4a1369c20285464bd5bb95713173f6
  schemas/public/tables/foo.sql
  scripts/grants_post.sql

After fix you want to push changes to production, but database allows only local connections. Let’s make package with changes:

repo: user$ pgv collect -o changes-to-prod.tar.gz
repo: user$ scp changes-to-prod.tar.gz prod://tmp
repo: user$ ssh prod
~:    user@prod$ pgv push -i /tmp/changes-to-prod.tar.gz -d prod

Tests

To run test use:

tox

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

pgv-0.0.2.tar.gz (13.5 kB view details)

Uploaded Source

File details

Details for the file pgv-0.0.2.tar.gz.

File metadata

  • Download URL: pgv-0.0.2.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pgv-0.0.2.tar.gz
Algorithm Hash digest
SHA256 fc94e4e31c75aa96dd99485ab200b462d2b3141079c8366ee7d5b579838e9304
MD5 9f5b9815c304052b7825a86415edb8f0
BLAKE2b-256 34478faa9c51b029b6ff8410672cf60a0ff9bf26b1d0cf453556586818c0d83c

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