Add checkout i18n DB columns for basket/checkout stability

This commit is contained in:
2026-05-23 16:32:09 +02:00
parent 90a71adb4f
commit a6a9ed2973

View File

@@ -0,0 +1,56 @@
from django.db import migrations
LANGUAGES = ("en", "de", "fr", "es", "it", "pt", "ru")
def _add_column_if_missing(schema_editor, table_name, column_name, column_sql):
connection = schema_editor.connection
with connection.cursor() as cursor:
existing = {
row.name
for row in connection.introspection.get_table_description(cursor, table_name)
}
if column_name in existing:
return
quoted_table = schema_editor.quote_name(table_name)
quoted_column = schema_editor.quote_name(column_name)
cursor.execute(
f"ALTER TABLE {quoted_table} ADD COLUMN {quoted_column} {column_sql}"
)
def add_checkout_i18n_columns(apps, schema_editor):
for lang in LANGUAGES:
_add_column_if_missing(
schema_editor,
"checkout_fixedsurcharge",
f"name_{lang}",
"varchar(32) NULL",
)
_add_column_if_missing(
schema_editor,
"checkout_percentagesurcharge",
f"name_{lang}",
"varchar(32) NULL",
)
_add_column_if_missing(
schema_editor,
"checkout_paymentmethod",
f"label_{lang}",
"varchar(32) NULL",
)
class Migration(migrations.Migration):
dependencies = [
("mandelstudio", "0004_contact_messages"),
("checkout", "0017_remove_unused_price_fields"),
]
operations = [
migrations.RunPython(
add_checkout_i18n_columns,
migrations.RunPython.noop,
)
]