-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Data migration to replace KUVA areasearch lessor with NUP
- Loading branch information
1 parent
133cd32
commit eb8e7bc
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
] |