 schema in the target database instance."
   (log/info "Installing schema:" schema)
   (let [ [schema-name schema-version ] schema ]
-    (safe-run-script conn (schema-install-script schema))
+    (safe-run-script conn (schema-install-script conn schema))
     (set-schema-version! conn schema-name schema-version)))
 
 (defn- migrate-schema [ conn schema-name cur-schema-version req-schema-version ]

  (log/info "Upgrading schema" schema-name "from version" cur-schema-version "to" req-schema-version)
  (doseq [ from-version (range cur-schema-version req-schema-version )]
    (let [ to-version (+ from-version 1) ]
      (safe-run-script conn (schema-migrate-script [ schema-name to-version ]))
      (set-schema-version! conn schema-name to-version))))

(defn- ensure-schema [ conn schema ]

            [clojure.java.jdbc :as jdbc]
            [sql-file.script :as script]))

(defn- locate-schema-script [ conn basename ]
  (or (some identity
            (map (fn [ prefix ]
                   (let [ script-path (format "%s%s" prefix basename)]
                     (log/debug "Checking for script:" script-path)
                     (clojure.java.io/resource script-path)))
                 (conj (get conn :script-prefixes []) "")))
      (throw (Exception. (str "Cannot find resource script: " basename)))))

(defn- schema-install-script [ conn schema ]
  "Locate the schema script to install the given schema name and
version. If there is no such script, throws an exception."
  (let [[ schema-name schema-version ] schema]
    (locate-schema-script conn (format "schema-%s-%s.sql" schema-name schema-version))))

(defn- schema-migrate-script [ conn schema ]
  "Locate the schema migration script for the given schema name and
to-version. If there is no such script, throws an exception. The
migration script is expected to migrate the schema from version n-1 to
version n, where n=to-version."
  (let [ [ schema-name schema-to-version ] schema ]
    (locate-schema-script conn (format "schema-%s-migrate-to-%s.sql" schema-name schema-to-version))))

(defn- run-script [ conn script-url ]
  "Run the database script at the given URL against a specific
