Skip to content

Commit 33971f0

Browse files
committed
Allow migration to run on non-postgres databases
1 parent bd3d939 commit 33971f0

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed
Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
from django.db import migrations
22

3+
from wger.utils.db import is_postgres_db
34

4-
class Migration(migrations.Migration):
5-
dependencies = [
6-
('nutrition', '0024_remove_ingredient_status'),
7-
]
85

9-
operations = [
10-
migrations.RunSQL(
6+
def add_publication(apps, schema_editor):
7+
if is_postgres_db():
8+
schema_editor.execute(
119
"""
1210
DO $$
1311
BEGIN
@@ -17,9 +15,20 @@ class Migration(migrations.Migration):
1715
CREATE PUBLICATION powersync FOR ALL TABLES;
1816
END IF;
1917
END $$;
20-
""",
21-
reverse_sql="""
22-
DROP PUBLICATION IF EXISTS powersync;
23-
""",
24-
),
18+
"""
19+
)
20+
21+
22+
def remove_publication(apps, schema_editor):
23+
if is_postgres_db():
24+
schema_editor.execute('DROP PUBLICATION IF EXISTS powersync;')
25+
26+
27+
class Migration(migrations.Migration):
28+
dependencies = [
29+
('nutrition', '0024_remove_ingredient_status'),
30+
]
31+
32+
operations = [
33+
migrations.RunPython(add_publication, reverse_code=remove_publication),
2534
]

0 commit comments

Comments
 (0)