Last active
December 20, 2019 12:15
-
-
Save werenall/89df5205e42506547bff444b4bba328b to your computer and use it in GitHub Desktop.
This gist is a draft of a module that would wrap duct configuration for ragtime migrations. I get a feeling that writing it by hand takes way too much space in config. Of course there are still some loose ends. For one, it could be more explicit about the ordering of migrations.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{;;... ... | |
:duct.migrator/ragtime {:database #ig/ref :duct.database/sql | |
:logger #ig/ref :duct/logger | |
:strategy :raise-error | |
:migrations-paths ["myproject/migrations/001-create-initial-schema" | |
"myproject/migrations/002-rename-foo-column" | |
"myproject/migrations/003-add-foreign-keys"]} | |
;;... ...} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{:duct.migrator/ragtime | |
{:migrations-paths ["myproject/dev_migrations/dev001-mock-data"]}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require '[integrant.core :as ig] | |
'[duct.core :as core] | |
'[clojure.string :as str]) | |
(defn- migration-name [migration-path] | |
(last (str/split migration-path #"/"))) | |
(defn- migration-keyword [migration-name] | |
(keyword | |
"myproject.migration" | |
(str "_" migration-name))) | |
(defn- migrations-refs [migration-names] | |
(mapv #(ig/ref (migration-keyword %)) migration-names)) | |
(defmethod ig/init-key :hydrogen.module/ragtime-migrations [_ _] | |
(fn [config] | |
(core/merge-configs | |
config | |
(when-let [migrations-paths (get-in config [:duct.migrator/ragtime :migrations-paths])] | |
(let [migrations (into {} (map #(vector (migration-name %) %) migrations-paths))] | |
(-> | |
(into {} | |
(map | |
(fn [[m-name m-path]] | |
[[:duct.migrator.ragtime/sql (migration-keyword m-name)] | |
{:up [(core/resource (str m-path ".up.sql"))] | |
:down [(core/resource (str m-path ".down.sql"))]}]) | |
migrations)) | |
(assoc-in [:duct.migrator/ragtime :migrations] | |
(migrations-refs (keys migrations))))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment