Style: Prepend "operation_" to data migrations

Prepend "operation_" to the data migration functions
for clear purpose. Add keyword arguments to the RunPython
migration opration.

Signed-off-by: Roberto Rosario <Roberto.Rosario@mayan-edms.com>
This commit is contained in:
Roberto Rosario
2018-12-07 17:28:22 -04:00
parent ab1482152e
commit 255b1c75ea
11 changed files with 29 additions and 29 deletions
@@ -4,7 +4,7 @@ from __future__ import unicode_literals
from django.db import migrations from django.db import migrations
def move_from_content_type_user_to_foreign_key_field_user(apps, schema_editor): def operation_move_from_content_type_user_to_foreign_key_field_user(apps, schema_editor):
# The model references the use who checked out the document using a # The model references the use who checked out the document using a
# generic.GenericForeignKey. This migrations changes that to a simpler # generic.GenericForeignKey. This migrations changes that to a simpler
# ForeignKey to the User model # ForeignKey to the User model
@@ -24,6 +24,6 @@ class Migration(migrations.Migration):
operations = [ operations = [
migrations.RunPython( migrations.RunPython(
move_from_content_type_user_to_foreign_key_field_user code=operation_move_from_content_type_user_to_foreign_key_field_user
), ),
] ]
@@ -4,7 +4,7 @@ from django.conf import settings
from django.db import migrations from django.db import migrations
def migrate_old_comments(apps, schema_editor): def operation_migrate_old_comments(apps, schema_editor):
# https://code.djangoproject.com/ticket/24282 # https://code.djangoproject.com/ticket/24282
# If someone has a better solution until Django 1.8, would appreciate # If someone has a better solution until Django 1.8, would appreciate
# a pull-request :) # a pull-request :)
@@ -43,5 +43,5 @@ class Migration(migrations.Migration):
] ]
operations = [ operations = [
migrations.RunPython(migrate_old_comments), migrations.RunPython(code=operation_migrate_old_comments),
] ]
@@ -4,7 +4,7 @@ from django.db import migrations
from django.template.defaultfilters import slugify from django.template.defaultfilters import slugify
def assign_slugs(apps, schema_editor): def operation_assign_slugs(apps, schema_editor):
Index = apps.get_model('document_indexing', 'Index') Index = apps.get_model('document_indexing', 'Index')
for index in Index.objects.using(schema_editor.connection.alias).all(): for index in Index.objects.using(schema_editor.connection.alias).all():
@@ -19,5 +19,5 @@ class Migration(migrations.Migration):
] ]
operations = [ operations = [
migrations.RunPython(assign_slugs), migrations.RunPython(code=operation_assign_slugs),
] ]
@@ -4,7 +4,7 @@ import django.db.models.deletion
from django.db import migrations, models from django.db import migrations, models
def create_parsing_setting_for_existing_document_types(apps, schema_editor): def operation_create_parsing_setting_for_existing_document_types(apps, schema_editor):
DocumentType = apps.get_model('documents', 'DocumentType') DocumentType = apps.get_model('documents', 'DocumentType')
DocumentTypeSettings = apps.get_model( DocumentTypeSettings = apps.get_model(
'document_parsing', 'DocumentTypeSettings' 'document_parsing', 'DocumentTypeSettings'
@@ -19,7 +19,7 @@ def create_parsing_setting_for_existing_document_types(apps, schema_editor):
pass pass
def delete_parsing_setting_for_existing_document_types(apps, schema_editor): def operation_delete_parsing_setting_for_existing_document_types(apps, schema_editor):
DocumentType = apps.get_model('documents', 'DocumentType') DocumentType = apps.get_model('documents', 'DocumentType')
DocumentTypeSettings = apps.get_model( DocumentTypeSettings = apps.get_model(
'document_parsing', 'DocumentTypeSettings' 'document_parsing', 'DocumentTypeSettings'
@@ -72,7 +72,7 @@ class Migration(migrations.Migration):
}, },
), ),
migrations.RunPython( migrations.RunPython(
code=create_parsing_setting_for_existing_document_types, code=operation_create_parsing_setting_for_existing_document_types,
reverse_code=delete_parsing_setting_for_existing_document_types, reverse_code=operation_delete_parsing_setting_for_existing_document_types,
) )
] ]
@@ -6,7 +6,7 @@ from django.utils.text import slugify
from mayan.apps.common.validators import validate_internal_name from mayan.apps.common.validators import validate_internal_name
def generate_internal_name(apps, schema_editor): def operation_generate_internal_name(apps, schema_editor):
Workflow = apps.get_model('document_states', 'Workflow') Workflow = apps.get_model('document_states', 'Workflow')
internal_names = [] internal_names = []
@@ -48,7 +48,7 @@ class Migration(migrations.Migration):
# Generate the slugs based on the labels # Generate the slugs based on the labels
migrations.RunPython( migrations.RunPython(
generate_internal_name, reverse_code=migrations.RunPython.noop code=operation_generate_internal_name, reverse_code=migrations.RunPython.noop
), ),
# Make the internal name field unique # Make the internal name field unique
@@ -7,7 +7,7 @@ import re
from django.db import migrations from django.db import migrations
def update_event_types_names(apps, schema_editor): def operation_update_event_types_names(apps, schema_editor):
Action = apps.get_model('actstream', 'Action') Action = apps.get_model('actstream', 'Action')
StoredEventType = apps.get_model('events', 'StoredEventType') StoredEventType = apps.get_model('events', 'StoredEventType')
@@ -35,7 +35,7 @@ def update_event_types_names(apps, schema_editor):
action.save() action.save()
def revert_event_types_names(apps, schema_editor): def operation_revert_event_types_names(apps, schema_editor):
Action = apps.get_model('actstream', 'Action') Action = apps.get_model('actstream', 'Action')
StoredEventType = apps.get_model('events', 'StoredEventType') StoredEventType = apps.get_model('events', 'StoredEventType')
@@ -80,7 +80,7 @@ class Migration(migrations.Migration):
operations = [ operations = [
migrations.RunPython( migrations.RunPython(
code=update_event_types_names, code=operation_update_event_types_names,
reverse_code=revert_event_types_names reverse_code=operation_revert_event_types_names
), ),
] ]
@@ -4,7 +4,7 @@ from __future__ import unicode_literals
from django.db import migrations from django.db import migrations
def move_content_from_documents_to_ocr_app(apps, schema_editor): def operation_move_content_from_documents_to_ocr_app(apps, schema_editor):
DocumentPage = apps.get_model('documents', 'DocumentPage') DocumentPage = apps.get_model('documents', 'DocumentPage')
DocumentPageContent = apps.get_model('ocr', 'DocumentPageContent') DocumentPageContent = apps.get_model('ocr', 'DocumentPageContent')
@@ -22,5 +22,5 @@ class Migration(migrations.Migration):
] ]
operations = [ operations = [
migrations.RunPython(move_content_from_documents_to_ocr_app), migrations.RunPython(code=operation_move_content_from_documents_to_ocr_app),
] ]
@@ -4,7 +4,7 @@ from __future__ import unicode_literals
from django.db import models, migrations from django.db import models, migrations
def create_ocr_setting_for_existing_document_types(apps, schema_editor): def operation_create_ocr_setting_for_existing_document_types(apps, schema_editor):
DocumentType = apps.get_model('documents', 'DocumentType') DocumentType = apps.get_model('documents', 'DocumentType')
DocumentTypeSettings = apps.get_model('ocr', 'DocumentTypeSettings') DocumentTypeSettings = apps.get_model('ocr', 'DocumentTypeSettings')
@@ -55,5 +55,5 @@ class Migration(migrations.Migration):
}, },
bases=(models.Model,), bases=(models.Model,),
), ),
migrations.RunPython(create_ocr_setting_for_existing_document_types), migrations.RunPython(code=operation_create_ocr_setting_for_existing_document_types),
] ]
@@ -5,7 +5,7 @@ from __future__ import unicode_literals
from django.db import migrations, models from django.db import migrations, models
def make_labels_unique(apps, schema_editor): def operation_make_labels_unique(apps, schema_editor):
Source = apps.get_model('sources', 'Source') Source = apps.get_model('sources', 'Source')
for source in Source.objects.using(schema_editor.connection.alias).all(): for source in Source.objects.using(schema_editor.connection.alias).all():
@@ -18,7 +18,7 @@ def make_labels_unique(apps, schema_editor):
source.save() source.save()
def make_labels_unique_reverse(apps, schema_editor): def operation_make_labels_unique_reverse(apps, schema_editor):
Source = apps.get_model('sources', 'Source') Source = apps.get_model('sources', 'Source')
for source in Source.objects.using(schema_editor.connection.alias).all(): for source in Source.objects.using(schema_editor.connection.alias).all():
@@ -35,7 +35,7 @@ class Migration(migrations.Migration):
operations = [ operations = [
migrations.RunPython( migrations.RunPython(
make_labels_unique, reverse_code=make_labels_unique_reverse code=operation_make_labels_unique, reverse_code=operation_make_labels_unique_reverse
), ),
migrations.AlterField( migrations.AlterField(
model_name='source', model_name='source',
@@ -31,7 +31,7 @@ RGB_VALUES = {
} }
def convert_color_names_to_rgb(apps, schema_editor): def operation_convert_color_names_to_rgb(apps, schema_editor):
Tag = apps.get_model('tags', 'Tag') Tag = apps.get_model('tags', 'Tag')
for tag in Tag.objects.using(schema_editor.connection.alias).all(): for tag in Tag.objects.using(schema_editor.connection.alias).all():
@@ -52,5 +52,5 @@ class Migration(migrations.Migration):
field=colorful.fields.RGBColorField(default='#FFFFFF'), field=colorful.fields.RGBColorField(default='#FFFFFF'),
preserve_default=False, preserve_default=False,
), ),
migrations.RunPython(convert_color_names_to_rgb), migrations.RunPython(code=operation_convert_color_names_to_rgb),
] ]
@@ -7,7 +7,7 @@ from django.db import migrations, models
import django.db.models.deletion import django.db.models.deletion
def add_user_options_to_existing_users(apps, schema_editor): def operation_add_user_options_to_existing_users(apps, schema_editor):
User = apps.get_model(settings.AUTH_USER_MODEL) User = apps.get_model(settings.AUTH_USER_MODEL)
UserOptions = apps.get_model( UserOptions = apps.get_model(
app_label='user_management', model_name='UserOptions' app_label='user_management', model_name='UserOptions'
@@ -19,7 +19,7 @@ def add_user_options_to_existing_users(apps, schema_editor):
).create(user=user) ).create(user=user)
def remove_user_options_from_existing_users(apps, schema_editor): def operation_remove_user_options_from_existing_users(apps, schema_editor):
User = apps.get_model(settings.AUTH_USER_MODEL) User = apps.get_model(settings.AUTH_USER_MODEL)
UserOptions = apps.get_model( UserOptions = apps.get_model(
app_label='user_management', model_name='UserOptions' app_label='user_management', model_name='UserOptions'
@@ -53,7 +53,7 @@ class Migration(migrations.Migration):
}, },
), ),
migrations.RunPython( migrations.RunPython(
code=add_user_options_to_existing_users, code=operation_add_user_options_to_existing_users,
reverse_code=remove_user_options_from_existing_users reverse_code=operation_remove_user_options_from_existing_users
), ),
] ]