Skip to content

Instantly share code, notes, and snippets.

View deaquino's full-sized avatar

Jaime de Aquino deaquino

  • Choose a company...
View GitHub Profile
@deaquino
deaquino / pg_schema_split.py
Last active December 21, 2017 15:51
Split schema-only PostgreSQL dumps for source control. Updated to Python 3
#! /usr/bin/python
import os, re, sys
# Split pg_dump files to schema/type file hierarchy
# Use with files produced by pg_dump -s
#TODO: Identify dropped objects and delete from tree
# Detect object header lines
re_obj = re.compile(r'-- Name: ([-\w\s\.]+)(?:\([-\w\s\[\],]*\))?; Type: ([-\w\s]+); Schema: ([-\w]+); Owner: ([-\w]*)(?:; Tablespace: )?([-\w]*)\n', flags=re.IGNORECASE)