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

Fix/create table options list guard #69

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
4 changes: 2 additions & 2 deletions lib/ecto/adapters/sqlite3/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ defmodule Ecto.Adapters.SQLite3.Connection do
##

@impl true
def execute_ddl({_command, %Table{options: keyword}, _}) when keyword != nil do
def execute_ddl({_command, %Table{options: options}, _}) when is_list(options) do
raise ArgumentError, "SQLite3 adapter does not support keyword lists in :options"
end

Expand Down Expand Up @@ -1624,7 +1624,7 @@ defmodule Ecto.Adapters.SQLite3.Connection do

defp options_expr(nil), do: []

defp options_expr(keyword) when is_list(keyword) do
defp options_expr(options) when is_list(options) do
raise ArgumentError, "SQLite3 adapter does not support keyword lists in :options"
end

Expand Down
19 changes: 18 additions & 1 deletion test/ecto/adapters/sqlite3/connection_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2233,11 +2233,28 @@ defmodule Ecto.Adapters.SQLite3.ConnectionTest do
end

test "create table with options" do
create =
{:create, table(:posts, options: "WITH FOO=BAR"),
[
{:add, :id, :serial, [primary_key: true]}
]}

assert execute_ddl(create) == [
"""
CREATE TABLE "posts" (\
"id" INTEGER PRIMARY KEY AUTOINCREMENT\
) \
WITH FOO=BAR\
"""
]
end

test "create table with list as options" do
assert_raise(
ArgumentError,
"SQLite3 adapter does not support keyword lists in :options",
fn ->
{:create, table(:posts, options: "WITH FOO=BAR"),
{:create, table(:posts, options: ["WITH FOO=BAR"]),
[{:add, :id, :serial, [primary_key: true]}, {:add, :created_at, :datetime, []}]}
|> execute_ddl()
end
Expand Down