Add checkout i18n DB columns for basket/checkout stability
This commit is contained in:
56
mandelstudio/migrations/0005_checkout_i18n_columns.py
Normal file
56
mandelstudio/migrations/0005_checkout_i18n_columns.py
Normal 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,
|
||||||
|
)
|
||||||
|
]
|
||||||
Reference in New Issue
Block a user