Make the djangocms_blog column rename conditional

Databases created from scratch already have customuser_id, so the
unconditional rename failed on them.
This commit is contained in:
sajeyks 2026-09-30 14:54:38 +03:00
commit 7fdd70022b

View file

@ -1,5 +1,23 @@
from django.db import migrations
# Only rename when the old column exists: databases created from scratch
# already have customuser_id (djangocms_blog is created after AUTH_USER_MODEL
# is set), so an unconditional rename fails there.
RENAME_IF_NEEDED = """
DO $$
BEGIN
IF EXISTS (
SELECT 1 FROM information_schema.columns
WHERE table_name = 'djangocms_blog_authorentriesplugin_authors'
AND column_name = 'user_id'
) THEN
ALTER TABLE djangocms_blog_authorentriesplugin_authors
RENAME COLUMN user_id TO customuser_id;
END IF;
END
$$;
"""
class Migration(migrations.Migration):
dependencies = [('membership', '0007_auto_20180213_0128'),
@ -7,7 +25,5 @@ class Migration(migrations.Migration):
]
operations = [
migrations.RunSQL(
"ALTER TABLE djangocms_blog_authorentriesplugin_authors "
"RENAME COLUMN user_id TO customuser_id;"),
migrations.RunSQL(RENAME_IF_NEEDED),
]