From 1f484c625dd08f4de5d50cb474955848fb1c85db Mon Sep 17 00:00:00 2001 From: Iacopo Spalletti Date: Sat, 25 Jun 2016 17:10:28 +0200 Subject: [PATCH 1/2] Moar migration fixes --- .../migrations/0017_thumbnail_move.py | 34 +++++++------- .../migrations/0018_thumbnail_move2.py | 43 +++++++++++++++++ .../migrations/0019_thumbnail_move3.py | 45 ++++++++++++++++++ .../migrations/0020_thumbnail_move4.py | 47 +++++++++++++++++++ 4 files changed, 153 insertions(+), 16 deletions(-) create mode 100644 djangocms_blog/migrations/0018_thumbnail_move2.py create mode 100644 djangocms_blog/migrations/0019_thumbnail_move3.py create mode 100644 djangocms_blog/migrations/0020_thumbnail_move4.py diff --git a/djangocms_blog/migrations/0017_thumbnail_move.py b/djangocms_blog/migrations/0017_thumbnail_move.py index fce5e56..f125639 100644 --- a/djangocms_blog/migrations/0017_thumbnail_move.py +++ b/djangocms_blog/migrations/0017_thumbnail_move.py @@ -16,6 +16,23 @@ class Migration(migrations.Migration): run_before = [ ('cmsplugin_filer_image', '0004_auto_20160120_0950'), ] + + operations = [ + migrations.AlterField( + model_name='post', + name='main_image_full', + field=models.ForeignKey(related_name='djangocms_blog_post_full', + verbose_name='Main image full', blank=True, + to=thumbnail_model, null=True), + ), + migrations.AlterField( + model_name='post', + name='main_image_thumbnail', + field=models.ForeignKey(related_name='djangocms_blog_post_thumbnail', + verbose_name='Main image thumbnail', blank=True, + to=thumbnail_model, null=True), + ), + ] else: dependencies = [ ('filer', '__first__'), @@ -23,19 +40,4 @@ class Migration(migrations.Migration): ('djangocms_blog', '0016_auto_20160502_1741'), ] - operations = [ - migrations.AlterField( - model_name='post', - name='main_image_full', - field=models.ForeignKey(related_name='djangocms_blog_post_full', - verbose_name='Main image full', blank=True, - to=thumbnail_model, null=True), - ), - migrations.AlterField( - model_name='post', - name='main_image_thumbnail', - field=models.ForeignKey(related_name='djangocms_blog_post_thumbnail', - verbose_name='Main image thumbnail', blank=True, - to=thumbnail_model, null=True), - ), - ] + operations = [] diff --git a/djangocms_blog/migrations/0018_thumbnail_move2.py b/djangocms_blog/migrations/0018_thumbnail_move2.py new file mode 100644 index 0000000..be5b3df --- /dev/null +++ b/djangocms_blog/migrations/0018_thumbnail_move2.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models +from djangocms_blog.models import thumbnail_model + + +class Migration(migrations.Migration): + + if 'cmsplugin_filer' not in thumbnail_model: + dependencies = [ + ('djangocms_blog', '0017_thumbnail_move'), + ('filer', '0003_thumbnailoption'), + ('cmsplugin_filer_image', '0003_mv_thumbnail_option_to_filer_20160119_1720'), + ] + run_before = [ + ('cmsplugin_filer_image', '0004_auto_20160120_0950'), + ] + + operations = [ + migrations.AddField( + model_name='post', + name='main_image_full_new', + field=models.ForeignKey(related_name='djangocms_blog_post_full', + verbose_name='Main image full', blank=True, + to=thumbnail_model, null=True), + ), + migrations.AddField( + model_name='post', + name='main_image_thumbnail_new', + field=models.ForeignKey(related_name='djangocms_blog_post_thumbnail', + verbose_name='Main image thumbnail', blank=True, + to=thumbnail_model, null=True), + ), + ] + else: + dependencies = [ + ('filer', '__first__'), + ('cmsplugin_filer_image', '__first__'), + ('djangocms_blog', '0017_thumbnail_move'), + ] + + operations = [] diff --git a/djangocms_blog/migrations/0019_thumbnail_move3.py b/djangocms_blog/migrations/0019_thumbnail_move3.py new file mode 100644 index 0000000..5253093 --- /dev/null +++ b/djangocms_blog/migrations/0019_thumbnail_move3.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models +from djangocms_blog.models import thumbnail_model + + +def move_thumbnail_opt_to_filer(apps, schema_editor): + Post = apps.get_model('djangocms_blog', 'Post') + for post in Post.objects.all(): + post.main_image_full_new_id = post.main_image_full_id + post.main_image_thumbnail_new_id = post.main_image_thumbnail_id + post.save() + + +def move_thumbnail_opt_to_plugin(apps, schema_editor): + Post = apps.get_model('djangocms_blog', 'Post') + for post in Post.objects.all(): + post.main_image_full_id = post.main_image_full_new_id + post.main_image_thumbnail_id = post.main_image_thumbnail_new_id + post.save() + + +class Migration(migrations.Migration): + if 'cmsplugin_filer' not in thumbnail_model: + dependencies = [ + ('djangocms_blog', '0018_thumbnail_move2'), + ('filer', '0003_thumbnailoption'), + ('cmsplugin_filer_image', '0003_mv_thumbnail_option_to_filer_20160119_1720'), + ] + run_before = [ + ('cmsplugin_filer_image', '0004_auto_20160120_0950'), + ] + + operations = [ + migrations.RunPython(move_thumbnail_opt_to_filer, move_thumbnail_opt_to_plugin), + ] + else: + dependencies = [ + ('filer', '__first__'), + ('cmsplugin_filer_image', '__first__'), + ('djangocms_blog', '0018_thumbnail_move2'), + ] + + operations = [] diff --git a/djangocms_blog/migrations/0020_thumbnail_move4.py b/djangocms_blog/migrations/0020_thumbnail_move4.py new file mode 100644 index 0000000..5968ca0 --- /dev/null +++ b/djangocms_blog/migrations/0020_thumbnail_move4.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models +from djangocms_blog.models import thumbnail_model + + +class Migration(migrations.Migration): + + if 'cmsplugin_filer' not in thumbnail_model: + dependencies = [ + ('djangocms_blog', '0019_thumbnail_move3'), + ('filer', '0003_thumbnailoption'), + ('cmsplugin_filer_image', '0003_mv_thumbnail_option_to_filer_20160119_1720'), + ] + run_before = [ + ('cmsplugin_filer_image', '0004_auto_20160120_0950'), + ] + + operations = [ + migrations.RemoveField( + model_name='post', + name='main_image_full' + ), + migrations.RemoveField( + model_name='post', + name='main_image_thumbnail', + ), + migrations.RenameField( + model_name='post', + old_name='main_image_full_new', + new_name='main_image_full', + ), + migrations.RenameField( + model_name='post', + old_name='main_image_thumbnail_new', + new_name='main_image_thumbnail', + ) + ] + else: + dependencies = [ + ('filer', '__first__'), + ('cmsplugin_filer_image', '__first__'), + ('djangocms_blog', '0019_thumbnail_move3'), + ] + + operations = [] From a40044d5333f807eec9c88a5726f9c2385bbc379 Mon Sep 17 00:00:00 2001 From: Iacopo Spalletti Date: Sat, 25 Jun 2016 17:32:45 +0200 Subject: [PATCH 2/2] Add note wrt cmsplugin-filer migration --- README.rst | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/README.rst b/README.rst index f6da42c..48d74ef 100644 --- a/README.rst +++ b/README.rst @@ -58,6 +58,36 @@ Supported django CMS versions: Some plugins have a broken tag management prior to 0.6, in case you have issues with tags, upgrade to latest version to have it fixed. +Upgrading cmsplugin-filer from 1.0 to 1.1 +----------------------------------------- + +Due to changes in cmsplugin-filer/filer which moved ``ThumbnailOption`` model from the +former to the latter, ``djangocms-blog`` must be migrated as well. + +Migrating cmsplugin-filer to 1.1 and djangocms-blog up to 0.8.4 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +If you have djangocms-blog up to 0.8.4 (included) installed or you are upgrading from a previous +djangocms-blog version together with cmsplugin-filer upgrade, you can just apply the migrations:: + + pip install cmsplugin-filer==1.1.1 django-filer==1.2.2 djangocms-blog==0.8.4 + python manage.py migrate + +Migrating cmsplugin-filer to 1.1 and djangocms-blog 0.8.5+ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +If you already a djangocms-blog 0.8.5+ or above, you have to de-apply some blog migrations when +doing the upgrade:: + + python manage.py migrate djangocms_blog 0017 ## reverse for these migration is a noop + pip install cmsplugin-filer==1.1.1 django-filer==1.2.2 + python manage.py migrate + +.. note:: de-apply migration **before** upgrading cmsplugin-filer. If running before upgrade, the + backward migration won't alter anything on the database, and it will just allow the code + to migrate ``ThumbnailOption`` from cmsplugin-filer to filer + + Features --------