Skip to content

Commit

Permalink
Raise if using an in memory database with pool_size != 1 (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdwaud authored Oct 5, 2023
1 parent 794efcc commit f9fdfa5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ project adheres to [Semantic Versioning][semver].

## Unreleased

- changed: raise if an in memory database is opened with a pool_size != 1

## v0.11.0

- added: Support for DDL transactions.
Expand Down
6 changes: 6 additions & 0 deletions lib/ecto/adapters/sqlite3.ex
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ defmodule Ecto.Adapters.SQLite3 do
@impl Ecto.Adapter.Storage
def storage_up(options) do
database = Keyword.get(options, :database)
pool_size = Keyword.get(options, :pool_size)

cond do
is_nil(database) ->
Expand All @@ -226,6 +227,11 @@ defmodule Ecto.Adapters.SQLite3 do
File.exists?(database) ->
{:error, :already_up}

database == ":memory:" && pool_size != 1 ->
raise ArgumentError, """
In memory databases must have a pool_size of 1
"""

true ->
{:ok, state} = Exqlite.Connection.connect(options)
:ok = Exqlite.Connection.disconnect(:normal, state)
Expand Down
14 changes: 14 additions & 0 deletions test/ecto/adapters/sqlite3_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,20 @@ defmodule Ecto.Adapters.SQLite3ConnTest do
fn -> SQLite3.storage_up(mumble: "no database here") == :ok end
)
end

test "can create an in memory database" do
assert SQLite3.storage_up(database: ":memory:", pool_size: 1) == :ok
end

test "fails if in memory database does not have a pool size of 1" do
assert_raise(
ArgumentError,
"""
In memory databases must have a pool_size of 1
""",
fn -> SQLite3.storage_up(database: ":memory:", pool_size: 2) end
)
end
end

describe ".storage_down/2" do
Expand Down

0 comments on commit f9fdfa5

Please sign in to comment.