From 992b7d028db5b4c4ef45e4a33b3dc4ce480b8270 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Fri, 13 Apr 2018 13:31:05 +0200 Subject: Refactoring of migrations --- .../migrations/0040_auto_20180409_1900.py | 55 ---------------------- .../migrations/0041_auto_20180409_1900.py | 55 ++++++++++++++++++++++ .../migrations/0041_auto_20180409_1901.py | 51 -------------------- .../migrations/0042_auto_20180409_1901.py | 51 ++++++++++++++++++++ .../migrations/0042_remove_persontype_groups.py | 19 -------- ishtar_common/migrations/0043_add_import_group.py | 31 ------------ .../migrations/0043_remove_persontype_groups.py | 19 ++++++++ ishtar_common/migrations/0044_add_import_group.py | 31 ++++++++++++ 8 files changed, 156 insertions(+), 156 deletions(-) delete mode 100644 ishtar_common/migrations/0040_auto_20180409_1900.py create mode 100644 ishtar_common/migrations/0041_auto_20180409_1900.py delete mode 100644 ishtar_common/migrations/0041_auto_20180409_1901.py create mode 100644 ishtar_common/migrations/0042_auto_20180409_1901.py delete mode 100644 ishtar_common/migrations/0042_remove_persontype_groups.py delete mode 100644 ishtar_common/migrations/0043_add_import_group.py create mode 100644 ishtar_common/migrations/0043_remove_persontype_groups.py create mode 100644 ishtar_common/migrations/0044_add_import_group.py diff --git a/ishtar_common/migrations/0040_auto_20180409_1900.py b/ishtar_common/migrations/0040_auto_20180409_1900.py deleted file mode 100644 index a8cf51e33..000000000 --- a/ishtar_common/migrations/0040_auto_20180409_1900.py +++ /dev/null @@ -1,55 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.10 on 2018-04-09 19:00 -from __future__ import unicode_literals - -import django.core.validators -from django.db import migrations, models -import django.db.models.deletion -import ishtar_common.models -import re - - -class Migration(migrations.Migration): - - dependencies = [ - ('auth', '0009_merge_20170821_1827'), - ('ishtar_common', '0039_auto_20180405_1923'), - ] - - operations = [ - migrations.CreateModel( - name='ProfileType', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('label', models.TextField(verbose_name='Label')), - ('txt_idx', models.TextField(help_text='The slug is the standardized version of the name. It contains only lowercase letters, numbers and hyphens. Each slug must be unique.', unique=True, validators=[django.core.validators.RegexValidator(re.compile('^[-a-zA-Z0-9_]+\\Z'), "Enter a valid 'slug' consisting of letters, numbers, underscores or hyphens.", 'invalid')], verbose_name='Textual ID')), - ('comment', models.TextField(blank=True, null=True, verbose_name='Comment')), - ('available', models.BooleanField(default=True, verbose_name='Available')), - ('groups', models.ManyToManyField(blank=True, to='auth.Group', verbose_name='Groups')), - ], - options={ - 'ordering': ('label',), - 'verbose_name': 'Profile type', - 'verbose_name_plural': 'Profile types', - }, - bases=(ishtar_common.models.Cached, models.Model), - ), - migrations.CreateModel( - name='UserProfile', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('current', models.BooleanField(default=False, verbose_name='Current profile')), - ('person', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='profiles', to='ishtar_common.Person', verbose_name='Person')), - ('profile_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='ishtar_common.ProfileType', verbose_name='Profile type')), - ], - options={ - 'verbose_name': 'User profile', - 'verbose_name_plural': 'User profiles', - }, - ), - migrations.AlterField( - model_name='import', - name='state', - field=models.CharField(choices=[(b'C', 'Created'), (b'AP', 'Analyse in progress'), (b'A', 'Analysed'), (b'HQ', 'Check modified in queue'), (b'IQ', 'Import in queue'), (b'HP', 'Check modified in progress'), (b'IP', 'Import in progress'), (b'PI', 'Partially imported'), (b'FE', 'Finished with errors'), (b'F', 'Finished'), (b'AC', 'Archived')], default='C', max_length=2, verbose_name='State'), - ), - ] diff --git a/ishtar_common/migrations/0041_auto_20180409_1900.py b/ishtar_common/migrations/0041_auto_20180409_1900.py new file mode 100644 index 000000000..a23f99b94 --- /dev/null +++ b/ishtar_common/migrations/0041_auto_20180409_1900.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.10 on 2018-04-09 19:00 +from __future__ import unicode_literals + +import django.core.validators +from django.db import migrations, models +import django.db.models.deletion +import ishtar_common.models +import re + + +class Migration(migrations.Migration): + + dependencies = [ + ('auth', '0009_merge_20170821_1827'), + ('ishtar_common', '0040_auto_20180413_1147'), + ] + + operations = [ + migrations.CreateModel( + name='ProfileType', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('label', models.TextField(verbose_name='Label')), + ('txt_idx', models.TextField(help_text='The slug is the standardized version of the name. It contains only lowercase letters, numbers and hyphens. Each slug must be unique.', unique=True, validators=[django.core.validators.RegexValidator(re.compile('^[-a-zA-Z0-9_]+\\Z'), "Enter a valid 'slug' consisting of letters, numbers, underscores or hyphens.", 'invalid')], verbose_name='Textual ID')), + ('comment', models.TextField(blank=True, null=True, verbose_name='Comment')), + ('available', models.BooleanField(default=True, verbose_name='Available')), + ('groups', models.ManyToManyField(blank=True, to='auth.Group', verbose_name='Groups')), + ], + options={ + 'ordering': ('label',), + 'verbose_name': 'Profile type', + 'verbose_name_plural': 'Profile types', + }, + bases=(ishtar_common.models.Cached, models.Model), + ), + migrations.CreateModel( + name='UserProfile', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('current', models.BooleanField(default=False, verbose_name='Current profile')), + ('person', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='profiles', to='ishtar_common.Person', verbose_name='Person')), + ('profile_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='ishtar_common.ProfileType', verbose_name='Profile type')), + ], + options={ + 'verbose_name': 'User profile', + 'verbose_name_plural': 'User profiles', + }, + ), + migrations.AlterField( + model_name='import', + name='state', + field=models.CharField(choices=[(b'C', 'Created'), (b'AP', 'Analyse in progress'), (b'A', 'Analysed'), (b'HQ', 'Check modified in queue'), (b'IQ', 'Import in queue'), (b'HP', 'Check modified in progress'), (b'IP', 'Import in progress'), (b'PI', 'Partially imported'), (b'FE', 'Finished with errors'), (b'F', 'Finished'), (b'AC', 'Archived')], default='C', max_length=2, verbose_name='State'), + ), + ] diff --git a/ishtar_common/migrations/0041_auto_20180409_1901.py b/ishtar_common/migrations/0041_auto_20180409_1901.py deleted file mode 100644 index cc34bb91c..000000000 --- a/ishtar_common/migrations/0041_auto_20180409_1901.py +++ /dev/null @@ -1,51 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.10 on 2018-04-09 17:29 -from __future__ import unicode_literals - -from django.db import migrations - - -def initialize_profiles(apps, schema_editor): - # Migrate PersonType -> ProfileType - PersonType = apps.get_model('ishtar_common', 'PersonType') - ProfileType = apps.get_model('ishtar_common', 'ProfileType') - UserProfile = apps.get_model('ishtar_common', 'UserProfile') - Person = apps.get_model('ishtar_common', 'Person') - - # create profile types from person types - profile_types = {} - for person_type in PersonType.objects.all(): - default = { - 'label': person_type.label, - 'comment': person_type.comment, - 'available': person_type.available, - } - pt, created = ProfileType.objects.get_or_create( - txt_idx=person_type.txt_idx, defaults=default) - if created: - for gp in person_type.groups.all(): - pt.groups.add(gp) - profile_types[pt.txt_idx] = pt - - # match profile type with person types - for person in Person.objects.filter(ishtaruser__isnull=False): - # is current if only one person_type is concerned - current = person.person_types.count() == 1 - # only person with an account are concerned - for person_type in person.person_types.all(): - UserProfile.objects.create( - profile_type=profile_types[person_type.txt_idx], - person=person, - current=current - ) - - -class Migration(migrations.Migration): - - dependencies = [ - ('ishtar_common', '0040_auto_20180409_1900'), - ] - - operations = [ - migrations.RunPython(initialize_profiles), - ] diff --git a/ishtar_common/migrations/0042_auto_20180409_1901.py b/ishtar_common/migrations/0042_auto_20180409_1901.py new file mode 100644 index 000000000..a2faa24e4 --- /dev/null +++ b/ishtar_common/migrations/0042_auto_20180409_1901.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.10 on 2018-04-09 17:29 +from __future__ import unicode_literals + +from django.db import migrations + + +def initialize_profiles(apps, schema_editor): + # Migrate PersonType -> ProfileType + PersonType = apps.get_model('ishtar_common', 'PersonType') + ProfileType = apps.get_model('ishtar_common', 'ProfileType') + UserProfile = apps.get_model('ishtar_common', 'UserProfile') + Person = apps.get_model('ishtar_common', 'Person') + + # create profile types from person types + profile_types = {} + for person_type in PersonType.objects.all(): + default = { + 'label': person_type.label, + 'comment': person_type.comment, + 'available': person_type.available, + } + pt, created = ProfileType.objects.get_or_create( + txt_idx=person_type.txt_idx, defaults=default) + if created: + for gp in person_type.groups.all(): + pt.groups.add(gp) + profile_types[pt.txt_idx] = pt + + # match profile type with person types + for person in Person.objects.filter(ishtaruser__isnull=False): + # is current if only one person_type is concerned + current = person.person_types.count() == 1 + # only person with an account are concerned + for person_type in person.person_types.all(): + UserProfile.objects.create( + profile_type=profile_types[person_type.txt_idx], + person=person, + current=current + ) + + +class Migration(migrations.Migration): + + dependencies = [ + ('ishtar_common', '0041_auto_20180409_1900'), + ] + + operations = [ + migrations.RunPython(initialize_profiles), + ] diff --git a/ishtar_common/migrations/0042_remove_persontype_groups.py b/ishtar_common/migrations/0042_remove_persontype_groups.py deleted file mode 100644 index 8be0539ad..000000000 --- a/ishtar_common/migrations/0042_remove_persontype_groups.py +++ /dev/null @@ -1,19 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.10 on 2018-04-10 18:14 -from __future__ import unicode_literals - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('ishtar_common', '0041_auto_20180409_1901'), - ] - - operations = [ - migrations.RemoveField( - model_name='persontype', - name='groups', - ), - ] diff --git a/ishtar_common/migrations/0043_add_import_group.py b/ishtar_common/migrations/0043_add_import_group.py deleted file mode 100644 index 1587dcff1..000000000 --- a/ishtar_common/migrations/0043_add_import_group.py +++ /dev/null @@ -1,31 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.10 on 2018-04-12 17:51 -from __future__ import unicode_literals - -from django.db import migrations - - -def add_import_group(apps, schema_editor): - Group = apps.get_model('auth', 'Group') - ProfileType = apps.get_model('ishtar_common', 'ProfileType') - gp, created = Group.objects.get_or_create( - name="Import : ajout/modification/suppression") - pt, created = ProfileType.objects.get_or_create( - txt_idx="administrator", - defaults={ - 'label':"Administrateur", 'comment': "", 'available':True - } - ) - if gp.pk not in list([g.pk for g in pt.groups.all()]): - pt.groups.add(gp) - - -class Migration(migrations.Migration): - - dependencies = [ - ('ishtar_common', '0042_remove_persontype_groups'), - ] - - operations = [ - migrations.RunPython(add_import_group), - ] diff --git a/ishtar_common/migrations/0043_remove_persontype_groups.py b/ishtar_common/migrations/0043_remove_persontype_groups.py new file mode 100644 index 000000000..ca6ce904c --- /dev/null +++ b/ishtar_common/migrations/0043_remove_persontype_groups.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.10 on 2018-04-10 18:14 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('ishtar_common', '0042_auto_20180409_1901'), + ] + + operations = [ + migrations.RemoveField( + model_name='persontype', + name='groups', + ), + ] diff --git a/ishtar_common/migrations/0044_add_import_group.py b/ishtar_common/migrations/0044_add_import_group.py new file mode 100644 index 000000000..7aa48f969 --- /dev/null +++ b/ishtar_common/migrations/0044_add_import_group.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.10 on 2018-04-12 17:51 +from __future__ import unicode_literals + +from django.db import migrations + + +def add_import_group(apps, schema_editor): + Group = apps.get_model('auth', 'Group') + ProfileType = apps.get_model('ishtar_common', 'ProfileType') + gp, created = Group.objects.get_or_create( + name="Import : ajout/modification/suppression") + pt, created = ProfileType.objects.get_or_create( + txt_idx="administrator", + defaults={ + 'label':"Administrateur", 'comment': "", 'available':True + } + ) + if gp.pk not in list([g.pk for g in pt.groups.all()]): + pt.groups.add(gp) + + +class Migration(migrations.Migration): + + dependencies = [ + ('ishtar_common', '0043_remove_persontype_groups'), + ] + + operations = [ + migrations.RunPython(add_import_group), + ] -- cgit v1.2.3