Skip to content

Instantly share code, notes, and snippets.

@igrishaev
Created March 6, 2018 08:50
Show Gist options
  • Save igrishaev/2471e5ab8b1b122682c8bed739f791a5 to your computer and use it in GitHub Desktop.
Save igrishaev/2471e5ab8b1b122682c8bed739f791a5 to your computer and use it in GitHub Desktop.
(defn psql
"Executes a SQL file using psql utility."
[sql-file]
(let [pg-keys ["PGHOST" "PGPORT" "PGDATABASE" "PGUSER" "PGPASSWORD"]
pg-vals (mapv #(System/getenv %) pg-keys)
pg-cred (into {} (map vector pg-keys pg-vals))]
(shell/with-env pg-cred
(shell/sh "psql" "-f" (from-workdir sql-file)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment