mirror of
https://github.com/ansible/awx.git
synced 2026-03-07 19:51:08 -03:30
Add autocommit to migration 36 if it's off.
This commit is contained in:
@@ -4,7 +4,7 @@ import sys
|
|||||||
from south.utils import datetime_utils as datetime
|
from south.utils import datetime_utils as datetime
|
||||||
from south.db import db
|
from south.db import db
|
||||||
from south.v2 import DataMigration
|
from south.v2 import DataMigration
|
||||||
from django.db import models
|
from django.db import models, transaction
|
||||||
from django.utils.encoding import smart_text
|
from django.utils.encoding import smart_text
|
||||||
|
|
||||||
class Migration(DataMigration):
|
class Migration(DataMigration):
|
||||||
@@ -63,6 +63,11 @@ class Migration(DataMigration):
|
|||||||
def forwards(self, orm):
|
def forwards(self, orm):
|
||||||
"Write your forwards methods here."
|
"Write your forwards methods here."
|
||||||
|
|
||||||
|
# South seems to perform migrations with autocommit off in some cases.
|
||||||
|
# That breaks this migration, so ensure it's turned on.
|
||||||
|
old_autocommit = transaction.get_autocommit()
|
||||||
|
transaction.set_autocommit(True)
|
||||||
|
|
||||||
# Copy Project old to new.
|
# Copy Project old to new.
|
||||||
print('Migrating Projects...', end='')
|
print('Migrating Projects...', end='')
|
||||||
new_ctype = self._get_content_type_for_model(orm, orm.Project)
|
new_ctype = self._get_content_type_for_model(orm, orm.Project)
|
||||||
@@ -382,11 +387,14 @@ class Migration(DataMigration):
|
|||||||
a_s.new_job.add(new_job)
|
a_s.new_job.add(new_job)
|
||||||
print('')
|
print('')
|
||||||
|
|
||||||
|
# Restore autocommit to what it was.
|
||||||
|
transaction.set_autocommit(old_autocommit)
|
||||||
|
|
||||||
def backwards(self, orm):
|
def backwards(self, orm):
|
||||||
"Write your backwards methods here."
|
"Write your backwards methods here."
|
||||||
|
|
||||||
# FIXME: Would like to have this, but not required.
|
# FIXME: Would like to have this, but not required.
|
||||||
raise NotImplementedError()
|
raise RuntimeError("This migration is not reversable")
|
||||||
|
|
||||||
models = {
|
models = {
|
||||||
u'auth.group': {
|
u'auth.group': {
|
||||||
|
|||||||
Reference in New Issue
Block a user