Skip to content

Commit

Permalink
Allow migration to run on non-postgres databases
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandgeider committed Sep 16, 2024
1 parent bd3d939 commit 33971f0
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions wger/nutrition/migrations/0025_create_publication.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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),
]

0 comments on commit 33971f0

Please sign in to comment.