Skip to content

Commit

Permalink
Data migration to replace KUVA areasearch lessor with NUP
Browse files Browse the repository at this point in the history
  • Loading branch information
juho-kettunen-nc committed Dec 17, 2024
1 parent 133cd32 commit eb8e7bc
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions plotsearch/migrations/0039_replace_kuva_lessor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Generated by Django 4.2.16 on 2024-12-17 08:11

from django.db import migrations


def replace_kuva_lessor(apps, schema_editor):
"""
Replace the lessor field value for plotsearch_areasearch rows where
KUVA was used.
KUVA is not needed as a standalone service unit, because it is represented by
its three sub-units NUP, LIPA, and UPA.
NUP is used as a replacement because at the moment all the areasearch rows
are for testing. Production environment table does not have any rows.
"""
# Get the database connection
connection = schema_editor.connection

# Execute raw SQL to update the field
with connection.cursor() as cursor:
cursor.execute(
"""UPDATE plotsearch_areasearch SET lessor = %s WHERE lessor = %s""",
["NUP", "KUVA"],
)


class Migration(migrations.Migration):

dependencies = [
("plotsearch", "0038_alter_favourite_user"),
]
operations = [
migrations.RunPython(replace_kuva_lessor),
]

0 comments on commit eb8e7bc

Please sign in to comment.