@@ -802,8 +802,9 @@ defmodule Sqlite.Ecto2.Test do
802802
803803 # DDL
804804
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 ]
807808
808809 test "executing a string during migration" do
809810 assert execute_ddl ( "example" ) == [ "example" ]
@@ -874,7 +875,7 @@ defmodule Sqlite.Ecto2.Test do
874875
875876 test "create table with prefix" do
876877 create = { :create , table ( :posts , prefix: :foo ) ,
877- [ { :add , :category_0 , references ( : categories) , [ ] } ] }
878+ [ { :add , :category_0 , % Reference { table: : categories} , [ ] } ] }
878879
879880 assert execute_ddl ( create ) == [ """
880881 CREATE TABLE "foo"."posts"
@@ -885,7 +886,7 @@ defmodule Sqlite.Ecto2.Test do
885886 test "create table with comment on columns and table" do
886887 create = { :create , table ( :posts , comment: "comment" ) ,
887888 [
888- { :add , :category_0 , references ( : categories) , [ comment: "column comment" ] } ,
889+ { :add , :category_0 , % Reference { table: : categories} , [ comment: "column comment" ] } ,
889890 { :add , :created_at , :timestamp , [ ] } ,
890891 { :add , :updated_at , :timestamp , [ comment: "column comment 2" ] }
891892 ] }
@@ -898,7 +899,7 @@ defmodule Sqlite.Ecto2.Test do
898899
899900 test "create table with comment on table" do
900901 create = { :create , table ( :posts , comment: "table comment" ) ,
901- [ { :add , :category_0 , references ( : categories) , [ ] } ] }
902+ [ { :add , :category_0 , % Reference { table: : categories} , [ ] } ] }
902903 assert execute_ddl ( create ) == [ remove_newlines ( """
903904 CREATE TABLE "posts"
904905 ("category_0" INTEGER CONSTRAINT "posts_category_0_fkey" REFERENCES "categories"("id"))
@@ -909,7 +910,7 @@ defmodule Sqlite.Ecto2.Test do
909910 test "create table with comment on columns" do
910911 create = { :create , table ( :posts ) ,
911912 [
912- { :add , :category_0 , references ( : categories) , [ comment: "column comment" ] } ,
913+ { :add , :category_0 , % Reference { table: : categories} , [ comment: "column comment" ] } ,
913914 { :add , :created_at , :timestamp , [ ] } ,
914915 { :add , :updated_at , :timestamp , [ comment: "column comment 2" ] }
915916 ] }
@@ -923,15 +924,15 @@ defmodule Sqlite.Ecto2.Test do
923924 test "create table with references" do
924925 create = { :create , table ( :posts ) ,
925926 [ { :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 ] } ] }
935936
936937 assert execute_ddl ( create ) == [ """
937938 CREATE TABLE "posts" ("id" INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -950,11 +951,11 @@ defmodule Sqlite.Ecto2.Test do
950951 test "create table with references including prefixes" do
951952 create = { :create , table ( :posts , prefix: :foo ) ,
952953 [ { :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 } , [ ] } ] }
958959
959960 assert execute_ddl ( create ) == [ """
960961 CREATE TABLE "foo"."posts" ("id" INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -1047,7 +1048,7 @@ defmodule Sqlite.Ecto2.Test do
10471048 test "alter table" do
10481049 alter = { :alter , table ( :posts ) ,
10491050 [ { :add , :title , :string , [ default: "Untitled" , size: 100 , null: false ] } ,
1050- { :add , :author_id , references ( : author) , [ ] } ] }
1051+ { :add , :author_id , % Reference { table: : author} , [ ] } ] }
10511052 assert execute_ddl ( alter ) == [
10521053 remove_newlines ( ~s| ALTER TABLE "posts" ADD COLUMN "title" TEXT DEFAULT 'Untitled' NOT NULL| ) ,
10531054 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
10651066 test "alter table with prefix" do
10661067 alter = { :alter , table ( :posts , prefix: :foo ) ,
10671068 [ { :add , :title , :string , [ default: "Untitled" , size: 100 , null: false ] } ,
1068- { :add , :author_id , references ( :author , prefix: :foo ) , [ ] } ] }
1069+ { :add , :author_id , % Reference { table: :author } , [ ] } ] }
10691070
10701071 assert execute_ddl ( alter ) == [
10711072 remove_newlines ( ~s| ALTER TABLE "foo"."posts" ADD COLUMN "title" TEXT DEFAULT 'Untitled' NOT NULL| ) ,
0 commit comments