Skip to content

Commit c789176

Browse files
authored
Add support for Ecto 3.10 (#108)
1 parent 6f1ca67 commit c789176

File tree

6 files changed

+33
-20
lines changed

6 files changed

+33
-20
lines changed

integration_test/constraints_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ defmodule Ecto.Integration.ConstraintsTest do
5252
assert_raise Ecto.ConstraintError, ~r/constraint error when attempting to insert struct/, fn ->
5353
PoolRepo.insert(overlapping_changeset)
5454
end
55-
assert exception.message =~ "cannot_overlap (check_constraint)"
55+
assert exception.message =~ ~r/cannot_overlap.*\(check_constraint\)/
5656
assert exception.message =~ "The changeset has not defined any constraint."
5757
assert exception.message =~ "call `check_constraint/3`"
5858

integration_test/test_helper.exs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ ExUnit.start(
116116
:placeholders,
117117
# SQLite3 stores booleans as integers, causing Ecto's json_extract_path tests to fail
118118
:json_extract_path,
119+
# SQLite3 doesn't support specifying columns for ON DELETE SET NULL
120+
:on_delete_nilify_column_list,
119121

120122
# We don't support selected_as
121123
:selected_as_with_group_by,

lib/ecto/adapters/sqlite3/connection.ex

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,13 @@ defmodule Ecto.Adapters.SQLite3.Connection do
681681
]
682682
end
683683

684+
def execute_ddl({:rename, %Index{} = index, new_index}) do
685+
[
686+
execute_ddl({:drop, index}),
687+
execute_ddl({:create, %Index{index | name: new_index}})
688+
]
689+
end
690+
684691
def execute_ddl(string) when is_binary(string), do: [string]
685692

686693
def execute_ddl(keyword) when is_list(keyword) do
@@ -894,6 +901,10 @@ defmodule Ecto.Adapters.SQLite3.Connection do
894901

895902
def cte(%{with_ctes: _}, _), do: []
896903

904+
defp cte_expr({name, _opts, cte}, sources, query) do
905+
cte_expr({name, cte}, sources, query)
906+
end
907+
897908
defp cte_expr({name, cte}, sources, query) do
898909
[
899910
quote_name(name),
@@ -1113,7 +1124,7 @@ defmodule Ecto.Adapters.SQLite3.Connection do
11131124

11141125
def limit(%{limit: nil}, _sources), do: []
11151126

1116-
def limit(%{limit: %QueryExpr{expr: expression}} = query, sources) do
1127+
def limit(%{limit: %{expr: expression}} = query, sources) do
11171128
[" LIMIT " | expr(expression, sources, query)]
11181129
end
11191130

mix.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ defmodule EctoSQLite3.MixProject do
3434
defp deps do
3535
[
3636
{:decimal, "~> 1.6 or ~> 2.0"},
37-
{:ecto_sql, "~> 3.9"},
38-
{:ecto, "~> 3.9"},
37+
{:ecto_sql, "~> 3.10"},
38+
{:ecto, "~> 3.10"},
3939
{:exqlite, "~> 0.9"},
4040
{:ex_doc, "~> 0.27", only: [:dev], runtime: false},
4141
{:jason, ">= 0.0.0", only: [:dev, :test, :docs]},

mix.lock

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
"benchee": {:hex, :benchee, "1.1.0", "f3a43817209a92a1fade36ef36b86e1052627fd8934a8b937ac9ab3a76c43062", [:mix], [{:deep_merge, "~> 1.0", [hex: :deep_merge, repo: "hexpm", optional: false]}, {:statistex, "~> 1.0", [hex: :statistex, repo: "hexpm", optional: false]}], "hexpm", "7da57d545003165a012b587077f6ba90b89210fd88074ce3c60ce239eb5e6d93"},
33
"benchee_markdown": {:hex, :benchee_markdown, "0.3.1", "9d08a81ae217722ba65ade422b39dfb932cc14d96a2047c44dd30b025bbbb8b7", [:mix], [{:benchee, ">= 1.1.0 and < 2.0.0", [hex: :benchee, repo: "hexpm", optional: false]}], "hexpm", "6274a076e8bd51b192e957b6a7de957b4a1bbb5583892ea3673e0808f658bf5f"},
44
"bunt": {:hex, :bunt, "0.2.1", "e2d4792f7bc0ced7583ab54922808919518d0e57ee162901a16a1b6664ef3b14", [:mix], [], "hexpm", "a330bfb4245239787b15005e66ae6845c9cd524a288f0d141c148b02603777a5"},
5-
"connection": {:hex, :connection, "1.1.0", "ff2a49c4b75b6fb3e674bfc5536451607270aac754ffd1bdfe175abe4a6d7a68", [:mix], [], "hexpm", "722c1eb0a418fbe91ba7bd59a47e28008a189d47e37e0e7bb85585a016b2869c"},
65
"credo": {:hex, :credo, "1.6.7", "323f5734350fd23a456f2688b9430e7d517afb313fbd38671b8a4449798a7854", [:mix], [{:bunt, "~> 0.2.1", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "41e110bfb007f7eda7f897c10bf019ceab9a0b269ce79f015d54b0dcf4fc7dd3"},
7-
"db_connection": {:hex, :db_connection, "2.4.3", "3b9aac9f27347ec65b271847e6baeb4443d8474289bd18c1d6f4de655b70c94d", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "c127c15b0fa6cfb32eed07465e05da6c815b032508d4ed7c116122871df73c12"},
6+
"db_connection": {:hex, :db_connection, "2.5.0", "bb6d4f30d35ded97b29fe80d8bd6f928a1912ca1ff110831edcd238a1973652c", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "c92d5ba26cd69ead1ff7582dbb860adeedfff39774105a4f1c92cbb654b55aa2"},
87
"decimal": {:hex, :decimal, "2.0.0", "a78296e617b0f5dd4c6caf57c714431347912ffb1d0842e998e9792b5642d697", [:mix], [], "hexpm", "34666e9c55dea81013e77d9d87370fe6cb6291d1ef32f46a1600230b1d44f577"},
98
"deep_merge": {:hex, :deep_merge, "1.0.0", "b4aa1a0d1acac393bdf38b2291af38cb1d4a52806cf7a4906f718e1feb5ee961", [:mix], [], "hexpm", "ce708e5f094b9cd4e8f2be4f00d2f4250c4095be93f8cd6d018c753894885430"},
109
"earmark_parser": {:hex, :earmark_parser, "1.4.29", "149d50dcb3a93d9f3d6f3ecf18c918fb5a2d3c001b5d3305c926cddfbd33355b", [:mix], [], "hexpm", "4902af1b3eb139016aed210888748db8070b8125c2342ce3dcae4f38dcc63503"},
11-
"ecto": {:hex, :ecto, "3.9.4", "3ee68e25dbe0c36f980f1ba5dd41ee0d3eb0873bccae8aeaf1a2647242bffa35", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "de5f988c142a3aa4ec18b85a4ec34a2390b65b24f02385c1144252ff6ff8ee75"},
12-
"ecto_sql": {:hex, :ecto_sql, "3.9.2", "34227501abe92dba10d9c3495ab6770e75e79b836d114c41108a4bf2ce200ad5", [:mix], [{:db_connection, "~> 2.4.1 or ~> 2.5", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.9.2", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.6.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.16.0 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1 or ~> 2.2", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "1eb5eeb4358fdbcd42eac11c1fbd87e3affd7904e639d77903c1358b2abd3f70"},
10+
"ecto": {:hex, :ecto, "3.10.0", "1a088843f42a1917f2ff2a9191d3b5995db10faeb9fa8c1a8f8ebcdf39a70161", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "4a8339a6acc0500516cf94ef074acb9c7f7c75360e45bf88f5c3a4577116686f"},
11+
"ecto_sql": {:hex, :ecto_sql, "3.10.1", "6ea6b3036a0b0ca94c2a02613fd9f742614b5cfe494c41af2e6571bb034dd94c", [:mix], [{:db_connection, "~> 2.4.1 or ~> 2.5", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.10.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.6.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.16.0 or ~> 0.17.0 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1 or ~> 2.2", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "f6a25bdbbd695f12c8171eaff0851fa4c8e72eec1e98c7364402dda9ce11c56b"},
1312
"elixir_make": {:hex, :elixir_make, "0.6.3", "bc07d53221216838d79e03a8019d0839786703129599e9619f4ab74c8c096eac", [:mix], [], "hexpm", "f5cbd651c5678bcaabdbb7857658ee106b12509cd976c2c2fca99688e1daf716"},
1413
"ex_doc": {:hex, :ex_doc, "0.29.1", "b1c652fa5f92ee9cf15c75271168027f92039b3877094290a75abcaac82a9f77", [:mix], [{:earmark_parser, "~> 1.4.19", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "b7745fa6374a36daf484e2a2012274950e084815b936b1319aeebcf7809574f6"},
1514
"exqlite": {:hex, :exqlite, "0.11.8", "b6bf596caa92d4811c303ddd8544dc9493a5351a18d2d16e1f85f977705cb39f", [:make, :mix], [{:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "8591959284f1012c0d8cb26a09d5d9ba0bc0559cbeaf26fb8fbef14213d73bc0"},
@@ -20,7 +19,7 @@
2019
"makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"},
2120
"myxql": {:hex, :myxql, "0.6.3", "3d77683a09f1227abb8b73d66b275262235c5cae68182f0cfa5897d72a03700e", [:mix], [{:db_connection, "~> 2.4.1 or ~> 2.5", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:geo, "~> 3.4", [hex: :geo, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "af9eb517ddaced5c5c28e8749015493757fd4413f2cfccea449c466d405d9f51"},
2221
"nimble_parsec": {:hex, :nimble_parsec, "1.2.3", "244836e6e3f1200c7f30cb56733fd808744eca61fd182f731eac4af635cc6d0b", [:mix], [], "hexpm", "c8d789e39b9131acf7b99291e93dae60ab48ef14a7ee9d58c6964f59efb570b0"},
23-
"postgrex": {:hex, :postgrex, "0.16.5", "fcc4035cc90e23933c5d69a9cd686e329469446ef7abba2cf70f08e2c4b69810", [:mix], [{:connection, "~> 1.1", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "edead639dc6e882618c01d8fc891214c481ab9a3788dfe38dd5e37fd1d5fb2e8"},
22+
"postgrex": {:hex, :postgrex, "0.17.0", "1ea81cb0820079bcedd880379357cfc9faf70bc8fee3a87054b13fcb646c6150", [:mix], [{:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "ea670562ed62a5ca40aa4689290167a97b0712f59f7e318d6ce9eb253f52e02e"},
2423
"statistex": {:hex, :statistex, "1.0.0", "f3dc93f3c0c6c92e5f291704cf62b99b553253d7969e9a5fa713e5481cd858a5", [:mix], [], "hexpm", "ff9d8bee7035028ab4742ff52fc80a2aa35cece833cf5319009b52f1b5a86c27"},
2524
"telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"},
2625
"temp": {:hex, :temp, "0.4.7", "2c78482cc2294020a4bc0c95950b907ff386523367d4e63308a252feffbea9f2", [:mix], [], "hexpm", "6af19e7d6a85a427478be1021574d1ae2a1e1b90882586f06bde76c63cd03e0d"},

test/ecto/adapters/sqlite3/connection_test.exs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,11 +1148,11 @@ defmodule Ecto.Adapters.SQLite3.ConnectionTest do
11481148
assert_raise Ecto.QueryError, fn ->
11491149
update_all(query)
11501150
end
1151-
11521151
end
11531152

11541153
test "update all with subquery" do
11551154
sub = from(p in Schema, where: p.x > ^10)
1155+
11561156
query =
11571157
Schema
11581158
|> join(:inner, [p], p2 in subquery(sub), on: p.id == p2.id)
@@ -1162,9 +1162,9 @@ defmodule Ecto.Adapters.SQLite3.ConnectionTest do
11621162
Ecto.Adapter.Queryable.plan_query(:update_all, Ecto.Adapters.SQLite3, query)
11631163

11641164
assert update_all(planned_query) ==
1165-
~s{UPDATE "schema" AS s0 SET "x" = ? FROM } <>
1166-
~s{(SELECT ss0."id" AS "id", ss0."x" AS "x", ss0."y" AS "y", ss0."z" AS "z", ss0."w" AS "w", ss0."meta" AS "meta" FROM "schema" AS ss0 WHERE (ss0."x" > ?)) } <>
1167-
~s{AS s1 WHERE (s0."id" = s1."id")}
1165+
~s{UPDATE "schema" AS s0 SET "x" = ? FROM } <>
1166+
~s{(SELECT ss0."id" AS "id", ss0."x" AS "x", ss0."y" AS "y", ss0."z" AS "z", ss0."w" AS "w", ss0."meta" AS "meta" FROM "schema" AS ss0 WHERE (ss0."x" > ?)) } <>
1167+
~s{AS s1 WHERE (s0."id" = s1."id")}
11681168

11691169
assert cast_params == [100, 10]
11701170
assert dump_params == [100, 10]
@@ -1823,7 +1823,6 @@ defmodule Ecto.Adapters.SQLite3.ConnectionTest do
18231823

18241824
assert query ==
18251825
~s{UPDATE "schema" SET "x" = ?, "y" = ? WHERE "id" = ? RETURNING "z"}
1826-
18271826
end
18281827

18291828
test "delete" do
@@ -1902,7 +1901,7 @@ defmodule Ecto.Adapters.SQLite3.ConnectionTest do
19021901
on_update: :update_all
19031902
}, [null: false]},
19041903
{:add, :category_9, %Reference{table: :categories, on_delete: :restrict}, []},
1905-
{:add, :category_10, %Reference{table: :categories, on_update: :restrict}, []},
1904+
{:add, :category_10, %Reference{table: :categories, on_update: :restrict}, []}
19061905
]}
19071906

19081907
assert execute_ddl(create) == [
@@ -2106,20 +2105,20 @@ defmodule Ecto.Adapters.SQLite3.ConnectionTest do
21062105
]}
21072106

21082107
assert_raise ArgumentError,
2109-
"unsupported type `{:a, :b, :c}`. " <>
2110-
"The type can either be an atom, a string or a tuple of the form " <>
2111-
"`{:map, t}` or `{:array, t}` where `t` itself follows the same conditions.",
2112-
fn -> execute_ddl(create) end
2108+
"unsupported type `{:a, :b, :c}`. " <>
2109+
"The type can either be an atom, a string or a tuple of the form " <>
2110+
"`{:map, t}` or `{:array, t}` where `t` itself follows the same conditions.",
2111+
fn -> execute_ddl(create) end
21132112
end
21142113

2115-
21162114
test "drop table" do
21172115
drop = {:drop, table(:posts)}
21182116
assert execute_ddl(drop) == [~s|DROP TABLE "posts"|]
21192117
end
21202118

21212119
test "drop table with prefix" do
21222120
drop = {:drop, table(:posts, prefix: :foo)}
2121+
21232122
assert_raise ArgumentError, "SQLite3 does not support table prefixes", fn ->
21242123
execute_ddl(drop)
21252124
end
@@ -2151,6 +2150,7 @@ defmodule Ecto.Adapters.SQLite3.ConnectionTest do
21512150
alter =
21522151
{:alter, table(:posts, prefix: :foo),
21532152
[{:add, :author_id, %Reference{table: :author}, []}]}
2153+
21542154
assert_raise ArgumentError, "SQLite3 does not support table prefixes", fn ->
21552155
execute_ddl(alter)
21562156
end
@@ -2339,6 +2339,7 @@ defmodule Ecto.Adapters.SQLite3.ConnectionTest do
23392339

23402340
test "rename table with prefix" do
23412341
rename = {:rename, table(:posts, prefix: :foo), table(:new_posts, prefix: :foo)}
2342+
23422343
assert_raise ArgumentError, "SQLite3 does not support table prefixes", fn ->
23432344
execute_ddl(rename)
23442345
end

0 commit comments

Comments
 (0)