PgDiff: check schema existance.
authorRadek Brich <radek.brich@devl.cz>
Fri, 25 Jan 2013 18:04:17 +0100
changeset 61 703bba757605
parent 60 bb6b20106ff5
child 62 af637235ca81
PgDiff: check schema existance.
pgtoolkit/pgdiff.py
schemadiff.py
--- a/pgtoolkit/pgdiff.py	Fri Jan 25 17:44:49 2013 +0100
+++ b/pgtoolkit/pgdiff.py	Fri Jan 25 18:04:17 2013 +0100
@@ -28,6 +28,10 @@
 from pgtoolkit.highlight import *
 
 
+class PgDiffError(Exception):
+    pass
+
+
 class DiffBase:
     COLORS = {
         '+' : BOLD | GREEN,
@@ -476,7 +480,13 @@
 
         Order: include, exclude
         include=[] means include everything
+
+        Raises:
+            PgDiffError: when schema from include list is not found in src db
+
         '''
+        for schema in include:
+            self._check_schema_exist(schema)
         self.include_schemas.clear()
         self.include_schemas.update(include)
         self.exclude_schemas.clear()
@@ -489,3 +499,8 @@
         self.exclude_tables.clear()
         self.exclude_tables.update(exclude)
 
+
+    def _check_schema_exist(self, schema):
+        if not schema in self.src.schemas:
+            raise PgDiffError('Schema "%s" not found in source database.' % schema)
+
--- a/schemadiff.py	Fri Jan 25 17:44:49 2013 +0100
+++ b/schemadiff.py	Fri Jan 25 18:04:17 2013 +0100
@@ -25,16 +25,19 @@
 
         pgd = pgdiff.PgDiff(srcbrowser, dstbrowser)
 
-        if self.args.schema:
-            pgd.filter_schemas(include=self.args.schema)
+        try:
+            if self.args.schema:
+                pgd.filter_schemas(include=self.args.schema)
+
+            if self.args.table:
+                pgd.filter_tables(include=self.args.table)
 
-        if self.args.table:
-            pgd.filter_tables(include=self.args.table)
-
-        if self.args.sql:
-            pgd.print_patch()
-        else:
-            pgd.print_diff()
+            if self.args.sql:
+                pgd.print_patch()
+            else:
+                pgd.print_diff()
+        except pgdiff.PgDiffError as e:
+            print('PgDiff error:', str(e))
 
 
 tool = SchemaDiffTool()