Skip to content

Implement Migrations Component#3

Merged
macielti merged 3 commits intomainfrom
implement-migrations-component
Jan 3, 2026
Merged

Implement Migrations Component#3
macielti merged 3 commits intomainfrom
implement-migrations-component

Conversation

@macielti
Copy link
Owner

@macielti macielti commented Jan 3, 2026

Added

  • Implement migrations component.

@macielti macielti requested a review from Copilot January 3, 2026 01:30
@macielti macielti merged commit fe90bc6 into main Jan 3, 2026
9 checks passed
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +11 to +15
configuration (merge postgresql-config migrations-config)]
(migrations/migrate-all configuration)))

(defmethod ig/halt-key! ::postgresql-migrations
[_ _]
Copy link

Copilot AI Jan 3, 2026

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.

Suggested change
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]

Copilot uses AI. Check for mistakes.
Comment on lines +9 to +12
(let [postgresql-config (-> components :config :postgresql)
migrations-config (-> components :config :postgresql-migrations)
configuration (merge postgresql-config migrations-config)]
(migrations/migrate-all configuration)))
Copy link

Copilot AI Jan 3, 2026

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.

Suggested change
(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))))

Copilot uses AI. Check for mistakes.
Comment on lines +6 to +12
(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)))
Copy link

Copilot AI Jan 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +3 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)))
Copy link

Copilot AI Jan 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
[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 uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments