Conversation
There was a problem hiding this comment.
Pull request overview
This PR implements a new migrations component for PostgreSQL database migrations using the Integrant lifecycle management framework. The component integrates with the pg2-migration library to execute database migrations during application startup.
Key Changes:
- Adds a new migrations component with Integrant lifecycle methods (init-key and halt-key!)
- Updates project dependencies and plugins to newer versions
- Bumps project version from 2.2.5 to 2.3.5
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/postgresql_component/migrations.clj | Implements the new migrations component with init-key and halt-key! methods for Integrant lifecycle management |
| project.clj | Updates project version to 2.3.5, upgrades multiple dependencies (Clojure, Pedestal, pg2-core, integrant, etc.), and updates plugin versions |
| CHANGELOG.md | Documents the 2.3.5 release with the migrations component addition |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| configuration (merge postgresql-config migrations-config)] | ||
| (migrations/migrate-all configuration))) | ||
|
|
||
| (defmethod ig/halt-key! ::postgresql-migrations | ||
| [_ _] |
There was a problem hiding this comment.
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] |
| (let [postgresql-config (-> components :config :postgresql) | ||
| migrations-config (-> components :config :postgresql-migrations) | ||
| configuration (merge postgresql-config migrations-config)] | ||
| (migrations/migrate-all configuration))) |
There was a problem hiding this comment.
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.
| (let [postgresql-config (-> components :config :postgresql) | |
| migrations-config (-> components :config :postgresql-migrations) | |
| configuration (merge postgresql-config migrations-config)] | |
| (migrations/migrate-all configuration))) | |
| (let [config (:config components) | |
| postgresql-config (:postgresql config) | |
| migrations-config (:postgresql-migrations config)] | |
| (when-not (map? config) | |
| (throw (ex-info "Missing or invalid :config for ::postgresql-migrations component" | |
| {:component ::postgresql-migrations | |
| :config config}))) | |
| (when-not (map? postgresql-config) | |
| (throw (ex-info "Missing or invalid :postgresql configuration for ::postgresql-migrations" | |
| {:component ::postgresql-migrations | |
| :postgresql-config postgresql-config}))) | |
| (when-not (map? migrations-config) | |
| (throw (ex-info "Missing or invalid :postgresql-migrations configuration for ::postgresql-migrations" | |
| {:component ::postgresql-migrations | |
| :migrations-config migrations-config}))) | |
| (let [configuration (merge postgresql-config migrations-config)] | |
| (migrations/migrate-all configuration)))) |
| (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))) |
There was a problem hiding this comment.
The new migrations component lacks test coverage. The repository has integration tests for the PostgreSQL component (postgresql_component_test.clj), but there are no tests for the migrations functionality. Consider adding integration tests to verify that the migrations component initializes correctly, applies migrations, and handles configuration properly.
| [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))) |
There was a problem hiding this comment.
The migrations component requires the pg.migration.core namespace (from com.github.igrishaev/pg2-migration), but this dependency is only available in the :dev profile. Since migrations.clj is production code (in src/, not test/), the pg2-migration dependency should be moved from :dev :dependencies to the main :dependencies list to ensure it's available at runtime.
| [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))) |
Added