Database access in data migrations defaults to the 'default' database. Force it to the user selected database instead.
Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -11,7 +11,7 @@ def move_from_content_type_user_to_foreign_key_field_user(apps, schema_editor):
|
||||
|
||||
DocumentCheckout = apps.get_model('checkouts', 'DocumentCheckout')
|
||||
|
||||
for document_checkout in DocumentCheckout.objects.all():
|
||||
for document_checkout in DocumentCheckout.objects.using(schema_editor.connection.alias).all():
|
||||
document_checkout.user = document_checkout.user_object
|
||||
document_checkout.save()
|
||||
|
||||
|
||||
@@ -21,9 +21,9 @@ def migrate_old_comments(apps, schema_editor):
|
||||
Document = apps.get_model('documents', 'Document')
|
||||
User = apps.get_model(*settings.AUTH_USER_MODEL.split('.'))
|
||||
|
||||
for old_comment in OldComment.objects.all():
|
||||
for old_comment in OldComment.objects.using(schema_editor.connection.alias).all():
|
||||
comment = Comment(
|
||||
document=Document.objects.get(pk=old_comment.object_pk),
|
||||
document=Document.objects.using(schema_editor.connection.alias).get(pk=old_comment.object_pk),
|
||||
user=User(old_comment.user.pk),
|
||||
comment=old_comment.comment,
|
||||
submit_date=old_comment.submit_date,
|
||||
|
||||
@@ -8,7 +8,7 @@ from django.template.defaultfilters import slugify
|
||||
def assign_slugs(apps, schema_editor):
|
||||
Index = apps.get_model('document_indexing', 'Index')
|
||||
|
||||
for index in Index.objects.all():
|
||||
for index in Index.objects.using(schema_editor.connection.alias).all():
|
||||
index.slug = slugify(index.label)
|
||||
index.save()
|
||||
|
||||
|
||||
@@ -10,9 +10,9 @@ def create_parsing_setting_for_existing_document_types(apps, schema_editor):
|
||||
DocumentType = apps.get_model('documents', 'DocumentType')
|
||||
DocumentTypeSettings = apps.get_model('document_parsing', 'DocumentTypeSettings')
|
||||
|
||||
for document_type in DocumentType.objects.all():
|
||||
for document_type in DocumentType.objects.using(schema_editor.connection.alias).all():
|
||||
try:
|
||||
DocumentTypeSettings.objects.create(document_type=document_type)
|
||||
DocumentTypeSettings.objects.using(schema_editor.connection.alias).create(document_type=document_type)
|
||||
except DocumentTypeSettings.DoesNotExist:
|
||||
pass
|
||||
|
||||
@@ -21,9 +21,9 @@ def delete_parsing_setting_for_existing_document_types(apps, schema_editor):
|
||||
DocumentType = apps.get_model('documents', 'DocumentType')
|
||||
DocumentTypeSettings = apps.get_model('document_parsing', 'DocumentTypeSettings')
|
||||
|
||||
for document_type in DocumentType.objects.all():
|
||||
for document_type in DocumentType.objects.using(schema_editor.connection.alias).all():
|
||||
try:
|
||||
DocumentTypeSettings.objects.get(document_type=document_type).delete()
|
||||
DocumentTypeSettings.objects.using(schema_editor.connection.alias).get(document_type=document_type).delete()
|
||||
except DocumentTypeSettings.DoesNotExist:
|
||||
pass
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ def generate_internal_name(apps, schema_editor):
|
||||
Workflow = apps.get_model('document_states', 'Workflow')
|
||||
internal_names = []
|
||||
|
||||
for workflow in Workflow.objects.all():
|
||||
for workflow in Workflow.objects.using(schema_editor.connection.alias).all():
|
||||
# Slugify and replace dashes (not allowed) by underscores
|
||||
workflow.internal_name = slugify(workflow.label).replace('-', '_')
|
||||
if workflow.internal_name in internal_names:
|
||||
|
||||
@@ -7,7 +7,7 @@ from django.db import models, migrations
|
||||
def make_existing_documents_not_stubs(apps, schema_editor):
|
||||
Document = apps.get_model('documents', 'Document')
|
||||
|
||||
for document in Document.objects.all():
|
||||
for document in Document.objects.using(schema_editor.connection.alias).all():
|
||||
document.is_stub = False
|
||||
document.save()
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ from django.db import migrations
|
||||
def change_bibliographic_to_terminology(apps, schema_editor):
|
||||
Document = apps.get_model('documents', 'Document')
|
||||
|
||||
for document in Document.objects.all():
|
||||
for document in Document.objects.using(schema_editor.connection.alias).all():
|
||||
try:
|
||||
language = pycountry.languages.get(bibliographic=document.language)
|
||||
except KeyError:
|
||||
|
||||
@@ -9,7 +9,7 @@ from django.db import migrations
|
||||
def convert_uuid_to_hex(apps, schema_editor):
|
||||
Document = apps.get_model('documents', 'Document')
|
||||
|
||||
for document in Document.objects.all():
|
||||
for document in Document.objects.using(schema_editor.connection.alias).all():
|
||||
document.uuid = uuid.UUID(document.uuid).hex
|
||||
document.save()
|
||||
|
||||
|
||||
@@ -22,13 +22,13 @@ def update_event_types_names(apps, schema_editor):
|
||||
|
||||
pattern = re.compile('|'.join(known_namespaces.keys()))
|
||||
|
||||
for event_type in StoredEventType.objects.all():
|
||||
for event_type in StoredEventType.objects.using(schema_editor.connection.alias).all():
|
||||
event_type.name = pattern.sub(
|
||||
lambda x: known_namespaces[x.group()], event_type.name
|
||||
)
|
||||
event_type.save()
|
||||
|
||||
for action in Action.objects.all():
|
||||
for action in Action.objects.using(schema_editor.connection.alias).all():
|
||||
action.verb = pattern.sub(
|
||||
lambda x: known_namespaces[x.group()], action.verb
|
||||
)
|
||||
@@ -50,7 +50,7 @@ def revert_event_types_names(apps, schema_editor):
|
||||
|
||||
pattern = re.compile('|'.join(known_namespaces.keys()))
|
||||
|
||||
for event_type in StoredEventType.objects.all():
|
||||
for event_type in StoredEventType.objects.using(schema_editor.connection.alias).all():
|
||||
old_name = event_type.name
|
||||
new_name = pattern.sub(
|
||||
lambda x: known_namespaces[x.group().replace('.', '\\.')],
|
||||
@@ -62,7 +62,7 @@ def revert_event_types_names(apps, schema_editor):
|
||||
else:
|
||||
event_type.save()
|
||||
|
||||
for action in Action.objects.all():
|
||||
for action in Action.objects.using(schema_editor.connection.alias).all():
|
||||
new_name = pattern.sub(
|
||||
lambda x: known_namespaces[x.group().replace('.', '\\.')],
|
||||
action.verb
|
||||
|
||||
@@ -8,12 +8,11 @@ def move_content_from_documents_to_ocr_app(apps, schema_editor):
|
||||
DocumentPage = apps.get_model('documents', 'DocumentPage')
|
||||
DocumentPageContent = apps.get_model('ocr', 'DocumentPageContent')
|
||||
|
||||
for document_page in DocumentPage.objects.all():
|
||||
document_page_content = DocumentPageContent(
|
||||
for document_page in DocumentPage.objects.using(schema_editor.connection.alias).all():
|
||||
document_page_content = DocumentPageContent.objects.using(schema_editor.connection.alias).create(
|
||||
document_page=document_page,
|
||||
content=document_page.content_old or ''
|
||||
)
|
||||
document_page_content.save()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
@@ -8,9 +8,11 @@ def create_ocr_setting_for_existing_document_types(apps, schema_editor):
|
||||
DocumentType = apps.get_model('documents', 'DocumentType')
|
||||
DocumentTypeSettings = apps.get_model('ocr', 'DocumentTypeSettings')
|
||||
|
||||
for document_type in DocumentType.objects.all():
|
||||
for document_type in DocumentType.objects.using(schema_editor.connection.alias).all():
|
||||
try:
|
||||
DocumentTypeSettings.objects.create(document_type=document_type)
|
||||
DocumentTypeSettings.objects.using(
|
||||
schema_editor.connection.alias
|
||||
).create(document_type=document_type)
|
||||
except DocumentTypeSettings.DoesNotExist:
|
||||
pass
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ RGB_VALUES = {
|
||||
def convert_color_names_to_rgb(apps, schema_editor):
|
||||
Tag = apps.get_model('tags', 'Tag')
|
||||
|
||||
for tag in Tag.objects.all():
|
||||
for tag in Tag.objects.using(schema_editor.connection.alias).all():
|
||||
tag.selection = RGB_VALUES[tag.color]
|
||||
tag.save()
|
||||
|
||||
|
||||
@@ -13,8 +13,10 @@ def add_user_options_to_existing_users(apps, schema_editor):
|
||||
app_label='user_management', model_name='UserOptions'
|
||||
)
|
||||
|
||||
for user in User.objects.all():
|
||||
UserOptions.objects.create(user=user)
|
||||
for user in User.objects.using(schema_editor.connection.alias).all():
|
||||
UserOptions.objects.using(
|
||||
schema_editor.connection.alias
|
||||
).create(user=user)
|
||||
|
||||
|
||||
def remove_user_options_from_existing_users(apps, schema_editor):
|
||||
@@ -23,8 +25,10 @@ def remove_user_options_from_existing_users(apps, schema_editor):
|
||||
app_label='user_management', model_name='UserOptions'
|
||||
)
|
||||
|
||||
for user in User.objects.all():
|
||||
UserOptions.objects.filter(user=user).delete()
|
||||
for user in User.objects.using(schema_editor.connection.alias).all():
|
||||
UserOptions.objects.using(
|
||||
schema_editor.connection.alias
|
||||
).filter(user=user).delete()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
Reference in New Issue
Block a user