prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  migrations fail for database name containing "-"
  **Describe the bug**
    Applying memory.0007_use_trigram...Traceback (most recent call last):
    File "/usr/lib/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
      return self.cursor.execute(sql, params)
  psycopg2.errors.SyntaxError: syntax error at or near "-"
  LINE 1: ALTER DATABASE weblate-staging SET pg_trgm.similarity_thresh...
                                ^
  **To Reproduce**
  Set the database name to "weblate-staging"
  
  I worked around this by changing of
  ALTER DATABASE {} SET
  to
  ALTER DATABASE \"{}\" SET
  in 0007_use_trigram.py and 0008_adjust_similarity.py.
  
  weblate-4.1.1
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `weblate/memory/migrations/0008_adjust_similarity.py`
  Content:
  ```
  1 # Generated by Django 3.0.5 on 2020-05-12 11:44
  2 
  3 from django.db import migrations
  4 
  5 
  6 def update_index(apps, schema_editor):
  7     if schema_editor.connection.vendor != "postgresql":
  8         return
  9     # This ensures that extensions are loaded into the session. Without that
  10     # the next ALTER database fails unless we're running as superuser (which
  11     # is allowed to set non existing parameters, so missing extension doesn't
  12     # matter)
  13     # See https://www.postgresql.org/message-id/6376.1533675236%40sss.pgh.pa.us
  14     schema_editor.execute("SELECT show_limit()")
  15 
  16     schema_editor.execute(
  17         "ALTER ROLE {} SET pg_trgm.similarity_threshold = 0.5".format(
  18             schema_editor.connection.settings_dict["USER"]
  19         )
  20     )
  21 
  22 
  23 class Migration(migrations.Migration):
  24 
  25     dependencies = [
  26         ("memory", "0007_use_trigram"),
  27     ]
  28 
  29     operations = [
  30         migrations.RunPython(
  31             update_index, migrations.RunPython.noop, elidable=False, atomic=False
  32         )
  33     ]
  34
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/weblate/memory/migrations/0008_adjust_similarity.py b/weblate/memory/migrations/0008_adjust_similarity.py
  --- a/weblate/memory/migrations/0008_adjust_similarity.py
  +++ b/weblate/memory/migrations/0008_adjust_similarity.py
  @@ -15,7 +15,7 @@
   
       schema_editor.execute(
           "ALTER ROLE {} SET pg_trgm.similarity_threshold = 0.5".format(
  -            schema_editor.connection.settings_dict["USER"]
  +            schema_editor.quote_name(schema_editor.connection.settings_dict["USER"])
           )
       )
  
verification_info: {"golden_diff": "diff --git a/weblate/memory/migrations/0008_adjust_similarity.py b/weblate/memory/migrations/0008_adjust_similarity.py\n--- a/weblate/memory/migrations/0008_adjust_similarity.py\n+++ b/weblate/memory/migrations/0008_adjust_similarity.py\n@@ -15,7 +15,7 @@\n \n     schema_editor.execute(\n         \"ALTER ROLE {} SET pg_trgm.similarity_threshold = 0.5\".format(\n-            schema_editor.connection.settings_dict[\"USER\"]\n+            schema_editor.quote_name(schema_editor.connection.settings_dict[\"USER\"])\n         )\n     )\n", "issue": "migrations fail for database name containing \"-\"\n**Describe the bug**\r\n  Applying memory.0007_use_trigram...Traceback (most recent call last):\r\n  File \"/usr/lib/python3.6/site-packages/django/db/backends/utils.py\", line 84, in _execute\r\n    return self.cursor.execute(sql, params)\r\npsycopg2.errors.SyntaxError: syntax error at or near \"-\"\r\nLINE 1: ALTER DATABASE weblate-staging SET pg_trgm.similarity_thresh...\r\n                              ^\r\n**To Reproduce**\r\nSet the database name to \"weblate-staging\"\r\n\r\nI worked around this by changing of\r\nALTER DATABASE {} SET\r\nto\r\nALTER DATABASE \\\"{}\\\" SET\r\nin 0007_use_trigram.py and 0008_adjust_similarity.py.\r\n\r\nweblate-4.1.1\n", "before_files": [{"content": "# Generated by Django 3.0.5 on 2020-05-12 11:44\n\nfrom django.db import migrations\n\n\ndef update_index(apps, schema_editor):\n    if schema_editor.connection.vendor != \"postgresql\":\n        return\n    # This ensures that extensions are loaded into the session. Without that\n    # the next ALTER database fails unless we're running as superuser (which\n    # is allowed to set non existing parameters, so missing extension doesn't\n    # matter)\n    # See https://www.postgresql.org/message-id/6376.1533675236%40sss.pgh.pa.us\n    schema_editor.execute(\"SELECT show_limit()\")\n\n    schema_editor.execute(\n        \"ALTER ROLE {} SET pg_trgm.similarity_threshold = 0.5\".format(\n            schema_editor.connection.settings_dict[\"USER\"]\n        )\n    )\n\n\nclass Migration(migrations.Migration):\n\n    dependencies = [\n        (\"memory\", \"0007_use_trigram\"),\n    ]\n\n    operations = [\n        migrations.RunPython(\n            update_index, migrations.RunPython.noop, elidable=False, atomic=False\n        )\n    ]\n", "path": "weblate/memory/migrations/0008_adjust_similarity.py"}], "after_files": [{"content": "# Generated by Django 3.0.5 on 2020-05-12 11:44\n\nfrom django.db import migrations\n\n\ndef update_index(apps, schema_editor):\n    if schema_editor.connection.vendor != \"postgresql\":\n        return\n    # This ensures that extensions are loaded into the session. Without that\n    # the next ALTER database fails unless we're running as superuser (which\n    # is allowed to set non existing parameters, so missing extension doesn't\n    # matter)\n    # See https://www.postgresql.org/message-id/6376.1533675236%40sss.pgh.pa.us\n    schema_editor.execute(\"SELECT show_limit()\")\n\n    schema_editor.execute(\n        \"ALTER ROLE {} SET pg_trgm.similarity_threshold = 0.5\".format(\n            schema_editor.quote_name(schema_editor.connection.settings_dict[\"USER\"])\n        )\n    )\n\n\nclass Migration(migrations.Migration):\n\n    dependencies = [\n        (\"memory\", \"0007_use_trigram\"),\n    ]\n\n    operations = [\n        migrations.RunPython(\n            update_index, migrations.RunPython.noop, elidable=False, atomic=False\n        )\n    ]\n", "path": "weblate/memory/migrations/0008_adjust_similarity.py"}]}