-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: drop processed column if it exists
- Loading branch information
1 parent
9d0ebcf
commit 4063fd4
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
apps/event_hub/migrations/0008_remove_processed_if_exists.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
] |