Skip to content
Browse files

v2.3.2 Added support for extracting DOMAINs

  • Loading branch information...
1 parent 4132114 commit d8a75f8e79a39b63c84d0eaf84d34e4a0e823fc2 @keithf4 keithf4 committed Sep 18, 2015
Showing with 11 additions and 8 deletions.
  1. +4 −0 CHANGELOG.txt
  2. +7 −8 pg_extractor.py
View
4 CHANGELOG.txt
@@ -1,3 +1,7 @@
+2.3.2
+* Added extraction of DOMAIN objects. These are considered a type and included with --gettypes (and --getall) and included in the types folder.
+
+
2.3.1
* Fixed --orreplace not working in combination with --schemadir option (Github #34).
* Fixed --getall or --getroles failing when either --dbname or PGDATABASE environment variable were not set.
View
15 pg_extractor.py
@@ -22,7 +22,7 @@ class PGExtractor:
"""
def __init__(self):
- self.version = "2.3.1"
+ self.version = "2.3.2"
self.args = False
self.temp_filelist = []
self.error_list = []
@@ -57,7 +57,7 @@ def build_main_object_list(self, restore_file="#default#"):
# Last object in this list cannot have a space in it.
# If an object type is missing, please let me know and I'll add it.
p_types = "ACL|AGGREGATE|COMMENT|CONSTRAINT|DATABASE|DEFAULT\sACL|DEFAULT|"
- p_types += "EXTENSION|FK\sCONSTRAINT|FOREIGN\sTABLE|FUNCTION|"
+ p_types += "DOMAIN|EXTENSION|FK\sCONSTRAINT|FOREIGN\sTABLE|FUNCTION|"
p_types += "INDEX|RULE|SCHEMA|SEQUENCE\sOWNED\sBY|SEQUENCE\sSET|SEQUENCE|"
p_types += "TABLE\sDATA|TABLE|TRIGGER|TYPE|VIEW|MATERIALIZED\sVIEW\sDATA|MATERIALIZED\sVIEW"
p_main_object_type = re.compile(p_objid + r'\s(?P<type>' + p_types + ')')
@@ -540,7 +540,7 @@ def create_extract_files(self, object_list, target_dir="#default#"):
process_list = []
process_count = 0
tmp_restore_list = None
- other_object_list = self.build_type_object_list(object_list, ["RULE", "SCHEMA", "TRIGGER", "TYPE", "EXTENSION"])
+ other_object_list = self.build_type_object_list(object_list, ["RULE", "SCHEMA", "TRIGGER", "TYPE", "EXTENSION", "DOMAIN"])
if len(other_object_list) > 0:
if self.args and not self.args.quiet:
print("Extracting remaining objects...")
@@ -573,7 +573,7 @@ def create_extract_files(self, object_list, target_dir="#default#"):
objname_filename = re.sub(r'\W', self.replace_char_with_hex, o.get('objname'))
output_file = os.path.join(output_file, objschema_filename + "." + objname_filename + ".sql")
- if o.get('objtype') == "TYPE":
+ if o.get('objtype') == "TYPE" or o.get('objtype') == "DOMAIN":
output_file = self.create_dir(os.path.join(output_file, 'types'))
# replace any non-alphanumeric characters with ",hexcode,"
objschema_filename = re.sub(r'\W', self.replace_char_with_hex, o.get('objschema'))
@@ -605,7 +605,7 @@ def create_extract_files(self, object_list, target_dir="#default#"):
restore_line += " " + a.get('objname') + " " + a.get('objowner') + "\n"
fh.write(restore_line)
for c in comment_list:
- if re.search(r'(RULE|SCHEMA|TRIGGER|TYPE|EXTENSION)', c.get('objsubtype')):
+ if re.search(r'(RULE|SCHEMA|TRIGGER|TYPE|EXTENSION|DOMAIN)', c.get('objsubtype')):
if o.get('objschema') == c.get('objschema') and o.get('objname') == c.get('objname'):
restore_line = c.get('objid') + " " + c.get('objtype') + " " + c.get('objschema')
if c.get('objsubtype') == 'EXTENSION':
@@ -694,7 +694,6 @@ def extract_roles(self, output_dir="#default#"):
Returns the full path to the output_file that was created.
"""
pg_dumpall_cmd = ["pg_dumpall", "--roles-only"]
- #TODO REMOVE
if (self._check_bin_version("pg_dumpall", "9.0") == True) and (self.args.dbname != None):
pg_dumpall_cmd.append("--database=" + self.args.dbname)
if output_dir == "#default#":
@@ -1072,7 +1071,7 @@ def _filter_object_list(self, main_object_list):
if (o.get('objtype') == 'SCHEMA'):
if(self.args.getschemata == False):
continue
- if (o.get('objtype') == 'TYPE'):
+ if (o.get('objtype') == 'TYPE|DOMAIN'):
if (self.args.gettypes == False):
continue
if (o.get('objtype') == 'RULE'):
@@ -1125,7 +1124,7 @@ def _parse_arguments(self):
args_filter.add_argument('--gettables', action="store_true", help="Export table ddl (includes foreign tables). Each file includes table's indexes, constraints, sequences, comments, rules, triggers. Included in --getall.")
args_filter.add_argument('--getviews', action="store_true", help="Export view ddl (includes materialized views). Each file includes all rules & triggers. Included in --getall.")
args_filter.add_argument('--getfuncs', action="store_true", help="Export function and/or aggregate ddl. Overloaded functions will all be in the same base filename. Custom aggregates are put in a separate folder than regular functions. Included in --getall.")
- args_filter.add_argument('--gettypes', action="store_true", help="Export custom types. Included in --getall.")
+ args_filter.add_argument('--gettypes', action="store_true", help="Export custom types and domains. Included in --getall.")
args_filter.add_argument('--getextensions', action="store_true", help="Export extensions. Included in --getall. Note this only places a 'CREATE EXTENSION...' line in the file along with any associated COMMENTs. Extension source code is never dumped out with pg_dump. See PostgreSQL docs on extensions for more info.")
args_filter.add_argument('--getroles', action="store_true", help="Export all roles in the cluster to a single file. A different folder for this file can be specified by --rolesdir if it needs to be kept out of version control. Included in --getall.")
args_filter.add_argument('--getdefaultprivs', action="store_true", help="Export all the default privilges for roles if they have been set. See the ALTER DEFAULT PRIVILEGES statement for how these are set. Theese are extracted to the same 'roles' folder that --getroles uses. Included in --getall.")

0 comments on commit d8a75f8

Please sign in to comment.
Something went wrong with that request. Please try again.