Skip to content

Commit

Permalink
Migrations: Use per role settings in PostgreSQL instead of per databa…
Browse files Browse the repository at this point in the history
…se ones

In some cases people have more schemas in the database and touching the
database settings is not allowed.

Also remove duplicate tweaking of the parameter, the old value setting
is not necessary.

Fixes #3940
  • Loading branch information
nijel committed Jul 22, 2020
1 parent 575c049 commit bbf6f11
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 14 deletions.
12 changes: 0 additions & 12 deletions weblate/memory/migrations/0007_use_trigram.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,6 @@
def create_index(apps, schema_editor):
if schema_editor.connection.vendor != "postgresql":
return
# This ensures that extensions are loaded into the session. Without that
# the next ALTER database fails unless we're running as superuser (which
# is allowed to set non existing parameters, so missing extension doesn't
# matter)
# See https://www.postgresql.org/message-id/6376.1533675236%40sss.pgh.pa.us
schema_editor.execute("SELECT show_limit()")

schema_editor.execute(
"ALTER DATABASE {} SET pg_trgm.similarity_threshold = 0.7".format(
schema_editor.connection.settings_dict["NAME"]
)
)
schema_editor.execute("DROP INDEX memory_source_fulltext")
schema_editor.execute(
"CREATE INDEX memory_source_trgm ON memory_memory USING GIN (source gin_trgm_ops)"
Expand Down
4 changes: 2 additions & 2 deletions weblate/memory/migrations/0008_adjust_similarity.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ def update_index(apps, schema_editor):
schema_editor.execute("SELECT show_limit()")

schema_editor.execute(
"ALTER DATABASE {} SET pg_trgm.similarity_threshold = 0.5".format(
schema_editor.connection.settings_dict["NAME"]
"ALTER ROLE {} SET pg_trgm.similarity_threshold = 0.5".format(
schema_editor.connection.settings_dict["USER"]
)
)

Expand Down

0 comments on commit bbf6f11

Please sign in to comment.