Skip to content

generate SQL changeset from differing postgres schemas

License

Notifications You must be signed in to change notification settings

thugdoubt/pypgdiff

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pyPGdiff

Tools for generating on-the-fly migrations between PostgreSQL schemas.

Usage

import psycopg2
from pypgdiff.objects import Database, Schema

conn = psycopg2.connect(database=x, user=y, password=z)

# the source of truth
source_schema = Schema(database=Database(conn=conn, name="source_schema")
# the target to change
target_schema = Schema(database=Database(conn=conn, name="target_schema")

# changeset will be sorted
changes = source_schema | target_schema
for change in changes:
    sql = change.sql

Configuration

Diffs can be configured with the Config context manager:

from pypgdiff import Config
with Config(prompt_for_defaults=True):
  changes = source_schema | target_schema

The following config options are available:

  • no_alter_sequences ~ Do not include ALTER SEQUENCE changes. This is primarily useful to suppress sequence restarts, which are probably not useful. Default: False

  • normalize_constraints ~ When comparing constraints, use an automagically generated name to avoid generating unnecessary constraint queries. Default: False

  • prompt_for_defaults ~ When altering a column to be not NULL, prompt the user for a defailt value to use. Default: False

About

generate SQL changeset from differing postgres schemas

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages