Give a more useful error if a table already exists and so we can't create it during...
authorChristopher Allan Webber <cwebber@dustycloud.org>
Mon, 4 Mar 2013 16:57:21 +0000 (10:57 -0600)
committerChristopher Allan Webber <cwebber@dustycloud.org>
Mon, 4 Mar 2013 16:57:21 +0000 (10:57 -0600)
This commit sponsored by Andrzej Prochyra.  Thanks!

mediagoblin/db/migration_tools.py

index e5380a3b9c3795731c9a8b3f0c4151ae8bab8841..c0c7e9981e717329262bcbcbd79682fce79150e4 100644 (file)
@@ -17,6 +17,9 @@
 from mediagoblin.tools.common import simple_printer
 from sqlalchemy import Table
 
+class TableAlreadyExists(Exception):
+    pass
+
 
 class MigrationManager(object):
     """
@@ -128,7 +131,10 @@ class MigrationManager(object):
         # sanity check before we proceed, none of these should be created
         for model in self.models:
             # Maybe in the future just print out a "Yikes!" or something?
-            assert not model.__table__.exists(self.session.bind)
+            if model.__table__.exists(self.session.bind):
+                raise TableAlreadyExists(
+                    u"Intended to create table '%s' but it already exists" %
+                    model.__table__.name)
 
         self.migration_model.metadata.create_all(
             self.session.bind,