prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  The requirement of superuser postgresql access is problematic
  ## Problem
  Mathesar needs a Postgres superuser to function correctly, from the docs at https://docs.mathesar.org/installation/build-from-source/ 
  
  ## Proposed solution
  The mathesar user should not require superuser access. 
  
  ## Additional context
  The superuser is a global permission meaning that a user that has superuser permission will be able to access (and do stuff) not on the mathesar but *all* the databases of the RDBMS. Considering that many production systems have a single RDBMS hosting many application this is a major problem since the mathsar user won't have any access boundaries on the same RDBMS. The mathesar user access can be unlimited but *must* be bounded without the mathesar database.
  
  </issue>
  <code>
  [start of db/install.py]
  1 from sqlalchemy import text
  2 from sqlalchemy.exc import OperationalError
  3 
  4 from db import engine
  5 from db.sql import install as sql_install
  6 from db.types import install as types_install
  7 
  8 
  9 def install_mathesar(
  10         database_name, username, password, hostname, port, skip_confirm
  11 ):
  12     """Create database and install Mathesar on it."""
  13     user_db_engine = engine.create_future_engine(
  14         username, password, hostname, database_name, port,
  15         connect_args={"connect_timeout": 10}
  16     )
  17     try:
  18         user_db_engine.connect()
  19         print(f"Installing Mathesar on preexisting PostgreSQL database {database_name} at host {hostname}...")
  20         sql_install.install(user_db_engine)
  21         types_install.install_mathesar_on_database(user_db_engine)
  22         user_db_engine.dispose()
  23     except OperationalError:
  24         database_created = _create_database(
  25             database_name=database_name,
  26             hostname=hostname,
  27             username=username,
  28             password=password,
  29             port=port,
  30             skip_confirm=skip_confirm
  31         )
  32         if database_created:
  33             print(f"Installing Mathesar on PostgreSQL database {database_name} at host {hostname}...")
  34             sql_install.install(user_db_engine)
  35             types_install.install_mathesar_on_database(user_db_engine)
  36             user_db_engine.dispose()
  37         else:
  38             print(f"Skipping installing on DB with key {database_name}.")
  39 
  40 
  41 def _create_database(database_name, hostname, username, password, port, skip_confirm=True):
  42     if skip_confirm is True:
  43         create_database = "y"
  44     else:
  45         create_database = input(
  46             f"Create a new Database called {database_name}? (y/n) > "
  47         )
  48     if create_database.lower() in ["y", "yes"]:
  49         # We need to connect to an existing database inorder to create a new Database.
  50         # So we use the default Database `postgres` that comes with postgres.
  51         # TODO Throw correct error when the default postgres database does not exists(which is very rare but still possible)
  52         root_database = "postgres"
  53         root_db_engine = engine.create_future_engine(
  54             username, password, hostname, root_database, port,
  55             connect_args={"connect_timeout": 10}
  56         )
  57         with root_db_engine.connect() as conn:
  58             conn.execution_options(isolation_level="AUTOCOMMIT")
  59             conn.execute(text(f'CREATE DATABASE "{database_name}"'))
  60         root_db_engine.dispose()
  61         print(f"Created DB is {database_name}.")
  62         return True
  63     else:
  64         print(f"Database {database_name} not created!")
  65         return False
  66
  [end of db/install.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/db/install.py b/db/install.py
  --- a/db/install.py
  +++ b/db/install.py
  @@ -1,5 +1,6 @@
  +from psycopg.errors import InsufficientPrivilege
   from sqlalchemy import text
  -from sqlalchemy.exc import OperationalError
  +from sqlalchemy.exc import OperationalError, ProgrammingError
   
   from db import engine
   from db.sql import install as sql_install
  @@ -54,12 +55,20 @@
               username, password, hostname, root_database, port,
               connect_args={"connect_timeout": 10}
           )
  -        with root_db_engine.connect() as conn:
  -            conn.execution_options(isolation_level="AUTOCOMMIT")
  -            conn.execute(text(f'CREATE DATABASE "{database_name}"'))
  -        root_db_engine.dispose()
  -        print(f"Created DB is {database_name}.")
  -        return True
  +        try:
  +            with root_db_engine.connect() as conn:
  +                conn.execution_options(isolation_level="AUTOCOMMIT")
  +                conn.execute(text(f'CREATE DATABASE "{database_name}"'))
  +            root_db_engine.dispose()
  +            print(f"Created DB is {database_name}.")
  +            return True
  +        except ProgrammingError as e:
  +            if isinstance(e.orig, InsufficientPrivilege):
  +                print(f"Database {database_name} could not be created due to Insufficient Privilege")
  +                return False
  +        except Exception:
  +            print(f"Database {database_name} could not be created!")
  +            return False
       else:
           print(f"Database {database_name} not created!")
           return False
  
verification_info: {"golden_diff": "diff --git a/db/install.py b/db/install.py\n--- a/db/install.py\n+++ b/db/install.py\n@@ -1,5 +1,6 @@\n+from psycopg.errors import InsufficientPrivilege\n from sqlalchemy import text\n-from sqlalchemy.exc import OperationalError\n+from sqlalchemy.exc import OperationalError, ProgrammingError\n \n from db import engine\n from db.sql import install as sql_install\n@@ -54,12 +55,20 @@\n             username, password, hostname, root_database, port,\n             connect_args={\"connect_timeout\": 10}\n         )\n-        with root_db_engine.connect() as conn:\n-            conn.execution_options(isolation_level=\"AUTOCOMMIT\")\n-            conn.execute(text(f'CREATE DATABASE \"{database_name}\"'))\n-        root_db_engine.dispose()\n-        print(f\"Created DB is {database_name}.\")\n-        return True\n+        try:\n+            with root_db_engine.connect() as conn:\n+                conn.execution_options(isolation_level=\"AUTOCOMMIT\")\n+                conn.execute(text(f'CREATE DATABASE \"{database_name}\"'))\n+            root_db_engine.dispose()\n+            print(f\"Created DB is {database_name}.\")\n+            return True\n+        except ProgrammingError as e:\n+            if isinstance(e.orig, InsufficientPrivilege):\n+                print(f\"Database {database_name} could not be created due to Insufficient Privilege\")\n+                return False\n+        except Exception:\n+            print(f\"Database {database_name} could not be created!\")\n+            return False\n     else:\n         print(f\"Database {database_name} not created!\")\n         return False\n", "issue": "The requirement of superuser postgresql access is problematic\n## Problem\r\nMathesar needs a Postgres superuser to function correctly, from the docs at https://docs.mathesar.org/installation/build-from-source/ \r\n\r\n## Proposed solution\r\nThe mathesar user should not require superuser access. \r\n\r\n## Additional context\r\nThe superuser is a global permission meaning that a user that has superuser permission will be able to access (and do stuff) not on the mathesar but *all* the databases of the RDBMS. Considering that many production systems have a single RDBMS hosting many application this is a major problem since the mathsar user won't have any access boundaries on the same RDBMS. The mathesar user access can be unlimited but *must* be bounded without the mathesar database.\n", "before_files": [{"content": "from sqlalchemy import text\nfrom sqlalchemy.exc import OperationalError\n\nfrom db import engine\nfrom db.sql import install as sql_install\nfrom db.types import install as types_install\n\n\ndef install_mathesar(\n        database_name, username, password, hostname, port, skip_confirm\n):\n    \"\"\"Create database and install Mathesar on it.\"\"\"\n    user_db_engine = engine.create_future_engine(\n        username, password, hostname, database_name, port,\n        connect_args={\"connect_timeout\": 10}\n    )\n    try:\n        user_db_engine.connect()\n        print(f\"Installing Mathesar on preexisting PostgreSQL database {database_name} at host {hostname}...\")\n        sql_install.install(user_db_engine)\n        types_install.install_mathesar_on_database(user_db_engine)\n        user_db_engine.dispose()\n    except OperationalError:\n        database_created = _create_database(\n            database_name=database_name,\n            hostname=hostname,\n            username=username,\n            password=password,\n            port=port,\n            skip_confirm=skip_confirm\n        )\n        if database_created:\n            print(f\"Installing Mathesar on PostgreSQL database {database_name} at host {hostname}...\")\n            sql_install.install(user_db_engine)\n            types_install.install_mathesar_on_database(user_db_engine)\n            user_db_engine.dispose()\n        else:\n            print(f\"Skipping installing on DB with key {database_name}.\")\n\n\ndef _create_database(database_name, hostname, username, password, port, skip_confirm=True):\n    if skip_confirm is True:\n        create_database = \"y\"\n    else:\n        create_database = input(\n            f\"Create a new Database called {database_name}? (y/n) > \"\n        )\n    if create_database.lower() in [\"y\", \"yes\"]:\n        # We need to connect to an existing database inorder to create a new Database.\n        # So we use the default Database `postgres` that comes with postgres.\n        # TODO Throw correct error when the default postgres database does not exists(which is very rare but still possible)\n        root_database = \"postgres\"\n        root_db_engine = engine.create_future_engine(\n            username, password, hostname, root_database, port,\n            connect_args={\"connect_timeout\": 10}\n        )\n        with root_db_engine.connect() as conn:\n            conn.execution_options(isolation_level=\"AUTOCOMMIT\")\n            conn.execute(text(f'CREATE DATABASE \"{database_name}\"'))\n        root_db_engine.dispose()\n        print(f\"Created DB is {database_name}.\")\n        return True\n    else:\n        print(f\"Database {database_name} not created!\")\n        return False\n", "path": "db/install.py"}]}