@@ -242,7 +242,7 @@ defmodule Ecto.Adapters.MyXQLTest do
242242 |> select ( [ :id , :parent_id ] )
243243
244244 cte_query = initial_query |> union_all ( ^ iteration_query )
245-
245+
246246 breadcrumbs_query =
247247 "tree"
248248 |> recursive_ctes ( true )
@@ -1101,6 +1101,20 @@ defmodule Ecto.Adapters.MyXQLTest do
11011101 """ |> remove_newlines ]
11021102 end
11031103
1104+ test "create table with comment on columns and table" do
1105+ create = { :create , table ( :posts , comment: "comment" , prefix: :foo ) ,
1106+ [
1107+ { :add , :category_0 , % Reference { table: :categories } , [ comment: "column comment" ] } ,
1108+ { :add , :created_at , :datetime , [ ] } ,
1109+ { :add , :updated_at , :datetime , [ comment: "column comment 2" ] }
1110+ ] }
1111+ assert execute_ddl ( create ) == [ """
1112+ CREATE TABLE `foo`.`posts` (`category_0` BIGINT UNSIGNED COMMENT 'column comment',
1113+ CONSTRAINT `posts_category_0_fkey` FOREIGN KEY (`category_0`) REFERENCES `foo`.`categories`(`id`),
1114+ `created_at` datetime, `updated_at` datetime COMMENT 'column comment 2') COMMENT = 'comment' ENGINE = INNODB
1115+ """ |> remove_newlines ]
1116+ end
1117+
11041118 test "create table with engine" do
11051119 create = { :create , table ( :posts , engine: :myisam ) ,
11061120 [ { :add , :id , :serial , [ primary_key: true ] } ] }
@@ -1335,6 +1349,24 @@ defmodule Ecto.Adapters.MyXQLTest do
13351349 """ |> remove_newlines ]
13361350 end
13371351
1352+ test "alter table with comments on table and columns" do
1353+ alter = { :alter , table ( :posts , comment: "table comment" ) ,
1354+ [ { :add , :title , :string , [ default: "Untitled" , size: 100 , null: false , comment: "column comment" ] } ,
1355+ { :modify , :price , :numeric , [ precision: 8 , scale: 2 , null: true ] } ,
1356+ { :modify , :permalink_id , % Reference { table: :permalinks } , [ null: false , comment: "column comment 2" ] } ,
1357+ { :remove , :summary } ] }
1358+
1359+ assert execute_ddl ( alter ) == [ """
1360+ ALTER TABLE `posts`
1361+ ADD `title` varchar(100) DEFAULT 'Untitled' NOT NULL COMMENT 'column comment',
1362+ MODIFY `price` numeric(8,2) NULL,
1363+ MODIFY `permalink_id` BIGINT UNSIGNED NOT NULL COMMENT 'column comment 2',
1364+ ADD CONSTRAINT `posts_permalink_id_fkey` FOREIGN KEY (`permalink_id`) REFERENCES `permalinks`(`id`),
1365+ DROP `summary`
1366+ """ |> remove_newlines ,
1367+ ~s| ALTER TABLE `posts` COMMENT 'table comment'| ]
1368+ end
1369+
13381370 test "alter table with prefix" do
13391371 alter = { :alter , table ( :posts , prefix: :foo ) ,
13401372 [ { :add , :author_id , % Reference { table: :author } , [ ] } ,
0 commit comments