From 33971f05b7f9ae156351d9dd01e1b59ace1b36e6 Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Mon, 16 Sep 2024 10:21:36 +0200 Subject: [PATCH] Allow migration to run on non-postgres databases --- .../migrations/0025_create_publication.py | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/wger/nutrition/migrations/0025_create_publication.py b/wger/nutrition/migrations/0025_create_publication.py index 3d61b69fb..4f7ff849d 100644 --- a/wger/nutrition/migrations/0025_create_publication.py +++ b/wger/nutrition/migrations/0025_create_publication.py @@ -1,13 +1,11 @@ from django.db import migrations +from wger.utils.db import is_postgres_db -class Migration(migrations.Migration): - dependencies = [ - ('nutrition', '0024_remove_ingredient_status'), - ] - operations = [ - migrations.RunSQL( +def add_publication(apps, schema_editor): + if is_postgres_db(): + schema_editor.execute( """ DO $$ BEGIN @@ -17,9 +15,20 @@ class Migration(migrations.Migration): CREATE PUBLICATION powersync FOR ALL TABLES; END IF; END $$; - """, - reverse_sql=""" - DROP PUBLICATION IF EXISTS powersync; - """, - ), + """ + ) + + +def remove_publication(apps, schema_editor): + if is_postgres_db(): + schema_editor.execute('DROP PUBLICATION IF EXISTS powersync;') + + +class Migration(migrations.Migration): + dependencies = [ + ('nutrition', '0024_remove_ingredient_status'), + ] + + operations = [ + migrations.RunPython(add_publication, reverse_code=remove_publication), ]