forked from ungleich-public/dynamicweb
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:
parent
3c9102167d
commit
7fdd70022b
1 changed files with 19 additions and 3 deletions
|
|
@ -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),
|
||||
]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue