From 62617493a669c775515e0ba9e722ab1d21f0e350 Mon Sep 17 00:00:00 2001 From: Vasilis Spilka Date: Sat, 10 Nov 2018 23:25:13 +0100 Subject: [PATCH 1/4] ensure Postgrex.Timestamp loaded --- lib/event_store/storage/reader.ex | 30 ++++++++++++++++-------------- mix.exs | 2 +- mix.lock | 4 ++-- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/lib/event_store/storage/reader.ex b/lib/event_store/storage/reader.ex index 4764cbe8..a2bce8bd 100644 --- a/lib/event_store/storage/reader.ex +++ b/lib/event_store/storage/reader.ex @@ -70,20 +70,22 @@ defmodule EventStore.Storage.Reader do defp to_naive(%NaiveDateTime{} = naive), do: naive - defp to_naive(%Postgrex.Timestamp{} = timestamp) do - %Postgrex.Timestamp{ - year: year, - month: month, - day: day, - hour: hour, - min: minute, - sec: second, - usec: microsecond - } = timestamp - - with {:ok, naive} <- - NaiveDateTime.new(year, month, day, hour, minute, second, {microsecond, 6}) do - naive + if (Code.ensure_loaded?(Postgrex.Timestamp)) do + defp to_naive(%Postgrex.Timestamp{} = timestamp) do + %Postgrex.Timestamp{ + year: year, + month: month, + day: day, + hour: hour, + min: minute, + sec: second, + usec: microsecond + } = timestamp + + with {:ok, naive} <- + NaiveDateTime.new(year, month, day, hour, minute, second, {microsecond, 6}) do + naive + end end end end diff --git a/mix.exs b/mix.exs index 43793434..edd19b4d 100644 --- a/mix.exs +++ b/mix.exs @@ -46,7 +46,7 @@ defmodule EventStore.Mixfile do {:fsm, "~> 0.3"}, {:gen_stage, "~> 0.14"}, {:poolboy, "~> 1.5"}, - {:postgrex, "~> 0.13"}, + {:postgrex, "~> 0.14 or ~> 0.13"}, {:elixir_uuid, "~> 1.2"}, # Test & release tooling diff --git a/mix.lock b/mix.lock index b53bdc88..34380b40 100644 --- a/mix.lock +++ b/mix.lock @@ -3,7 +3,7 @@ "bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm"}, "connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], [], "hexpm"}, "credo": {:hex, :credo, "0.10.1", "e85efaf2dd7054399083ab2c6a5199f6cb1805de1a5b00d9e8c5f07033407b1f", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm"}, - "db_connection": {:hex, :db_connection, "1.1.3", "89b30ca1ef0a3b469b1c779579590688561d586694a3ce8792985d4d7e575a61", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm"}, + "db_connection": {:hex, :db_connection, "2.0.1", "09454c6c6e8e4295f400b72580b19f0ac68fda2602e209533285206cb99bee6b", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm"}, "decimal": {:hex, :decimal, "1.5.0", "b0433a36d0e2430e3d50291b1c65f53c37d56f83665b43d79963684865beab68", [:mix], [], "hexpm"}, "dialyxir": {:hex, :dialyxir, "0.5.1", "b331b091720fd93e878137add264bac4f644e1ddae07a70bf7062c7862c4b952", [:mix], [], "hexpm"}, "earmark": {:hex, :earmark, "1.2.6", "b6da42b3831458d3ecc57314dff3051b080b9b2be88c2e5aa41cd642a5b044ed", [:mix], [], "hexpm"}, @@ -21,5 +21,5 @@ "nimble_parsec": {:hex, :nimble_parsec, "0.4.0", "ee261bb53214943679422be70f1658fff573c5d0b0a1ecd0f18738944f818efe", [:mix], [], "hexpm"}, "poison": {:hex, :poison, "4.0.1", "bcb755a16fac91cad79bfe9fc3585bb07b9331e50cfe3420a24bcc2d735709ae", [:mix], [], "hexpm"}, "poolboy": {:hex, :poolboy, "1.5.1", "6b46163901cfd0a1b43d692657ed9d7e599853b3b21b95ae5ae0a777cf9b6ca8", [:rebar], [], "hexpm"}, - "postgrex": {:hex, :postgrex, "0.13.5", "3d931aba29363e1443da167a4b12f06dcd171103c424de15e5f3fc2ba3e6d9c5", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 1.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm"}, + "postgrex": {:hex, :postgrex, "0.14.0", "f3d6ffea1ca8a156e0633900a5338a3d17b00435227726baed8982718232b694", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.0", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm"}, } From 2c6483ad9cdd2210d979c1f98a5176d64ce822ff Mon Sep 17 00:00:00 2001 From: Vasilis Spilka Date: Sat, 10 Nov 2018 23:39:43 +0100 Subject: [PATCH 2/4] update to postgrex 0.14 --- lib/event_store.ex | 2 +- lib/event_store/config.ex | 12 +++++++++- lib/event_store/storage/database.ex | 2 +- .../subscriptions/subscription_fsm.ex | 6 ++--- lib/event_store/tasks/init.ex | 2 +- lib/event_store/tasks/migrate.ex | 2 +- mix.exs | 2 +- test/config_test.exs | 22 +++++++++---------- .../subscribe_to_stream_test.exs | 2 +- .../subscription_locking_test.exs | 2 +- 10 files changed, 32 insertions(+), 22 deletions(-) diff --git a/lib/event_store.ex b/lib/event_store.ex index 4d2e32a8..64bdea97 100644 --- a/lib/event_store.ex +++ b/lib/event_store.ex @@ -620,7 +620,7 @@ defmodule EventStore do """ def configuration, do: EventStore.Config.get() - @default_opts [pool: DBConnection.Poolboy] + @default_opts [pool: EventStore.Config.get_pool()] defp opts, do: @default_opts diff --git a/lib/event_store/config.ex b/lib/event_store/config.ex index 628429f2..9118beba 100644 --- a/lib/event_store/config.ex +++ b/lib/event_store/config.ex @@ -13,6 +13,15 @@ defmodule EventStore.Config do raise ArgumentError, "EventStore storage configuration not specified in environment" end + @doc """ + """ + def get_pool do + case Code.ensure_loaded?(DBConnection.ConnectionPool) do + true -> DBConnection.ConnectionPool + false -> DBConnection.Poolboy + end + end + @doc """ Get the event store configuration for the environment. """ @@ -32,9 +41,10 @@ defmodule EventStore.Config do {:socket_dir, value}, config -> Keyword.put(config, :socket_dir, get_config_value(value)) {key, value}, config -> Keyword.put(config, key, get_config_value(value)) end) - |> Keyword.merge(pool: DBConnection.Poolboy) + |> Keyword.merge(pool: EventStore.Config.get_pool()) end + @doc """ Converts a database url into a Keyword list """ diff --git a/lib/event_store/storage/database.ex b/lib/event_store/storage/database.ex index 95ba9626..302a08ff 100644 --- a/lib/event_store/storage/database.ex +++ b/lib/event_store/storage/database.ex @@ -123,7 +123,7 @@ defmodule EventStore.Storage.Database do opts = opts |> Keyword.drop([:name, :log]) - |> Keyword.put(:pool, DBConnection.Connection) + |> Keyword.put(:pool, EventStore.Config.get_pool()) |> Keyword.put(:backoff_type, :stop) {:ok, pid} = Task.Supervisor.start_link() diff --git a/lib/event_store/subscriptions/subscription_fsm.ex b/lib/event_store/subscriptions/subscription_fsm.ex index 9494e4e2..7e80c021 100644 --- a/lib/event_store/subscriptions/subscription_fsm.ex +++ b/lib/event_store/subscriptions/subscription_fsm.ex @@ -264,7 +264,7 @@ defmodule EventStore.Subscriptions.SubscriptionFsm do stream_uuid, subscription_name, start_from, - pool: DBConnection.Poolboy + pool: EventStore.Config.get_pool() ) end @@ -387,7 +387,7 @@ defmodule EventStore.Subscriptions.SubscriptionFsm do stream_uuid, last_sent + 1, max_size, - pool: DBConnection.Poolboy + pool: EventStore.Config.get_pool() ) end @@ -601,7 +601,7 @@ defmodule EventStore.Subscriptions.SubscriptionFsm do stream_uuid, subscription_name, last_ack, - pool: DBConnection.Poolboy + pool: EventStore.Config.get_pool() ) data diff --git a/lib/event_store/tasks/init.ex b/lib/event_store/tasks/init.ex index 5807b676..9387bdf4 100644 --- a/lib/event_store/tasks/init.ex +++ b/lib/event_store/tasks/init.ex @@ -31,7 +31,7 @@ defmodule EventStore.Tasks.Init do {:ok, conn} = Postgrex.start_link(config) - conn_opts = [pool: DBConnection.Poolboy] + conn_opts = [pool: EventStore.Config.get_pool()] Postgrex.query!(conn, @is_events_table_exists, [], conn_opts) |> case do diff --git a/lib/event_store/tasks/migrate.ex b/lib/event_store/tasks/migrate.ex index 9907ffcc..1e05a733 100644 --- a/lib/event_store/tasks/migrate.ex +++ b/lib/event_store/tasks/migrate.ex @@ -87,7 +87,7 @@ defmodule EventStore.Tasks.Migrate do |> Postgrex.query!( "SELECT major_version, minor_version, patch_version FROM schema_migrations", [], - pool: DBConnection.Poolboy + pool: EventStore.Config.get_pool() ) |> handle_response() end diff --git a/mix.exs b/mix.exs index edd19b4d..5e950cf6 100644 --- a/mix.exs +++ b/mix.exs @@ -45,7 +45,7 @@ defmodule EventStore.Mixfile do [ {:fsm, "~> 0.3"}, {:gen_stage, "~> 0.14"}, - {:poolboy, "~> 1.5"}, + {:poolboy, "~> 1.5", optional: true}, {:postgrex, "~> 0.14 or ~> 0.13"}, {:elixir_uuid, "~> 1.2"}, diff --git a/test/config_test.exs b/test/config_test.exs index 27cd37b0..4aa32d73 100644 --- a/test/config_test.exs +++ b/test/config_test.exs @@ -9,7 +9,7 @@ defmodule EventStore.ConfigTest do hostname: "localhost", database: "eventstore_test", password: "postgres", - pool: DBConnection.Poolboy + pool: EventStore.Config.get_pool() ] assert Config.parse(original) == [ @@ -17,7 +17,7 @@ defmodule EventStore.ConfigTest do database: "eventstore_test", hostname: "localhost", username: "postgres", - pool: DBConnection.Poolboy + pool: EventStore.Config.get_pool() ] end @@ -27,7 +27,7 @@ defmodule EventStore.ConfigTest do socket: "/path/to/socket", database: "eventstore_test", password: "postgres", - pool: DBConnection.Poolboy + pool: EventStore.Config.get_pool() ] assert Config.parse(original) == [ @@ -35,7 +35,7 @@ defmodule EventStore.ConfigTest do database: "eventstore_test", socket: "/path/to/socket", username: "postgres", - pool: DBConnection.Poolboy + pool: EventStore.Config.get_pool() ] end @@ -45,7 +45,7 @@ defmodule EventStore.ConfigTest do socket_dir: "/path/to/socket_dir", database: "eventstore_test", password: "postgres", - pool: DBConnection.Poolboy + pool: EventStore.Config.get_pool() ] assert Config.parse(original) == [ @@ -53,7 +53,7 @@ defmodule EventStore.ConfigTest do database: "eventstore_test", socket_dir: "/path/to/socket_dir", username: "postgres", - pool: DBConnection.Poolboy + pool: EventStore.Config.get_pool() ] end @@ -67,7 +67,7 @@ defmodule EventStore.ConfigTest do password: "password", database: "database", hostname: "localhost", - pool: DBConnection.Poolboy + pool: EventStore.Config.get_pool() ] end @@ -83,7 +83,7 @@ defmodule EventStore.ConfigTest do hostname: "localhost", pool_size: 5, ssl: true, - pool: DBConnection.Poolboy + pool: EventStore.Config.get_pool() ] end @@ -97,7 +97,7 @@ defmodule EventStore.ConfigTest do password: "password", database: "database", hostname: "localhost", - pool: DBConnection.Poolboy + pool: EventStore.Config.get_pool() ] end @@ -125,7 +125,7 @@ defmodule EventStore.ConfigTest do database: "database", password: "password", username: "username", - pool: DBConnection.Poolboy + pool: EventStore.Config.get_pool() ] end @@ -134,7 +134,7 @@ defmodule EventStore.ConfigTest do assert config == [ username: "default_username", - pool: DBConnection.Poolboy + pool: EventStore.Config.get_pool() ] end diff --git a/test/subscriptions/subscribe_to_stream_test.exs b/test/subscriptions/subscribe_to_stream_test.exs index 1112e0db..cf8d3e20 100644 --- a/test/subscriptions/subscribe_to_stream_test.exs +++ b/test/subscriptions/subscribe_to_stream_test.exs @@ -556,7 +556,7 @@ defmodule EventStore.Subscriptions.SubscribeToStreamTest do assert :ok = EventStore.delete_subscription(stream_uuid, subscription_name) refute Process.alive?(subscription) - assert {:ok, []} = EventStore.Storage.subscriptions(@conn, pool: DBConnection.Poolboy) + assert {:ok, []} = EventStore.Storage.subscriptions(@conn, pool: EventStore.Config.get_pool()) end end diff --git a/test/subscriptions/subscription_locking_test.exs b/test/subscriptions/subscription_locking_test.exs index 9200b1ba..2045dd43 100644 --- a/test/subscriptions/subscription_locking_test.exs +++ b/test/subscriptions/subscription_locking_test.exs @@ -78,7 +78,7 @@ defmodule EventStore.Subscriptions.SubscriptionLockingTest do "$all", subscription_name, 2, - pool: DBConnection.Poolboy + pool: EventStore.Config.get_pool() ) :ok = reconnect(subscription) From 0ecd15943c2fbe40ad938514b20e46608427ef9a Mon Sep 17 00:00:00 2001 From: Vasilis Spilka Date: Sat, 10 Nov 2018 23:43:13 +0100 Subject: [PATCH 3/4] add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec1877bb..bb44263e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - Rename `uuid` dependency to `elixir_uuid` ([#135](https://github.com/commanded/eventstore/pull/135)). - Subscription concurrency ([#134](https://github.com/commanded/eventstore/pull/134)). - Send `:subscribed` message to all subscribers connected to a subscription ([#136](https://github.com/commanded/eventstore/pull/136)). +- Update to `postgrex 0.14` ([#143](https://github.com/commanded/eventstore/pull/143)). ## 0.15.1 From 69ed01724c1c7a2c4fb47a44915684a4cd78b9a7 Mon Sep 17 00:00:00 2001 From: Vasilis Spilka Date: Sat, 10 Nov 2018 23:47:47 +0100 Subject: [PATCH 4/4] add missing doc --- lib/event_store/config.ex | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/event_store/config.ex b/lib/event_store/config.ex index 9118beba..95c6cdb4 100644 --- a/lib/event_store/config.ex +++ b/lib/event_store/config.ex @@ -14,6 +14,7 @@ defmodule EventStore.Config do end @doc """ + Get the connection pool module for postgrex. """ def get_pool do case Code.ensure_loaded?(DBConnection.ConnectionPool) do