Skip to content
Merged
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
48 changes: 21 additions & 27 deletions lib/ecto/adapters/sqlite3.ex
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,27 @@ defmodule Ecto.Adapters.SQLite3 do

@impl Ecto.Adapter.Storage
def storage_up(options) do
storage_up_with_path(
Keyword.get(options, :database),
Keyword.get(options, :journal_mode, :wal)
)
database = Keyword.get(options, :database)

cond do
is_nil(database) ->
raise ArgumentError,
"""
No SQLite database path specified. Please check the configuration for your Repo.
Your config/*.exs file should have something like this in it:

config :my_app, MyApp.Repo,
adapter: Ecto.Adapters.SQLite3,
database: "/path/to/sqlite/database"
"""

File.exists?(database) ->
{:error, :already_up}

true ->
{:ok, state} = Exqlite.Connection.connect(options)
:ok = Exqlite.Connection.disconnect(:normal, state)
end
end

@impl Ecto.Adapter.Migration
Expand Down Expand Up @@ -446,29 +463,6 @@ defmodule Ecto.Adapters.SQLite3 do
## HELPERS
##

defp storage_up_with_path(nil, _) do
raise ArgumentError,
"""
No SQLite database path specified. Please check the configuration for your Repo.
Your config/*.exs file should have something like this in it:

config :my_app, MyApp.Repo,
adapter: Ecto.Adapters.SQLite3,
database: "/path/to/sqlite/database"
"""
end

defp storage_up_with_path(db_path, journal_mode) do
if File.exists?(db_path) do
{:error, :already_up}
else
db_path |> Path.dirname() |> File.mkdir_p!()
{:ok, db} = Exqlite.Sqlite3.open(db_path)
:ok = Exqlite.Sqlite3.execute(db, "PRAGMA JOURNAL_MODE = #{journal_mode}")
:ok = Exqlite.Sqlite3.close(db)
end
end

defp dump_versions(config) do
table = config[:migration_source] || "schema_migrations"

Expand Down