diff options
Diffstat (limited to 'archaeological_finds/migrations')
5 files changed, 255 insertions, 36 deletions
diff --git a/archaeological_finds/migrations/0138_donor_to_donors.py b/archaeological_finds/migrations/0138_donor_to_donors.py deleted file mode 100644 index 24ecf65d1..000000000 --- a/archaeological_finds/migrations/0138_donor_to_donors.py +++ /dev/null @@ -1,36 +0,0 @@ -# Generated by Django 2.2.24 on 2025-08-25 10:14 - -from django.db import migrations, models - - -SQL_MIGRATE = """ -INSERT INTO archaeological_finds_find_museum_donors - (find_id, biographicalnote_id) - SELECT id, museum_donor_id FROM archaeological_finds_find - WHERE museum_donor_id IS NOT NULL; -""" - - -class Migration(migrations.Migration): - - dependencies = [ - ('ishtar_common', '0263_media_exporter'), - ('archaeological_finds', '0137_data_migration_treatment_status_inputstatus'), - ] - - operations = [ - migrations.AddField( - model_name='find', - name='museum_donors', - field=models.ManyToManyField(blank=True, related_name='finds_donors', to='ishtar_common.BiographicalNote', verbose_name='Donors, testators or vendors'), - ), - migrations.RunSQL(SQL_MIGRATE), - migrations.RemoveField( - model_name='find', - name='museum_donor', - ), - migrations.RemoveField( - model_name='historicalfind', - name='museum_donor', - ), - ] diff --git a/archaeological_finds/migrations/0138_donors_owner_ownership_status_collections.py b/archaeological_finds/migrations/0138_donors_owner_ownership_status_collections.py new file mode 100644 index 000000000..edb476ebc --- /dev/null +++ b/archaeological_finds/migrations/0138_donors_owner_ownership_status_collections.py @@ -0,0 +1,123 @@ +# Generated by Django 2.2.24 on 2025-08-25 10:14 + +import ishtar_common.models_common +import django.core.validators +from django.db import migrations, models +import re + + +SQL_MIGRATE_1 = """ +INSERT INTO archaeological_finds_find_museum_donors + (find_id, biographicalnote_id) + SELECT id, museum_donor_id FROM archaeological_finds_find + WHERE museum_donor_id IS NOT NULL; +""" +SQL_MIGRATE_2 = """ +INSERT INTO archaeological_finds_find_museum_collections + (find_id, museumcollection_id) + SELECT id, museum_collection_id FROM archaeological_finds_find + WHERE museum_collection_id IS NOT NULL; +""" + + +class Migration(migrations.Migration): + + dependencies = [ + ('ishtar_common', '0263_media_exporter'), + ('archaeological_finds', '0137_data_migration_treatment_status_inputstatus'), + ] + + operations = [ + migrations.AddField( + model_name='find', + name='museum_donors', + field=models.ManyToManyField(blank=True, related_name='finds_donors', to='ishtar_common.BiographicalNote', verbose_name='Donors, testators or vendors'), + ), + migrations.RunSQL(SQL_MIGRATE_1), + migrations.RemoveField( + model_name='find', + name='museum_donor', + ), + migrations.RemoveField( + model_name='historicalfind', + name='museum_donor', + ), + migrations.CreateModel( + name='OwnerType', + 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, default='', verbose_name='Comment')), + ('available', models.BooleanField(default=True, verbose_name='Available')), + ('order', models.IntegerField(default=10, verbose_name='Order')), + ('parent', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='archaeological_finds.OwnerType', verbose_name='Parent')), + ], + options={ + 'verbose_name': 'Ownership type', + 'verbose_name_plural': 'Owner types', + 'ordering': ('order', 'parent__label', 'label'), + }, + bases=(ishtar_common.models_common.Cached, models.Model), + ), + migrations.CreateModel( + name='OwnershipStatus', + 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, default='', verbose_name='Comment')), + ('available', models.BooleanField(default=True, verbose_name='Available')), + ('order', models.IntegerField(default=10, verbose_name='Order')), + ('parent', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='archaeological_finds.OwnershipStatus', verbose_name='Parent')), + ], + options={ + 'verbose_name': 'Ownership status', + 'verbose_name_plural': 'Ownership status', + 'ordering': ('order', 'parent__label', 'label'), + }, + bases=(ishtar_common.models_common.Cached, models.Model), + ), + migrations.AddField( + model_name='find', + name='owner', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='archaeological_finds.OwnerType', verbose_name='Owner'), + ), + migrations.AddField( + model_name='find', + name='ownership_status', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='archaeological_finds.OwnershipStatus', verbose_name='Ownership status'), + ), + migrations.AddField( + model_name='historicalfind', + name='owner', + field=models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='archaeological_finds.OwnerType', verbose_name='Owner'), + ), + migrations.AddField( + model_name='historicalfind', + name='ownership_status', + field=models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='archaeological_finds.OwnershipStatus', verbose_name='Ownership status'), + ), + migrations.AddField( + model_name='find', + name='museum_collections', + field=models.ManyToManyField(blank=True, to='archaeological_finds.MuseumCollection', verbose_name='Collections'), + ), + migrations.RunSQL(SQL_MIGRATE_2), + migrations.RemoveField( + model_name='find', + name='museum_collection', + ), + migrations.RemoveField( + model_name='historicalfind', + name='museum_collection', + ), + migrations.RemoveField( + model_name='find', + name='collection', + ), + migrations.RemoveField( + model_name='historicalfind', + name='collection', + ), + ] diff --git a/archaeological_finds/migrations/0139_data_migration_owner_ownership.py b/archaeological_finds/migrations/0139_data_migration_owner_ownership.py new file mode 100644 index 000000000..9ce23e697 --- /dev/null +++ b/archaeological_finds/migrations/0139_data_migration_owner_ownership.py @@ -0,0 +1,29 @@ +import os + +from django.db import migrations +from django.core.management import call_command + + +def load_data(apps, __): + OwnershipStatus = apps.get_model("archaeological_finds", "ownershipstatus") + if not OwnershipStatus.objects.count(): + migration = "0139_data_migration_ownership_status.json" + json_path = os.sep.join(os.path.abspath(__file__).split(os.sep)[:-1] + [migration]) + call_command("loaddata", json_path) + + OwnerType = apps.get_model("archaeological_finds", "ownertype") + if not OwnerType.objects.count(): + migration = "0139_data_migration_owner_type.json" + json_path = os.sep.join(os.path.abspath(__file__).split(os.sep)[:-1] + [migration]) + call_command("loaddata", json_path) + + +class Migration(migrations.Migration): + + dependencies = [ + ('archaeological_finds', '0138_donors_owner_ownership_status_collections'), + ] + + operations = [ + migrations.RunPython(load_data) + ] diff --git a/archaeological_finds/migrations/0139_data_migration_owner_type.json b/archaeological_finds/migrations/0139_data_migration_owner_type.json new file mode 100644 index 000000000..e49241655 --- /dev/null +++ b/archaeological_finds/migrations/0139_data_migration_owner_type.json @@ -0,0 +1,35 @@ +[ + { + "model": "archaeological_finds.ownertype", + "fields": { + "label": "\u00c9tat", + "txt_idx": "etat", + "comment": "", + "available": true, + "order": 10, + "parent": null + } + }, + { + "model": "archaeological_finds.ownertype", + "fields": { + "label": "Collectivit\u00e9", + "txt_idx": "collectivite", + "comment": "", + "available": true, + "order": 20, + "parent": null + } + }, + { + "model": "archaeological_finds.ownertype", + "fields": { + "label": "Inventeur", + "txt_idx": "inventeur", + "comment": "", + "available": true, + "order": 30, + "parent": null + } + } +]
\ No newline at end of file diff --git a/archaeological_finds/migrations/0139_data_migration_ownership_status.json b/archaeological_finds/migrations/0139_data_migration_ownership_status.json new file mode 100644 index 000000000..33dc4de97 --- /dev/null +++ b/archaeological_finds/migrations/0139_data_migration_ownership_status.json @@ -0,0 +1,68 @@ +[ + { + "model": "archaeological_finds.ownershipstatus", + "fields": { + "label": "Collection patrimoniale", + "txt_idx": "collection-patrimoniale", + "comment": "", + "available": true, + "order": 10, + "parent": null + } + }, + { + "model": "archaeological_finds.ownershipstatus", + "fields": { + "label": "D\u00e9p\u00f4t", + "txt_idx": "depot", + "comment": "", + "available": true, + "order": 20, + "parent": null + } + }, + { + "model": "archaeological_finds.ownershipstatus", + "fields": { + "label": "R\u00e9gl\u00e9", + "txt_idx": "regle", + "comment": "", + "available": true, + "order": 30, + "parent": null + } + }, + { + "model": "archaeological_finds.ownershipstatus", + "fields": { + "label": "Non r\u00e9gl\u00e9", + "txt_idx": "non-regle", + "comment": "", + "available": true, + "order": 40, + "parent": null + } + }, + { + "model": "archaeological_finds.ownershipstatus", + "fields": { + "label": "En cours", + "txt_idx": "en-cours", + "comment": "", + "available": true, + "order": 50, + "parent": null + } + }, + { + "model": "archaeological_finds.ownershipstatus", + "fields": { + "label": "Probl\u00e9matique", + "txt_idx": "problematique", + "comment": "", + "available": true, + "order": 60, + "parent": null + } + } +]
\ No newline at end of file |