From 079c66625e2027081d29260ee9c55fb970f64ce6 Mon Sep 17 00:00:00 2001 From: Eliot Berriot Date: Tue, 22 Jan 2019 09:58:35 +0100 Subject: [PATCH] Fix #663: Do not try to create unaccent extension if it's already present --- .../common/migrations/0001_initial.py | 14 +++++++++++++- changes/changelog.d/663.bugfix | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 changes/changelog.d/663.bugfix diff --git a/api/funkwhale_api/common/migrations/0001_initial.py b/api/funkwhale_api/common/migrations/0001_initial.py index a362855b8..2460f74ba 100644 --- a/api/funkwhale_api/common/migrations/0001_initial.py +++ b/api/funkwhale_api/common/migrations/0001_initial.py @@ -3,8 +3,20 @@ from django.db import migrations from django.contrib.postgres.operations import UnaccentExtension +class CustomUnaccentExtension(UnaccentExtension): + def database_forwards(self, app_label, schema_editor, from_state, to_state): + check_sql = "SELECT 1 FROM pg_extension WHERE extname = 'unaccent'" + with schema_editor.connection.cursor() as cursor: + cursor.execute(check_sql) + result = cursor.fetchall() + + if result: + return + return super().database_forwards(app_label, schema_editor, from_state, to_state) + + class Migration(migrations.Migration): dependencies = [] - operations = [UnaccentExtension()] + operations = [CustomUnaccentExtension()] diff --git a/changes/changelog.d/663.bugfix b/changes/changelog.d/663.bugfix new file mode 100644 index 000000000..fb88800b8 --- /dev/null +++ b/changes/changelog.d/663.bugfix @@ -0,0 +1 @@ +Do not try to create unaccent extension if it's already present (#663)