From 1bd90f9304280cff05688b97c4a6ae50ab58783a Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Wed, 30 Jun 2021 15:33:35 +0200 Subject: [PATCH] fixed migration order and dependencies --- .../0124_alter_userpreference_theme.py | 18 +++ cookbook/migrations/0125_space_demo.py | 2 +- .../migrations/0132_build_full_text_index.py | 111 ------------------ .../migrations/0133_create_searchfields.py | 23 ---- ...ord_to_tree.py => 0141_keyword_to_tree.py} | 2 +- ...index.py => 0142_build_full_text_index.py} | 2 +- ...hfields.py => 0143_create_searchfields.py} | 2 +- ...0144_alter_userpreference_search_style.py} | 2 +- 8 files changed, 23 insertions(+), 139 deletions(-) create mode 100644 cookbook/migrations/0124_alter_userpreference_theme.py delete mode 100644 cookbook/migrations/0132_build_full_text_index.py delete mode 100644 cookbook/migrations/0133_create_searchfields.py rename cookbook/migrations/{0134_keyword_to_tree.py => 0141_keyword_to_tree.py} (97%) rename cookbook/migrations/{0141_build_full_text_index.py => 0142_build_full_text_index.py} (98%) rename cookbook/migrations/{0142_create_searchfields.py => 0143_create_searchfields.py} (92%) rename cookbook/migrations/{0124_alter_userpreference_search_style.py => 0144_alter_userpreference_search_style.py} (89%) diff --git a/cookbook/migrations/0124_alter_userpreference_theme.py b/cookbook/migrations/0124_alter_userpreference_theme.py new file mode 100644 index 000000000..6190a46f0 --- /dev/null +++ b/cookbook/migrations/0124_alter_userpreference_theme.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.3 on 2021-05-30 15:53 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('cookbook', '0123_invitelink_email'), + ] + + operations = [ + migrations.AlterField( + model_name='userpreference', + name='theme', + field=models.CharField(choices=[('BOOTSTRAP', 'Bootstrap'), ('DARKLY', 'Darkly'), ('FLATLY', 'Flatly'), ('SUPERHERO', 'Superhero'), ('TANDOOR', 'Tandoor')], default='FLATLY', max_length=128), + ), + ] \ No newline at end of file diff --git a/cookbook/migrations/0125_space_demo.py b/cookbook/migrations/0125_space_demo.py index 5904bb90a..ea2528790 100644 --- a/cookbook/migrations/0125_space_demo.py +++ b/cookbook/migrations/0125_space_demo.py @@ -6,7 +6,7 @@ from django.db import migrations, models class Migration(migrations.Migration): dependencies = [ - ('cookbook', '0124_alter_userpreference_search_style'), + ('cookbook', '0124_alter_userpreference_theme'), ] operations = [ diff --git a/cookbook/migrations/0132_build_full_text_index.py b/cookbook/migrations/0132_build_full_text_index.py deleted file mode 100644 index e7428ed4c..000000000 --- a/cookbook/migrations/0132_build_full_text_index.py +++ /dev/null @@ -1,111 +0,0 @@ -# Generated by Django 3.1.7 on 2021-04-07 20:00 -import annoying.fields -from django.conf import settings -from django.contrib.postgres.indexes import GinIndex -from django.contrib.postgres.search import SearchVectorField, SearchVector -from django.db import migrations, models -from django.db.models import deletion -from django_scopes import scopes_disabled -from django.utils import translation -from cookbook.managers import DICTIONARY -from cookbook.models import Recipe, Step, Index, PermissionModelMixin, nameSearchField, allSearchFields - - -def set_default_search_vector(apps, schema_editor): - if settings.DATABASES['default']['ENGINE'] not in ['django.db.backends.postgresql_psycopg2', 'django.db.backends.postgresql']: - return - language = DICTIONARY.get(translation.get_language(), 'simple') - with scopes_disabled(): - # TODO this approach doesn't work terribly well if multiple languages are in use - # I'm also uncertain about forcing unaccent here - Recipe.objects.all().update( - name_search_vector=SearchVector('name__unaccent', weight='A', config=language), - desc_search_vector=SearchVector('description__unaccent', weight='B', config=language) - ) - Step.objects.all().update(search_vector=SearchVector('instruction__unaccent', weight='B')) - - -class Migration(migrations.Migration): - dependencies = [ - ('auth', '0012_alter_user_first_name_max_length'), - ('cookbook', '0131_auto_20210608_1929'), - ] - operations = [ - migrations.AddField( - model_name='recipe', - name='desc_search_vector', - field=SearchVectorField(null=True), - ), - migrations.AddField( - model_name='recipe', - name='name_search_vector', - field=SearchVectorField(null=True), - ), - migrations.AddIndex( - model_name='recipe', - index=GinIndex(fields=['name_search_vector', 'desc_search_vector'], name='cookbook_re_name_se_bdf3ca_gin'), - ), - migrations.AddField( - model_name='step', - name='search_vector', - field=SearchVectorField(null=True), - ), - migrations.AddIndex( - model_name='step', - index=GinIndex(fields=['search_vector'], name='cookbook_st_search__2ef7fa_gin'), - ), - migrations.AddIndex( - model_name='cooklog', - index=Index(fields=['id', 'recipe', '-created_at', 'rating'], name='cookbook_co_id_37485a_idx'), - ), - migrations.AddIndex( - model_name='food', - index=Index(fields=['id', 'name'], name='cookbook_fo_id_22b733_idx'), - ), - migrations.AddIndex( - model_name='ingredient', - index=Index(fields=['id', 'food', 'unit'], name='cookbook_in_id_3368be_idx'), - ), - migrations.AddIndex( - model_name='keyword', - index=Index(fields=['id', 'name'], name='cookbook_ke_id_ebc03f_idx'), - ), - migrations.AddIndex( - model_name='recipe', - index=Index(fields=['id', 'name', 'description'], name='cookbook_re_id_e4c2d4_idx'), - ), - migrations.AddIndex( - model_name='recipebook', - index=Index(fields=['name', 'description'], name='cookbook_re_name_bbe446_idx'), - ), - migrations.AddIndex( - model_name='viewlog', - index=Index(fields=['recipe', '-created_at'], name='cookbook_vi_recipe__5cd178_idx'), - ), - migrations.CreateModel( - name='SearchFields', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('name', models.CharField(max_length=32, unique=True)), - ('field', models.CharField(max_length=64, unique=True)), - ], - bases=(models.Model, PermissionModelMixin), - ), - migrations.CreateModel( - name='SearchPreference', - fields=[ - ('user', annoying.fields.AutoOneToOneField(on_delete=deletion.CASCADE, primary_key=True, serialize=False, to='auth.user')), - ('search', models.CharField(choices=[('plain', 'Simple'), ('phrase', 'Phrase'), ('websearch', 'Web'), ('raw', 'Raw')], default='plain', max_length=32)), - ('lookup', models.BooleanField(default=False)), - ('fulltext', models.ManyToManyField(blank=True, related_name='fulltext_fields', to='cookbook.SearchFields')), - ('icontains', models.ManyToManyField(blank=True, default=nameSearchField, related_name='icontains_fields', to='cookbook.SearchFields')), - ('istartswith', models.ManyToManyField(blank=True, related_name='istartswith_fields', to='cookbook.SearchFields')), - ('trigram', models.ManyToManyField(blank=True, related_name='trigram_fields', to='cookbook.SearchFields')), - ('unaccent', models.ManyToManyField(blank=True, default=allSearchFields, related_name='unaccent_fields', to='cookbook.SearchFields')), - ], - bases=(models.Model, PermissionModelMixin), - ), - migrations.RunPython( - set_default_search_vector - ), - ] diff --git a/cookbook/migrations/0133_create_searchfields.py b/cookbook/migrations/0133_create_searchfields.py deleted file mode 100644 index 647c0875d..000000000 --- a/cookbook/migrations/0133_create_searchfields.py +++ /dev/null @@ -1,23 +0,0 @@ -from cookbook.models import SearchFields -from django.db import migrations - - -def create_searchfields(apps, schema_editor): - SearchFields.objects.create(name='Name', field='name') - SearchFields.objects.create(name='Description', field='description') - SearchFields.objects.create(name='Instructions', field='steps__instruction') - SearchFields.objects.create(name='Ingredients', field='steps__ingredients__food__name') - SearchFields.objects.create(name='Keywords', field='keywords__name') - - -class Migration(migrations.Migration): - - dependencies = [ - ('cookbook', '0132_build_full_text_index'), - ] - - operations = [ - migrations.RunPython( - create_searchfields - ), - ] diff --git a/cookbook/migrations/0134_keyword_to_tree.py b/cookbook/migrations/0141_keyword_to_tree.py similarity index 97% rename from cookbook/migrations/0134_keyword_to_tree.py rename to cookbook/migrations/0141_keyword_to_tree.py index 59cb1bf6c..f4337a6ac 100644 --- a/cookbook/migrations/0134_keyword_to_tree.py +++ b/cookbook/migrations/0141_keyword_to_tree.py @@ -27,7 +27,7 @@ def backwards(apps, schema_editor): class Migration(migrations.Migration): dependencies = [ - ('cookbook', '0133_create_searchfields'), + ('cookbook', '0140_userpreference_created_at'), ] operations = [ diff --git a/cookbook/migrations/0141_build_full_text_index.py b/cookbook/migrations/0142_build_full_text_index.py similarity index 98% rename from cookbook/migrations/0141_build_full_text_index.py rename to cookbook/migrations/0142_build_full_text_index.py index 0163a0ed3..1c00d5d09 100644 --- a/cookbook/migrations/0141_build_full_text_index.py +++ b/cookbook/migrations/0142_build_full_text_index.py @@ -27,7 +27,7 @@ def set_default_search_vector(apps, schema_editor): class Migration(migrations.Migration): dependencies = [ - ('cookbook', '0140_userpreference_created_at'), + ('cookbook', '0141_keyword_to_tree'), ] operations = [ migrations.AddField( diff --git a/cookbook/migrations/0142_create_searchfields.py b/cookbook/migrations/0143_create_searchfields.py similarity index 92% rename from cookbook/migrations/0142_create_searchfields.py rename to cookbook/migrations/0143_create_searchfields.py index a61f1852f..79fb986a5 100644 --- a/cookbook/migrations/0142_create_searchfields.py +++ b/cookbook/migrations/0143_create_searchfields.py @@ -13,7 +13,7 @@ def create_searchfields(apps, schema_editor): class Migration(migrations.Migration): dependencies = [ - ('cookbook', '0141_build_full_text_index'), + ('cookbook', '0142_build_full_text_index'), ] operations = [ diff --git a/cookbook/migrations/0124_alter_userpreference_search_style.py b/cookbook/migrations/0144_alter_userpreference_search_style.py similarity index 89% rename from cookbook/migrations/0124_alter_userpreference_search_style.py rename to cookbook/migrations/0144_alter_userpreference_search_style.py index 37b817823..6a9417abb 100644 --- a/cookbook/migrations/0124_alter_userpreference_search_style.py +++ b/cookbook/migrations/0144_alter_userpreference_search_style.py @@ -6,7 +6,7 @@ from django.db import migrations, models class Migration(migrations.Migration): dependencies = [ - ('cookbook', '0123_invitelink_email'), + ('cookbook', '0143_create_searchfields'), ] operations = [