prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Install.py script assumes database to exist
  ## Description
  The install.py script has a hard check on the hostname to check if we're using the docker created postgres container and only creates the databases if we do.
  
  `if DATABASES[database_key]["HOST"] == "db":`
  
  In https://github.com/centerofci/mathesar/pull/747, we gave our containers persistent names. The db container's name was set as `mathesar_db`.
  
  This leads to all fresh setup of mathesar to fail.
  
  ## Expected behavior
  Following the instructions in readme should work without any error.
  
  ## To Reproduce
  <!-- How can we recreate this bug? Please try to provide a Minimal, Complete, and Verifiable (http://stackoverflow.com/help/mcve) example if code-related. -->
  * Stop mathesar, if you have it running
  * Remove your database
  * Start mathesar and run migrations and install.py script 
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `install.py`
  Content:
  ```
  1 """
  2 This script installs functions and types for Mathesar onto the configured DB.
  3 """
  4 from config.settings import DATABASES
  5 from db import install
  6 import sys
  7 import getopt
  8 
  9 
  10 def main():
  11     skip_confirm = False
  12     (opts, _) = getopt.getopt(sys.argv[1:], ":s", ["skip-confirm"])
  13     for (opt, value) in opts:
  14         if (opt == "-s") or (opt == "--skip-confirm"):
  15             skip_confirm = True
  16     for database_key in [key for key in DATABASES if key != "default"]:
  17         install_on_db_with_key(database_key, skip_confirm)
  18 
  19 
  20 def install_on_db_with_key(database_key, skip_confirm):
  21     if DATABASES[database_key]["HOST"] == "db":
  22         # if we're going to install on the docker-created Postgres, we'll
  23         # create the DB
  24         print("Creating Mathesar DB on docker-created PostgreSQL instance")
  25         install.create_mathesar_database(
  26             DATABASES[database_key]["NAME"],
  27             DATABASES["default"]["USER"],
  28             DATABASES["default"]["PASSWORD"],
  29             DATABASES["default"]["HOST"],
  30             DATABASES["default"]["NAME"],
  31             DATABASES["default"]["PORT"],
  32         )
  33         print(f"Created DB is {DATABASES['mathesar_tables']['NAME']}")
  34     else:
  35         # if we're installing anywhere else, we require the DB to exist in
  36         # advance.
  37         username = DATABASES[database_key]["USER"]
  38         password = DATABASES[database_key]["PASSWORD"]
  39         host = DATABASES[database_key]["HOST"]
  40         db_name = DATABASES[database_key]["NAME"]
  41         port = DATABASES[database_key]["PORT"]
  42         print("Installing Mathesar DB on preexisting PostgreSQL instance...")
  43         if skip_confirm is False:
  44             confirmation = input(
  45                 f"Mathesar will be installed on DB {db_name} at host {host}."
  46                 "Confirm? (y/n) >  "
  47             )
  48             if (confirmation.lower() in ["y", "yes"]) or (skip_confirm is True):
  49                 print("Installing...")
  50                 install.install_mathesar_on_preexisting_database(
  51                     username,
  52                     password,
  53                     host,
  54                     db_name,
  55                     port,
  56                 )
  57             else:
  58                 print("Skipping DB with key {database_key}.")
  59 
  60 
  61 if __name__ == "__main__":
  62     main()
  63
  ```
  --- 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/install.py b/install.py
  --- a/install.py
  +++ b/install.py
  @@ -18,7 +18,7 @@
   
   
   def install_on_db_with_key(database_key, skip_confirm):
  -    if DATABASES[database_key]["HOST"] == "db":
  +    if DATABASES[database_key]["HOST"] == "mathesar_db":
           # if we're going to install on the docker-created Postgres, we'll
           # create the DB
           print("Creating Mathesar DB on docker-created PostgreSQL instance")
  
verification_info: {"golden_diff": "diff --git a/install.py b/install.py\n--- a/install.py\n+++ b/install.py\n@@ -18,7 +18,7 @@\n \n \n def install_on_db_with_key(database_key, skip_confirm):\n-    if DATABASES[database_key][\"HOST\"] == \"db\":\n+    if DATABASES[database_key][\"HOST\"] == \"mathesar_db\":\n         # if we're going to install on the docker-created Postgres, we'll\n         # create the DB\n         print(\"Creating Mathesar DB on docker-created PostgreSQL instance\")\n", "issue": "Install.py script assumes database to exist\n## Description\r\nThe install.py script has a hard check on the hostname to check if we're using the docker created postgres container and only creates the databases if we do.\r\n\r\n`if DATABASES[database_key][\"HOST\"] == \"db\":`\r\n\r\nIn https://github.com/centerofci/mathesar/pull/747, we gave our containers persistent names. The db container's name was set as `mathesar_db`.\r\n\r\nThis leads to all fresh setup of mathesar to fail.\r\n\r\n## Expected behavior\r\nFollowing the instructions in readme should work without any error.\r\n\r\n## To Reproduce\r\n<!-- How can we recreate this bug? Please try to provide a Minimal, Complete, and Verifiable (http://stackoverflow.com/help/mcve) example if code-related. -->\r\n* Stop mathesar, if you have it running\r\n* Remove your database\r\n* Start mathesar and run migrations and install.py script \n", "before_files": [{"content": "\"\"\"\nThis script installs functions and types for Mathesar onto the configured DB.\n\"\"\"\nfrom config.settings import DATABASES\nfrom db import install\nimport sys\nimport getopt\n\n\ndef main():\n    skip_confirm = False\n    (opts, _) = getopt.getopt(sys.argv[1:], \":s\", [\"skip-confirm\"])\n    for (opt, value) in opts:\n        if (opt == \"-s\") or (opt == \"--skip-confirm\"):\n            skip_confirm = True\n    for database_key in [key for key in DATABASES if key != \"default\"]:\n        install_on_db_with_key(database_key, skip_confirm)\n\n\ndef install_on_db_with_key(database_key, skip_confirm):\n    if DATABASES[database_key][\"HOST\"] == \"db\":\n        # if we're going to install on the docker-created Postgres, we'll\n        # create the DB\n        print(\"Creating Mathesar DB on docker-created PostgreSQL instance\")\n        install.create_mathesar_database(\n            DATABASES[database_key][\"NAME\"],\n            DATABASES[\"default\"][\"USER\"],\n            DATABASES[\"default\"][\"PASSWORD\"],\n            DATABASES[\"default\"][\"HOST\"],\n            DATABASES[\"default\"][\"NAME\"],\n            DATABASES[\"default\"][\"PORT\"],\n        )\n        print(f\"Created DB is {DATABASES['mathesar_tables']['NAME']}\")\n    else:\n        # if we're installing anywhere else, we require the DB to exist in\n        # advance.\n        username = DATABASES[database_key][\"USER\"]\n        password = DATABASES[database_key][\"PASSWORD\"]\n        host = DATABASES[database_key][\"HOST\"]\n        db_name = DATABASES[database_key][\"NAME\"]\n        port = DATABASES[database_key][\"PORT\"]\n        print(\"Installing Mathesar DB on preexisting PostgreSQL instance...\")\n        if skip_confirm is False:\n            confirmation = input(\n                f\"Mathesar will be installed on DB {db_name} at host {host}.\"\n                \"Confirm? (y/n) >  \"\n            )\n            if (confirmation.lower() in [\"y\", \"yes\"]) or (skip_confirm is True):\n                print(\"Installing...\")\n                install.install_mathesar_on_preexisting_database(\n                    username,\n                    password,\n                    host,\n                    db_name,\n                    port,\n                )\n            else:\n                print(\"Skipping DB with key {database_key}.\")\n\n\nif __name__ == \"__main__\":\n    main()\n", "path": "install.py"}], "after_files": [{"content": "\"\"\"\nThis script installs functions and types for Mathesar onto the configured DB.\n\"\"\"\nfrom config.settings import DATABASES\nfrom db import install\nimport sys\nimport getopt\n\n\ndef main():\n    skip_confirm = False\n    (opts, _) = getopt.getopt(sys.argv[1:], \":s\", [\"skip-confirm\"])\n    for (opt, value) in opts:\n        if (opt == \"-s\") or (opt == \"--skip-confirm\"):\n            skip_confirm = True\n    for database_key in [key for key in DATABASES if key != \"default\"]:\n        install_on_db_with_key(database_key, skip_confirm)\n\n\ndef install_on_db_with_key(database_key, skip_confirm):\n    if DATABASES[database_key][\"HOST\"] == \"mathesar_db\":\n        # if we're going to install on the docker-created Postgres, we'll\n        # create the DB\n        print(\"Creating Mathesar DB on docker-created PostgreSQL instance\")\n        install.create_mathesar_database(\n            DATABASES[database_key][\"NAME\"],\n            DATABASES[\"default\"][\"USER\"],\n            DATABASES[\"default\"][\"PASSWORD\"],\n            DATABASES[\"default\"][\"HOST\"],\n            DATABASES[\"default\"][\"NAME\"],\n            DATABASES[\"default\"][\"PORT\"],\n        )\n        print(f\"Created DB is {DATABASES['mathesar_tables']['NAME']}\")\n    else:\n        # if we're installing anywhere else, we require the DB to exist in\n        # advance.\n        username = DATABASES[database_key][\"USER\"]\n        password = DATABASES[database_key][\"PASSWORD\"]\n        host = DATABASES[database_key][\"HOST\"]\n        db_name = DATABASES[database_key][\"NAME\"]\n        port = DATABASES[database_key][\"PORT\"]\n        print(\"Installing Mathesar DB on preexisting PostgreSQL instance...\")\n        if skip_confirm is False:\n            confirmation = input(\n                f\"Mathesar will be installed on DB {db_name} at host {host}.\"\n                \"Confirm? (y/n) >  \"\n            )\n            if (confirmation.lower() in [\"y\", \"yes\"]) or (skip_confirm is True):\n                print(\"Installing...\")\n                install.install_mathesar_on_preexisting_database(\n                    username,\n                    password,\n                    host,\n                    db_name,\n                    port,\n                )\n            else:\n                print(\"Skipping DB with key {database_key}.\")\n\n\nif __name__ == \"__main__\":\n    main()\n", "path": "install.py"}]}