Skip to content

Commit

Permalink
fix: drop processed column if it exists
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianmcphee committed Nov 26, 2024
1 parent 9d0ebcf commit 4063fd4
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions apps/event_hub/migrations/0008_remove_processed_if_exists.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from django.db import migrations

def remove_processed_if_exists(apps, schema_editor):
# Get the database connection
connection = schema_editor.connection

with connection.cursor() as cursor:
# Check if processed column exists
cursor.execute("""
SELECT column_name
FROM information_schema.columns
WHERE table_name = 'event_hub_eventlog'
AND column_name = 'processed';
""")

if cursor.fetchone():
# Column exists, so drop it
cursor.execute(
"ALTER TABLE event_hub_eventlog DROP COLUMN processed"
)

class Migration(migrations.Migration):
dependencies = [
('event_hub', '0007_alter_delete_at_nullable'),
]

operations = [
migrations.RunPython(remove_processed_if_exists, migrations.RunPython.noop),
]

0 comments on commit 4063fd4

Please sign in to comment.