-
Notifications
You must be signed in to change notification settings - Fork 0
Implement Migrations Component #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,16 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||
| (ns postgresql-component.migrations | ||||||||||||||||||||||||||||||||||||||||||||||||
| (:require [clojure.tools.logging :as log] | ||||||||||||||||||||||||||||||||||||||||||||||||
| [integrant.core :as ig] | ||||||||||||||||||||||||||||||||||||||||||||||||
| [pg.migration.core :as migrations])) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| (defmethod ig/init-key ::postgresql-migrations | ||||||||||||||||||||||||||||||||||||||||||||||||
| [_ {:keys [components]}] | ||||||||||||||||||||||||||||||||||||||||||||||||
| (log/info :starting ::postgresql-migrations) | ||||||||||||||||||||||||||||||||||||||||||||||||
| (let [postgresql-config (-> components :config :postgresql) | ||||||||||||||||||||||||||||||||||||||||||||||||
| migrations-config (-> components :config :postgresql-migrations) | ||||||||||||||||||||||||||||||||||||||||||||||||
| configuration (merge postgresql-config migrations-config)] | ||||||||||||||||||||||||||||||||||||||||||||||||
| (migrations/migrate-all configuration))) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+6
to
+12
|
||||||||||||||||||||||||||||||||||||||||||||||||
| [integrant.core :as ig] | |
| [pg.migration.core :as migrations])) | |
| (defmethod ig/init-key ::postgresql-migrations | |
| [_ {:keys [components]}] | |
| (log/info :starting ::postgresql-migrations) | |
| (let [postgresql-config (-> components :config :postgresql) | |
| migrations-config (-> components :config :postgresql-migrations) | |
| configuration (merge postgresql-config migrations-config)] | |
| (migrations/migrate-all configuration))) | |
| [integrant.core :as ig])) | |
| (defmethod ig/init-key ::postgresql-migrations | |
| [_ {:keys [components]}] | |
| (log/info :starting ::postgresql-migrations) | |
| (let [postgresql-config (-> components :config :postgresql) | |
| migrations-config (-> components :config :postgresql-migrations) | |
| configuration (merge postgresql-config migrations-config) | |
| migrate-all (or (some-> 'pg.migration.core/migrate-all | |
| clojure.core/requiring-resolve) | |
| (throw (ex-info "pg.migration.core/migrate-all not found; ensure com.github.igrishaev/pg2-migration is on the classpath" | |
| {:component ::postgresql-migrations})))] | |
| (migrate-all configuration))) |
Copilot
AI
Jan 3, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The init-key method doesn't return the result of migrations/migrate-all. In Integrant, init-key should return a value that represents the initialized component, which is then passed to halt-key!. Currently, this method returns the result of migrate-all but doesn't store or track the migration state. Consider whether the component should return a map containing the configuration or migration result so it can be properly managed and potentially rolled back in halt-key! if needed.
| configuration (merge postgresql-config migrations-config)] | |
| (migrations/migrate-all configuration))) | |
| (defmethod ig/halt-key! ::postgresql-migrations | |
| [_ _] | |
| configuration (merge postgresql-config migrations-config) | |
| result (migrations/migrate-all configuration)] | |
| {:configuration configuration | |
| :result result})) | |
| (defmethod ig/halt-key! ::postgresql-migrations | |
| [_ component] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The configuration retrieval from nested maps doesn't include nil checks or validation. If components, :config, :postgresql, or :postgresql-migrations are nil or missing, this will fail silently or produce confusing errors. Consider adding validation or error handling to provide clear error messages when required configuration is missing.