 (defn create-db!
   "Given a DB spec that has a user with permission to create databases and that
   connects to a database that isn't `db-name`, the database's name, and the name
-  of the user that will own the database, creates the database `db-name` owned by
-  `db-owner`, with the DB's encoding set to UTF-8."
+  of the user that will own the database, creates the database `db-name` owned
+  by `db-owner`, with the DB's encoding set to UTF-8."
   [admin-db-spec db-name db-owner]
   (let [sql (format "CREATE DATABASE %s WITH OWNER %s ENCODING 'UTF8'"
                     (pg-escape-identifier db-name)

      result)))

(defn db-exists?
  [admin-db-spec db-name]
  (-> (jdbc/query admin-db-spec ["SELECT 1 AS exists FROM pg_database WHERE datname = ?" db-name])
    first

    nil))

(defn drop-user!
  "Given a DB spec that connects with a user besides `username` and has
  permisson to drop that user, remove the named user. Note that only superusers
  can remove other superusers; other users can be removed by anyone with the
  CREATEROLE permission."
  [admin-db-spec username]
  (let [sql (format "DROP ROLE IF EXISTS %s" (pg-escape-identifier username))]
    (jdbc/execute! admin-db-spec [sql])
