@@ -802,8 +802,9 @@ defmodule Sqlite.Ecto2.Test do
802
802
803
803
# DDL
804
804
805
- import Ecto.Migration , only: [ table: 1 , table: 2 , index: 2 , index: 3 , references: 1 ,
806
- references: 2 , constraint: 2 , constraint: 3 ]
805
+ alias Ecto.Migration.Reference
806
+ import Ecto.Migration , only: [ table: 1 , table: 2 , index: 2 , index: 3 ,
807
+ constraint: 2 , constraint: 3 ]
807
808
808
809
test "executing a string during migration" do
809
810
assert execute_ddl ( "example" ) == [ "example" ]
@@ -874,7 +875,7 @@ defmodule Sqlite.Ecto2.Test do
874
875
875
876
test "create table with prefix" do
876
877
create = { :create , table ( :posts , prefix: :foo ) ,
877
- [ { :add , :category_0 , references ( : categories) , [ ] } ] }
878
+ [ { :add , :category_0 , % Reference { table: : categories} , [ ] } ] }
878
879
879
880
assert execute_ddl ( create ) == [ """
880
881
CREATE TABLE "foo"."posts"
@@ -885,7 +886,7 @@ defmodule Sqlite.Ecto2.Test do
885
886
test "create table with comment on columns and table" do
886
887
create = { :create , table ( :posts , comment: "comment" ) ,
887
888
[
888
- { :add , :category_0 , references ( : categories) , [ comment: "column comment" ] } ,
889
+ { :add , :category_0 , % Reference { table: : categories} , [ comment: "column comment" ] } ,
889
890
{ :add , :created_at , :timestamp , [ ] } ,
890
891
{ :add , :updated_at , :timestamp , [ comment: "column comment 2" ] }
891
892
] }
@@ -898,7 +899,7 @@ defmodule Sqlite.Ecto2.Test do
898
899
899
900
test "create table with comment on table" do
900
901
create = { :create , table ( :posts , comment: "table comment" ) ,
901
- [ { :add , :category_0 , references ( : categories) , [ ] } ] }
902
+ [ { :add , :category_0 , % Reference { table: : categories} , [ ] } ] }
902
903
assert execute_ddl ( create ) == [ remove_newlines ( """
903
904
CREATE TABLE "posts"
904
905
("category_0" INTEGER CONSTRAINT "posts_category_0_fkey" REFERENCES "categories"("id"))
@@ -909,7 +910,7 @@ defmodule Sqlite.Ecto2.Test do
909
910
test "create table with comment on columns" do
910
911
create = { :create , table ( :posts ) ,
911
912
[
912
- { :add , :category_0 , references ( : categories) , [ comment: "column comment" ] } ,
913
+ { :add , :category_0 , % Reference { table: : categories} , [ comment: "column comment" ] } ,
913
914
{ :add , :created_at , :timestamp , [ ] } ,
914
915
{ :add , :updated_at , :timestamp , [ comment: "column comment 2" ] }
915
916
] }
@@ -923,15 +924,15 @@ defmodule Sqlite.Ecto2.Test do
923
924
test "create table with references" do
924
925
create = { :create , table ( :posts ) ,
925
926
[ { :add , :id , :serial , [ primary_key: true ] } ,
926
- { :add , :category_0 , references ( : categories) , [ ] } ,
927
- { :add , :category_1 , references ( : categories, name: :foo_bar ) , [ ] } ,
928
- { :add , :category_2 , references ( : categories, on_delete: :nothing ) , [ ] } ,
929
- { :add , :category_3 , references ( : categories, on_delete: :delete_all ) , [ null: false ] } ,
930
- { :add , :category_4 , references ( : categories, on_delete: :nilify_all ) , [ ] } ,
931
- { :add , :category_5 , references ( : categories, on_update: :nothing ) , [ ] } ,
932
- { :add , :category_6 , references ( : categories, on_update: :update_all ) , [ null: false ] } ,
933
- { :add , :category_7 , references ( : categories, on_update: :nilify_all ) , [ ] } ,
934
- { :add , :category_8 , references ( : categories, on_delete: :nilify_all , on_update: :update_all ) , [ null: false ] } ] }
927
+ { :add , :category_0 , % Reference { table: : categories} , [ ] } ,
928
+ { :add , :category_1 , % Reference { table: : categories, name: :foo_bar } , [ ] } ,
929
+ { :add , :category_2 , % Reference { table: : categories, on_delete: :nothing } , [ ] } ,
930
+ { :add , :category_3 , % Reference { table: : categories, on_delete: :delete_all } , [ null: false ] } ,
931
+ { :add , :category_4 , % Reference { table: : categories, on_delete: :nilify_all } , [ ] } ,
932
+ { :add , :category_5 , % Reference { table: : categories, on_update: :nothing } , [ ] } ,
933
+ { :add , :category_6 , % Reference { table: : categories, on_update: :update_all } , [ null: false ] } ,
934
+ { :add , :category_7 , % Reference { table: : categories, on_update: :nilify_all } , [ ] } ,
935
+ { :add , :category_8 , % Reference { table: : categories, on_delete: :nilify_all , on_update: :update_all } , [ null: false ] } ] }
935
936
936
937
assert execute_ddl ( create ) == [ """
937
938
CREATE TABLE "posts" ("id" INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -950,11 +951,11 @@ defmodule Sqlite.Ecto2.Test do
950
951
test "create table with references including prefixes" do
951
952
create = { :create , table ( :posts , prefix: :foo ) ,
952
953
[ { :add , :id , :serial , [ primary_key: true ] } ,
953
- { :add , :category_0 , references ( :categories , prefix: :foo ) , [ ] } ,
954
- { :add , :category_1 , references ( : categories, name: :foo_bar , prefix: :foo ) , [ ] } ,
955
- { :add , :category_2 , references ( : categories, on_delete: :nothing , prefix: :foo ) , [ ] } ,
956
- { :add , :category_3 , references ( : categories, on_delete: :delete_all , prefix: :foo ) , [ null: false ] } ,
957
- { :add , :category_4 , references ( : categories, on_delete: :nilify_all , prefix: :foo ) , [ ] } ] }
954
+ { :add , :category_0 , % Reference { table: :categories } , [ ] } ,
955
+ { :add , :category_1 , % Reference { table: : categories, name: :foo_bar } , [ ] } ,
956
+ { :add , :category_2 , % Reference { table: : categories, on_delete: :nothing } , [ ] } ,
957
+ { :add , :category_3 , % Reference { table: : categories, on_delete: :delete_all } , [ null: false ] } ,
958
+ { :add , :category_4 , % Reference { table: : categories, on_delete: :nilify_all } , [ ] } ] }
958
959
959
960
assert execute_ddl ( create ) == [ """
960
961
CREATE TABLE "foo"."posts" ("id" INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -1047,7 +1048,7 @@ defmodule Sqlite.Ecto2.Test do
1047
1048
test "alter table" do
1048
1049
alter = { :alter , table ( :posts ) ,
1049
1050
[ { :add , :title , :string , [ default: "Untitled" , size: 100 , null: false ] } ,
1050
- { :add , :author_id , references ( : author) , [ ] } ] }
1051
+ { :add , :author_id , % Reference { table: : author} , [ ] } ] }
1051
1052
assert execute_ddl ( alter ) == [
1052
1053
remove_newlines ( ~s| ALTER TABLE "posts" ADD COLUMN "title" TEXT DEFAULT 'Untitled' NOT NULL| ) ,
1053
1054
remove_newlines ( ~s| ALTER TABLE "posts" ADD COLUMN "author_id" INTEGER CONSTRAINT "posts_author_id_fkey" REFERENCES "author"("id")| ) ]
@@ -1065,7 +1066,7 @@ defmodule Sqlite.Ecto2.Test do
1065
1066
test "alter table with prefix" do
1066
1067
alter = { :alter , table ( :posts , prefix: :foo ) ,
1067
1068
[ { :add , :title , :string , [ default: "Untitled" , size: 100 , null: false ] } ,
1068
- { :add , :author_id , references ( :author , prefix: :foo ) , [ ] } ] }
1069
+ { :add , :author_id , % Reference { table: :author } , [ ] } ] }
1069
1070
1070
1071
assert execute_ddl ( alter ) == [
1071
1072
remove_newlines ( ~s| ALTER TABLE "foo"."posts" ADD COLUMN "title" TEXT DEFAULT 'Untitled' NOT NULL| ) ,
0 commit comments