Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
All notable changes to this project will be documented in this file. This change log follows the conventions
of [keepachangelog.com](http://keepachangelog.com/).

## Unreleased
## 2.3.5 - 2026-01-02

## 2.2.4 - 2025-02-01
### Added

- Implement migrations component.

## 2.2.5 - 2025-02-01

### Changed

Expand Down
22 changes: 11 additions & 11 deletions project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject net.clojars.macielti/postgresql-component "2.2.5"
(defproject net.clojars.macielti/postgresql-component "2.3.5"

:description "PostgreSQL Component"

Expand All @@ -7,24 +7,24 @@
:license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
:url "https://www.eclipse.org/legal/epl-2.0/"}

:plugins [[com.github.clojure-lsp/lein-clojure-lsp "1.4.16"]
:plugins [[com.github.clojure-lsp/lein-clojure-lsp "2.0.13"]
[com.github.liquidz/antq "RELEASE"]
[lein-shell "0.5.0"]]

:dependencies [[org.clojure/clojure "1.12.0"]
[io.pedestal/pedestal.interceptor "0.7.2"]
[com.github.igrishaev/pg2-core "0.1.33"]
[org.clojure/tools.logging "1.3.0"]
[integrant "0.13.1"]]
:dependencies [[org.clojure/clojure "1.12.4"]
[io.pedestal/pedestal.interceptor "0.8.1"]
[com.github.igrishaev/pg2-core "0.1.41"]
[org.clojure/tools.logging "1.3.1"]
[integrant "1.0.1"]]

:profiles {:dev {:resource-paths ^:replace ["test/resources"]

:test-paths ^:replace ["test/unit" "test/integration" "test/helpers"]

:dependencies [[com.github.igrishaev/pg2-migration "0.1.33"]
[nubank/matcher-combinators "3.9.1"]
[org.slf4j/slf4j-api "2.0.16"]
[ch.qos.logback/logback-classic "1.5.16"]
:dependencies [[com.github.igrishaev/pg2-migration "0.1.41"]
[nubank/matcher-combinators "3.9.2"]
[org.slf4j/slf4j-api "2.0.17"]
[ch.qos.logback/logback-classic "1.5.23"]
[prismatic/schema "1.4.1"]
[clojure.java-time "1.4.3"]
[hashp "0.2.2"]]
Expand Down
16 changes: 16 additions & 0 deletions src/postgresql_component/migrations.clj
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 +9 to +12
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
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
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.

(defmethod ig/halt-key! ::postgresql-migrations
[_ _]
Comment on lines +11 to +15
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.
(log/info :stopping ::postgresql-migrations))