Skip to content
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

Update to Postgres 0.14 #143

Merged
merged 4 commits into from
Nov 11, 2018
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/event_store.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 12 additions & 1 deletion lib/event_store/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ defmodule EventStore.Config do
raise ArgumentError, "EventStore storage configuration not specified in environment"
end

@doc """
Get the connection pool module for postgrex.
"""
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.
"""
Expand All @@ -32,9 +42,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
"""
Expand Down
2 changes: 1 addition & 1 deletion lib/event_store/storage/database.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
30 changes: 16 additions & 14 deletions lib/event_store/storage/reader.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lib/event_store/subscriptions/subscription_fsm.ex
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ defmodule EventStore.Subscriptions.SubscriptionFsm do
stream_uuid,
subscription_name,
start_from,
pool: DBConnection.Poolboy
pool: EventStore.Config.get_pool()
)
end

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -601,7 +601,7 @@ defmodule EventStore.Subscriptions.SubscriptionFsm do
stream_uuid,
subscription_name,
last_ack,
pool: DBConnection.Poolboy
pool: EventStore.Config.get_pool()
)

data
Expand Down
2 changes: 1 addition & 1 deletion lib/event_store/tasks/init.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/event_store/tasks/migrate.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ defmodule EventStore.Mixfile do
[
{:fsm, "~> 0.3"},
{:gen_stage, "~> 0.14"},
{:poolboy, "~> 1.5"},
{:postgrex, "~> 0.13"},
{:poolboy, "~> 1.5", optional: true},
{:postgrex, "~> 0.14 or ~> 0.13"},
{:elixir_uuid, "~> 1.2"},

# Test & release tooling
Expand Down
4 changes: 2 additions & 2 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand All @@ -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"},
}
22 changes: 11 additions & 11 deletions test/config_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ defmodule EventStore.ConfigTest do
hostname: "localhost",
database: "eventstore_test",
password: "postgres",
pool: DBConnection.Poolboy
pool: EventStore.Config.get_pool()
]

assert Config.parse(original) == [
password: "postgres",
database: "eventstore_test",
hostname: "localhost",
username: "postgres",
pool: DBConnection.Poolboy
pool: EventStore.Config.get_pool()
]
end

Expand All @@ -27,15 +27,15 @@ 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) == [
password: "postgres",
database: "eventstore_test",
socket: "/path/to/socket",
username: "postgres",
pool: DBConnection.Poolboy
pool: EventStore.Config.get_pool()
]
end

Expand All @@ -45,15 +45,15 @@ 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) == [
password: "postgres",
database: "eventstore_test",
socket_dir: "/path/to/socket_dir",
username: "postgres",
pool: DBConnection.Poolboy
pool: EventStore.Config.get_pool()
]
end

Expand All @@ -67,7 +67,7 @@ defmodule EventStore.ConfigTest do
password: "password",
database: "database",
hostname: "localhost",
pool: DBConnection.Poolboy
pool: EventStore.Config.get_pool()
]
end

Expand All @@ -83,7 +83,7 @@ defmodule EventStore.ConfigTest do
hostname: "localhost",
pool_size: 5,
ssl: true,
pool: DBConnection.Poolboy
pool: EventStore.Config.get_pool()
]
end

Expand All @@ -97,7 +97,7 @@ defmodule EventStore.ConfigTest do
password: "password",
database: "database",
hostname: "localhost",
pool: DBConnection.Poolboy
pool: EventStore.Config.get_pool()
]
end

Expand Down Expand Up @@ -125,7 +125,7 @@ defmodule EventStore.ConfigTest do
database: "database",
password: "password",
username: "username",
pool: DBConnection.Poolboy
pool: EventStore.Config.get_pool()
]
end

Expand All @@ -134,7 +134,7 @@ defmodule EventStore.ConfigTest do

assert config == [
username: "default_username",
pool: DBConnection.Poolboy
pool: EventStore.Config.get_pool()
]
end

Expand Down
2 changes: 1 addition & 1 deletion test/subscriptions/subscribe_to_stream_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion test/subscriptions/subscription_locking_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ defmodule EventStore.Subscriptions.SubscriptionLockingTest do
"$all",
subscription_name,
2,
pool: DBConnection.Poolboy
pool: EventStore.Config.get_pool()
)

:ok = reconnect(subscription)
Expand Down