Skip to content

Instantly share code, notes, and snippets.

View lorentzlasson's full-sized avatar

Lorentz Lasson lorentzlasson

View GitHub Profile
@lorentzlasson
lorentzlasson / pg_schema_split.py
Last active March 26, 2020 09:11
Split schema-only PostgreSQL dumps for source control
#! /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)