Skip to content

Commit

Permalink
Merge pull request #1913 from certego/fix_users_migration_typo
Browse files Browse the repository at this point in the history
fixed wrong migration management
  • Loading branch information
doomedraven authored Jan 9, 2024
2 parents e198012 + c51ea3d commit 7df17b8
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions web/users/migrations/0003_rename_field_subscription.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from django.db import connection, migrations


def migrate(apps, schema_editor):
with schema_editor.connection.cursor() as cursor:
if connection.vendor == "postgresql":
cursor.execute("SELECT column_name FROM information_schema.columns WHERE table_name = 'users_userprofile';")
elif connection.vendor == "sqlite":
cursor.execute("SELECT sql FROM sqlite_master WHERE tbl_name = 'users_userprofile' AND type = 'table';")
columns = [el[0] for el in cursor.fetchall()]
if "suscription" in columns:
cursor.execute("ALTER TABLE users_userprofile RENAME COLUMN suscription TO subscription;")


def reverse_migrate(apps, schema_editor):
with schema_editor.connection.cursor() as cursor:
if connection.vendor == "postgresql":
cursor.execute("SELECT column_name FROM information_schema.columns WHERE table_name = 'users_userprofile';")
elif connection.vendor == "sqlite":
cursor.execute("SELECT sql FROM sqlite_master WHERE tbl_name = 'users_userprofile' AND type = 'table';")
columns = [el[0] for el in cursor.fetchall()]
if "subscription" in columns:
cursor.execute("ALTER TABLE users_userprofile RENAME COLUMN subscription TO suscription;")


class Migration(migrations.Migration):

dependencies = [
("users", "0002_reports"),
]

operations = [migrations.RunPython(migrate, reverse_migrate)]

0 comments on commit 7df17b8

Please sign in to comment.