Skip to content

Commit

Permalink
Ecto 2.2.2 compatibility. (#198)
Browse files Browse the repository at this point in the history
* Update references to point to Ecto 2.2.2.

* Advance to "Set foreign key type to same used on primary keys (#2204)" commit from 08 Sep 2017.

Integration tests are broken at this commit.

* Adapt for breaking API change WRT references.

IMHO this was not an appropriate change for a double-dot release.

* Require Ecto 2.2.2 and up. There was a breaking API change from 2.2.1 to 2.2.2.
  • Loading branch information
scouten authored Sep 11, 2017
1 parent 17f39db commit 435f82a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 24 deletions.
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ defmodule Sqlite.Ecto2.Mixfile do
{:dogma, "~> 0.1", only: :dev},
{:esqlite, "~> 0.2.3"},
{:ex_doc, "~> 0.16", only: :dev},
{:ecto, "~> 2.2.0"},
{:ecto, "~> 2.2.2"},
{:poison, "~> 2.2 or ~> 3.0", optional: true},
{:postgrex, "~> 0.13.0", optional: true},
{:sbroker, "~> 1.0"},
Expand Down
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"decimal": {:hex, :decimal, "1.4.0", "fac965ce71a46aab53d3a6ce45662806bdd708a4a95a65cde8a12eb0124a1333", [:mix], [], "hexpm"},
"dogma": {:hex, :dogma, "0.1.15", "5bceba9054b2b97a4adcb2ab4948ca9245e5258b883946e82d32f785340fd411", [:mix], [{:poison, ">= 2.0.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"},
"earmark": {:hex, :earmark, "1.2.2", "f718159d6b65068e8daeef709ccddae5f7fdc770707d82e7d126f584cd925b74", [:mix], [], "hexpm"},
"ecto": {:hex, :ecto, "2.2.1", "ccc6fd304f9bb785f2c3cfd0ee8da6bad6544ab12ca5f7162b20a743d938417c", [], [{:db_connection, "~> 1.1", [hex: :db_connection, repo: "hexpm", optional: true]}, {:decimal, "~> 1.2", [hex: :decimal, repo: "hexpm", optional: false]}, {:mariaex, "~> 0.8.0", [hex: :mariaex, repo: "hexpm", optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.13.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm"},
"ecto": {:hex, :ecto, "2.2.2", "e9bd6ebc044eaaab1cb369e3465686d8aca830aa5bf545ef2bae000a3d42c54b", [], [{:db_connection, "~> 1.1", [hex: :db_connection, repo: "hexpm", optional: true]}, {:decimal, "~> 1.2", [hex: :decimal, repo: "hexpm", optional: false]}, {:mariaex, "~> 0.8.0", [hex: :mariaex, repo: "hexpm", optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.13.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm"},
"esqlite": {:hex, :esqlite, "0.2.3", "1a8b60877fdd3d50a8a84b342db04032c0231cc27ecff4ddd0d934485d4c0cd5", [:rebar3], [], "hexpm"},
"ex_doc": {:hex, :ex_doc, "0.16.3", "cd2a4cfe5d26e37502d3ec776702c72efa1adfa24ed9ce723bb565f4c30bd31a", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"},
"hackney": {:hex, :hackney, "1.7.1", "e238c52c5df3c3b16ce613d3a51c7220a784d734879b1e231c9babd433ac1cb4", [:rebar3], [{:certifi, "1.0.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "4.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"},
Expand Down
45 changes: 23 additions & 22 deletions test/sqlite_ecto_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -802,8 +802,9 @@ defmodule Sqlite.Ecto2.Test do

# DDL

import Ecto.Migration, only: [table: 1, table: 2, index: 2, index: 3, references: 1,
references: 2, constraint: 2, constraint: 3]
alias Ecto.Migration.Reference
import Ecto.Migration, only: [table: 1, table: 2, index: 2, index: 3,
constraint: 2, constraint: 3]

test "executing a string during migration" do
assert execute_ddl("example") == ["example"]
Expand Down Expand Up @@ -874,7 +875,7 @@ defmodule Sqlite.Ecto2.Test do

test "create table with prefix" do
create = {:create, table(:posts, prefix: :foo),
[{:add, :category_0, references(:categories), []}]}
[{:add, :category_0, %Reference{table: :categories}, []}]}

assert execute_ddl(create) == ["""
CREATE TABLE "foo"."posts"
Expand All @@ -885,7 +886,7 @@ defmodule Sqlite.Ecto2.Test do
test "create table with comment on columns and table" do
create = {:create, table(:posts, comment: "comment"),
[
{:add, :category_0, references(:categories), [comment: "column comment"]},
{:add, :category_0, %Reference{table: :categories}, [comment: "column comment"]},
{:add, :created_at, :timestamp, []},
{:add, :updated_at, :timestamp, [comment: "column comment 2"]}
]}
Expand All @@ -898,7 +899,7 @@ defmodule Sqlite.Ecto2.Test do

test "create table with comment on table" do
create = {:create, table(:posts, comment: "table comment"),
[{:add, :category_0, references(:categories), []}]}
[{:add, :category_0, %Reference{table: :categories}, []}]}
assert execute_ddl(create) == [remove_newlines("""
CREATE TABLE "posts"
("category_0" INTEGER CONSTRAINT "posts_category_0_fkey" REFERENCES "categories"("id"))
Expand All @@ -909,7 +910,7 @@ defmodule Sqlite.Ecto2.Test do
test "create table with comment on columns" do
create = {:create, table(:posts),
[
{:add, :category_0, references(:categories), [comment: "column comment"]},
{:add, :category_0, %Reference{table: :categories}, [comment: "column comment"]},
{:add, :created_at, :timestamp, []},
{:add, :updated_at, :timestamp, [comment: "column comment 2"]}
]}
Expand All @@ -923,15 +924,15 @@ defmodule Sqlite.Ecto2.Test do
test "create table with references" do
create = {:create, table(:posts),
[{:add, :id, :serial, [primary_key: true]},
{:add, :category_0, references(:categories), []},
{:add, :category_1, references(:categories, name: :foo_bar), []},
{:add, :category_2, references(:categories, on_delete: :nothing), []},
{:add, :category_3, references(:categories, on_delete: :delete_all), [null: false]},
{:add, :category_4, references(:categories, on_delete: :nilify_all), []},
{:add, :category_5, references(:categories, on_update: :nothing), []},
{:add, :category_6, references(:categories, on_update: :update_all), [null: false]},
{:add, :category_7, references(:categories, on_update: :nilify_all), []},
{:add, :category_8, references(:categories, on_delete: :nilify_all, on_update: :update_all), [null: false]}]}
{:add, :category_0, %Reference{table: :categories}, []},
{:add, :category_1, %Reference{table: :categories, name: :foo_bar}, []},
{:add, :category_2, %Reference{table: :categories, on_delete: :nothing}, []},
{:add, :category_3, %Reference{table: :categories, on_delete: :delete_all}, [null: false]},
{:add, :category_4, %Reference{table: :categories, on_delete: :nilify_all}, []},
{:add, :category_5, %Reference{table: :categories, on_update: :nothing}, []},
{:add, :category_6, %Reference{table: :categories, on_update: :update_all}, [null: false]},
{:add, :category_7, %Reference{table: :categories, on_update: :nilify_all}, []},
{:add, :category_8, %Reference{table: :categories, on_delete: :nilify_all, on_update: :update_all}, [null: false]}]}

assert execute_ddl(create) == ["""
CREATE TABLE "posts" ("id" INTEGER PRIMARY KEY AUTOINCREMENT,
Expand All @@ -950,11 +951,11 @@ defmodule Sqlite.Ecto2.Test do
test "create table with references including prefixes" do
create = {:create, table(:posts, prefix: :foo),
[{:add, :id, :serial, [primary_key: true]},
{:add, :category_0, references(:categories, prefix: :foo), []},
{:add, :category_1, references(:categories, name: :foo_bar, prefix: :foo), []},
{:add, :category_2, references(:categories, on_delete: :nothing, prefix: :foo), []},
{:add, :category_3, references(:categories, on_delete: :delete_all, prefix: :foo), [null: false]},
{:add, :category_4, references(:categories, on_delete: :nilify_all, prefix: :foo), []}]}
{:add, :category_0, %Reference{table: :categories}, []},
{:add, :category_1, %Reference{table: :categories, name: :foo_bar}, []},
{:add, :category_2, %Reference{table: :categories, on_delete: :nothing}, []},
{:add, :category_3, %Reference{table: :categories, on_delete: :delete_all}, [null: false]},
{:add, :category_4, %Reference{table: :categories, on_delete: :nilify_all}, []}]}

assert execute_ddl(create) == ["""
CREATE TABLE "foo"."posts" ("id" INTEGER PRIMARY KEY AUTOINCREMENT,
Expand Down Expand Up @@ -1047,7 +1048,7 @@ defmodule Sqlite.Ecto2.Test do
test "alter table" do
alter = {:alter, table(:posts),
[{:add, :title, :string, [default: "Untitled", size: 100, null: false]},
{:add, :author_id, references(:author), []}]}
{:add, :author_id, %Reference{table: :author}, []}]}
assert execute_ddl(alter) == [
remove_newlines(~s|ALTER TABLE "posts" ADD COLUMN "title" TEXT DEFAULT 'Untitled' NOT NULL|),
remove_newlines(~s|ALTER TABLE "posts" ADD COLUMN "author_id" INTEGER CONSTRAINT "posts_author_id_fkey" REFERENCES "author"("id")|)]
Expand All @@ -1065,7 +1066,7 @@ defmodule Sqlite.Ecto2.Test do
test "alter table with prefix" do
alter = {:alter, table(:posts, prefix: :foo),
[{:add, :title, :string, [default: "Untitled", size: 100, null: false]},
{:add, :author_id, references(:author, prefix: :foo), []}]}
{:add, :author_id, %Reference{table: :author}, []}]}

assert execute_ddl(alter) == [
remove_newlines(~s|ALTER TABLE "foo"."posts" ADD COLUMN "title" TEXT DEFAULT 'Untitled' NOT NULL|),
Expand Down

0 comments on commit 435f82a

Please sign in to comment.