From caa69d6e6e85f5d047da3d80865af27437253e23 Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Sat, 2 Oct 2021 02:39:06 +0200 Subject: [PATCH] Added temporary datamigrations for photoalbum -> externallink (release preparation). --- .../0008_photoalbum_linktype.py | 18 ++++++ .../0009_photoalbum_externallink_interim.py | 37 ++++++++++++ ...0_photoalbum_externallink_datamigration.py | 22 ++++++++ .../0011_remove_migrated_photoalbum_data.py | 56 +++++++++++++++++++ 4 files changed, 133 insertions(+) create mode 100644 django_lostplaces/lostplaces/migrations_release_temp/0008_photoalbum_linktype.py create mode 100644 django_lostplaces/lostplaces/migrations_release_temp/0009_photoalbum_externallink_interim.py create mode 100644 django_lostplaces/lostplaces/migrations_release_temp/0010_photoalbum_externallink_datamigration.py create mode 100644 django_lostplaces/lostplaces/migrations_release_temp/0011_remove_migrated_photoalbum_data.py diff --git a/django_lostplaces/lostplaces/migrations_release_temp/0008_photoalbum_linktype.py b/django_lostplaces/lostplaces/migrations_release_temp/0008_photoalbum_linktype.py new file mode 100644 index 0000000..0282982 --- /dev/null +++ b/django_lostplaces/lostplaces/migrations_release_temp/0008_photoalbum_linktype.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.7 on 2021-10-01 19:50 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('lostplaces', '0007_auto_20211001_1925'), + ] + + operations = [ + migrations.AddField( + model_name='photoalbum', + name='linktype', + field=models.CharField(blank=True, max_length=20, null=True, verbose_name='link type'), + ), + ] diff --git a/django_lostplaces/lostplaces/migrations_release_temp/0009_photoalbum_externallink_interim.py b/django_lostplaces/lostplaces/migrations_release_temp/0009_photoalbum_externallink_interim.py new file mode 100644 index 0000000..606dfba --- /dev/null +++ b/django_lostplaces/lostplaces/migrations_release_temp/0009_photoalbum_externallink_interim.py @@ -0,0 +1,37 @@ +# Generated by Django 3.2.7 on 2021-10-01 20:13 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('lostplaces', '0008_photoalbum_linktype'), + ] + + operations = [ + migrations.CreateModel( + name='ExternalLink', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('submitted_when', models.DateTimeField(auto_now_add=True, null=True, verbose_name='Submission date')), + ('subclass', models.IntegerField(default=-1)), + ('subclassid', models.IntegerField(default=-1)), + ('url', models.URLField(verbose_name='URL')), + ('label', models.CharField(max_length=100, verbose_name='link text')), + ('linktype', models.CharField(blank=True, max_length=20, null=True, verbose_name='link type')), + ('place', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='externallinks', to='lostplaces.place')), + ('submitted_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='externallinks', to='lostplaces.explorer', verbose_name='Submitter')), + ], + options={ + 'abstract': False, + }, + ), + migrations.AddField( + model_name='photoalbum', + name='externallink_ptr', + field=models.OneToOneField(auto_created=True, null=True, blank=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, serialize=False, to='lostplaces.externallink'), + preserve_default=False, + ), + ] diff --git a/django_lostplaces/lostplaces/migrations_release_temp/0010_photoalbum_externallink_datamigration.py b/django_lostplaces/lostplaces/migrations_release_temp/0010_photoalbum_externallink_datamigration.py new file mode 100644 index 0000000..d0a17b5 --- /dev/null +++ b/django_lostplaces/lostplaces/migrations_release_temp/0010_photoalbum_externallink_datamigration.py @@ -0,0 +1,22 @@ +# Generated by Django 3.2.7 on 2021-10-01 20:32 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('lostplaces', '0009_photoalbum_externallink_interim'), + ] + + operations = [ + # insert data from subclass into parent class with subclass 'number' and primary key/id + migrations.RunSQL("""INSERT INTO lostplaces_externallink (submitted_when, url, label, place_id, submitted_by_id, subclass, subclassid) + SELECT submitted_when, url, label, place_id, submitted_by_id, 1, id + FROM lostplaces_photoalbum;""" + + ), + # update subclass primary key to point to parent class (notice composite key values): + migrations.RunSQL("UPDATE lostplaces_photoalbum SET externallink_ptr_id=lostplaces_externallink.id FROM lostplaces_externallink WHERE lostplaces_externallink.subclassid=lostplaces_photoalbum.id AND lostplaces_externallink.subclass=1;" + ), + ] diff --git a/django_lostplaces/lostplaces/migrations_release_temp/0011_remove_migrated_photoalbum_data.py b/django_lostplaces/lostplaces/migrations_release_temp/0011_remove_migrated_photoalbum_data.py new file mode 100644 index 0000000..a76896e --- /dev/null +++ b/django_lostplaces/lostplaces/migrations_release_temp/0011_remove_migrated_photoalbum_data.py @@ -0,0 +1,56 @@ +# Generated by Django 3.2.7 on 2021-10-01 22:48 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('lostplaces', '0010_photoalbum_externallink_datamigration'), + ] + + operations = [ + migrations.RemoveField( + model_name='externallink', + name='subclass', + ), + migrations.RemoveField( + model_name='externallink', + name='subclassid', + ), + migrations.RemoveField( + model_name='photoalbum', + name='id', + ), + migrations.RemoveField( + model_name='photoalbum', + name='label', + ), + migrations.RemoveField( + model_name='photoalbum', + name='linktype', + ), + migrations.RemoveField( + model_name='photoalbum', + name='place', + ), + migrations.RemoveField( + model_name='photoalbum', + name='submitted_by', + ), + migrations.RemoveField( + model_name='photoalbum', + name='submitted_when', + ), + migrations.RemoveField( + model_name='photoalbum', + name='url', + ), + migrations.AlterField( + model_name='photoalbum', + name='externallink_ptr', + field=models.OneToOneField(auto_created=True, default=-1, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='lostplaces.externallink'), + preserve_default=False, + ), + ]