Skip to content

Raise if using an in memory database with pool_size != 1 #128

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

Merged
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
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