Permalink
Browse files

More conversion to a ContextManager schema_editor

  • Loading branch information...
1 parent ce5bd42 commit 331546f6ee7f50a92c01f919e1bb4bea6ed32625 @andrewgodwin andrewgodwin committed May 18, 2013
Showing with 215 additions and 312 deletions.
  1. +7 −26 django/db/backends/schema.py
  2. +6 −0 django/db/migrations/state.py
  3. +202 −286 tests/schema/tests.py
@@ -61,38 +61,19 @@ def __init__(self, connection):
# State-managing methods
- def start(self):
- """
- Marks the start of a schema-altering run.
- """
- self.deferred_sql = []
- atomic(self.connection.alias).__enter__()
-
- def commit(self):
- """
- Finishes a schema-altering run.
- """
- for sql in self.deferred_sql:
- self.execute(sql)
- atomic(self.connection.alias).__exit__(None, None, None)
-
- def rollback(self):
- """
- Tries to roll back a schema-altering run. Call instead of commit().
- """
- if not self.connection.features.can_rollback_ddl:
- raise RuntimeError("Cannot rollback schema changes on this backend")
- atomic(self.connection.alias).__exit__(*sys.exc_info())
-
def __enter__(self):
- self.start()
+ self.deferred_sql = []
+ atomic(self.connection.alias, self.connection.features.can_rollback_ddl).__enter__()
return self
def __exit__(self, exc_type, exc_value, traceback):
if exc_type is None:
- self.commit()
+ for sql in self.deferred_sql:
+ self.execute(sql)
+ atomic(self.connection.alias, self.connection.features.can_rollback_ddl).__exit__(None, None, None)
else:
- self.rollback()
+ # Continue propagating exception
+ return None
# Core utility functions
@@ -30,6 +30,12 @@ def render(self):
model.render(self.app_cache)
return self.app_cache
+ @classmethod
+ def from_app_cache(cls, app_cache):
+ "Takes in an AppCache and returns a ProjectState matching it"
+ for model in app_cache.get_models():
+ print model
+
class ModelState(object):
"""
Oops, something went wrong.

0 comments on commit 331546f

Please sign in to comment.