Skip to main content

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

Metadata

Release files for pgv 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pgv 0.0.2
File Size Uploaded
pgv-0.0.2.tar.gz 13.5 kB Details

Release files / pgv-0.0.2.tar.gz

Download URL pgv-0.0.2.tar.gz
Size 13.5 kB
Tags Source
SHA-256 checksum
How to use checksums
fc94e4e31c75aa96dd99485ab200b462d2b3141079c8366ee7d5b579838e9304
BLAKE2b-256 checksum
How to use checksums
34478faa9c51b029b6ff8410672cf60a0ff9bf26b1d0cf453556586818c0d83c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.0.2 This release

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page