Skip to content

Commit 586900b

Browse files
committed
Collation is set without checking column type
1 parent c520dc5 commit 586900b

File tree

6 files changed

+29
-58
lines changed

6 files changed

+29
-58
lines changed

integration_test/myxql/migrations_test.exs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ defmodule Ecto.Integration.MigrationsTest do
5151
create table(:collate) do
5252
add :string, :string, collation: @collation
5353
add :varchar, :varchar, size: 255, collation: @collation
54-
add :integer, :integer, collation: @collation
5554
add :name_string, references(:collate_reference, type: :string, column: :name), collation: @collation
5655

5756
for type <- @text_variants do
@@ -163,10 +162,6 @@ defmodule Ecto.Integration.MigrationsTest do
163162
rows: [[@collation]]
164163
} = Ecto.Adapters.SQL.query!(PoolRepo, query.(type), [])
165164
end
166-
167-
assert %{
168-
rows: [[nil]]
169-
} = Ecto.Adapters.SQL.query!(PoolRepo, query.("integer"), [])
170165
end
171166
end
172167
end

integration_test/pg/migrations_test.exs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ defmodule Ecto.Integration.MigrationsTest do
6565
add type, type, collation: @collation
6666
end
6767

68-
add :integer, :integer, collation: @collation
6968
add :name_string, references(:collate_reference, type: :string, column: :name), collation: @collation
7069
end
7170

@@ -202,10 +201,6 @@ defmodule Ecto.Integration.MigrationsTest do
202201
rows: [[@collation]]
203202
} = Ecto.Adapters.SQL.query!(PoolRepo, query.(type), [])
204203
end
205-
206-
assert %{
207-
rows: [[nil]]
208-
} = Ecto.Adapters.SQL.query!(PoolRepo, query.("integer"), [])
209204
end
210205
end
211206
end

integration_test/tds/migrations_test.exs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ defmodule Ecto.Integration.MigrationsTest do
3737
add :nvarchar, :nvarchar, size: 255, collation: @collation
3838
add :text, :text, collation: @collation
3939
add :ntext, :ntext, collation: @collation
40-
add :integer, :integer, collation: @collation
4140
add :name_string, references(:collate_reference, type: :string, column: :name), collation: @collation
4241
end
4342

@@ -130,10 +129,6 @@ defmodule Ecto.Integration.MigrationsTest do
130129
rows: [[@collation]]
131130
} = Ecto.Adapters.SQL.query!(PoolRepo, query.(type), [])
132131
end
133-
134-
assert %{
135-
rows: [[nil]]
136-
} = Ecto.Adapters.SQL.query!(PoolRepo, query.("integer"), [])
137132
end
138133
end
139134
end

lib/ecto/adapters/myxql/connection.ex

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,13 +1171,13 @@ if Code.ensure_loaded?(MyXQL) do
11711171
quote_name(name),
11721172
?\s,
11731173
reference_column_type(ref.type, opts),
1174-
column_options(ref.type, opts),
1174+
column_options(opts),
11751175
reference_expr(ref, table, name)
11761176
]
11771177
end
11781178

11791179
defp column_definition(_table, {:add, name, type, opts}) do
1180-
[quote_name(name), ?\s, column_type(type, opts), column_options(type, opts)]
1180+
[quote_name(name), ?\s, column_type(type, opts), column_options(opts)]
11811181
end
11821182

11831183
defp column_changes(table, columns) do
@@ -1194,13 +1194,13 @@ if Code.ensure_loaded?(MyXQL) do
11941194
quote_name(name),
11951195
?\s,
11961196
reference_column_type(ref.type, opts),
1197-
column_options(ref.type, opts),
1197+
column_options(opts),
11981198
constraint_expr(ref, table, name)
11991199
]
12001200
end
12011201

12021202
defp column_change(_table, {:add, name, type, opts}) do
1203-
["ADD ", quote_name(name), ?\s, column_type(type, opts), column_options(type, opts)]
1203+
["ADD ", quote_name(name), ?\s, column_type(type, opts), column_options(opts)]
12041204
end
12051205

12061206
defp column_change(table, {:add_if_not_exists, name, %Reference{} = ref, opts}) do
@@ -1209,7 +1209,7 @@ if Code.ensure_loaded?(MyXQL) do
12091209
quote_name(name),
12101210
?\s,
12111211
reference_column_type(ref.type, opts),
1212-
column_options(ref.type, opts),
1212+
column_options(opts),
12131213
constraint_if_not_exists_expr(ref, table, name)
12141214
]
12151215
end
@@ -1220,7 +1220,7 @@ if Code.ensure_loaded?(MyXQL) do
12201220
quote_name(name),
12211221
?\s,
12221222
column_type(type, opts),
1223-
column_options(type, opts)
1223+
column_options(opts)
12241224
]
12251225
end
12261226

@@ -1231,7 +1231,7 @@ if Code.ensure_loaded?(MyXQL) do
12311231
quote_name(name),
12321232
?\s,
12331233
reference_column_type(ref.type, opts),
1234-
column_options(ref.type, opts),
1234+
column_options(opts),
12351235
constraint_expr(ref, table, name)
12361236
]
12371237
end
@@ -1243,7 +1243,7 @@ if Code.ensure_loaded?(MyXQL) do
12431243
quote_name(name),
12441244
?\s,
12451245
column_type(type, opts),
1246-
column_options(type, opts)
1246+
column_options(opts)
12471247
]
12481248
end
12491249

@@ -1265,7 +1265,7 @@ if Code.ensure_loaded?(MyXQL) do
12651265
defp column_change(_table, {:remove_if_exists, name}),
12661266
do: ["DROP IF EXISTS ", quote_name(name)]
12671267

1268-
defp column_options(type, opts) do
1268+
defp column_options(opts) do
12691269
default = Keyword.fetch(opts, :default)
12701270
null = Keyword.get(opts, :null)
12711271
after_column = Keyword.get(opts, :after)
@@ -1274,7 +1274,7 @@ if Code.ensure_loaded?(MyXQL) do
12741274

12751275
[
12761276
default_expr(default),
1277-
collation_expr(collation, type),
1277+
collation_expr(collation),
12781278
null_expr(null),
12791279
comment_expr(comment),
12801280
after_expr(after_column)
@@ -1299,12 +1299,8 @@ if Code.ensure_loaded?(MyXQL) do
12991299
defp null_expr(true), do: " NULL"
13001300
defp null_expr(_), do: []
13011301

1302-
defp collation_expr({:ok, collation_name}, text_type)
1303-
when text_type in ~w/string char varchar text tinytext mediumtext longtext/a do
1304-
" COLLATE \"#{collation_name}\""
1305-
end
1306-
1307-
defp collation_expr(_, _), do: []
1302+
defp collation_expr({:ok, collation_name}), do: " COLLATE \"#{collation_name}\""
1303+
defp collation_expr(_), do: []
13081304

13091305
defp new_constraint_expr(%Constraint{check: check} = constraint) when is_binary(check) do
13101306
[

lib/ecto/adapters/postgres/connection.ex

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,7 +1567,7 @@ if Code.ensure_loaded?(Postgrex) do
15671567
reference_expr(ref, table, name),
15681568
modify_null(name, opts),
15691569
modify_default(name, ref.type, opts),
1570-
collation_expr(collation, ref.type)
1570+
collation_expr(collation)
15711571
]
15721572
end
15731573

@@ -1582,7 +1582,7 @@ if Code.ensure_loaded?(Postgrex) do
15821582
column_type(type, opts),
15831583
modify_null(name, opts),
15841584
modify_default(name, type, opts),
1585-
collation_expr(collation, type)
1585+
collation_expr(collation)
15861586
]
15871587
end
15881588

@@ -1632,19 +1632,15 @@ if Code.ensure_loaded?(Postgrex) do
16321632
null = Keyword.get(opts, :null)
16331633
collation = Keyword.fetch(opts, :collation)
16341634

1635-
[default_expr(default, type), null_expr(null), collation_expr(collation, type)]
1635+
[default_expr(default, type), null_expr(null), collation_expr(collation)]
16361636
end
16371637

16381638
defp null_expr(false), do: " NOT NULL"
16391639
defp null_expr(true), do: " NULL"
16401640
defp null_expr(_), do: []
16411641

1642-
defp collation_expr({:ok, collation_name}, text_type)
1643-
when text_type in ~w/string text char varchar/a do
1644-
" COLLATE \"#{collation_name}\""
1645-
end
1646-
1647-
defp collation_expr(_, _), do: []
1642+
defp collation_expr({:ok, collation_name}), do: " COLLATE \"#{collation_name}\""
1643+
defp collation_expr(_), do: []
16481644

16491645
defp new_constraint_expr(%Constraint{check: check} = constraint) when is_binary(check) do
16501646
[

lib/ecto/adapters/tds/connection.ex

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,13 +1369,13 @@ if Code.ensure_loaded?(Tds) do
13691369
quote_name(name),
13701370
" ",
13711371
reference_column_type(ref.type, opts),
1372-
column_options(table, name, ref.type, opts),
1372+
column_options(table, name, opts),
13731373
reference_expr(ref, table, name)
13741374
]
13751375
end
13761376

13771377
defp column_definition(table, {:add, name, type, opts}) do
1378-
[quote_name(name), " ", column_type(type, opts), column_options(table, name, type, opts)]
1378+
[quote_name(name), " ", column_type(type, opts), column_options(table, name, opts)]
13791379
end
13801380

13811381
defp column_changes(statement, table, columns) do
@@ -1396,7 +1396,7 @@ if Code.ensure_loaded?(Tds) do
13961396
quote_name(name),
13971397
" ",
13981398
reference_column_type(ref.type, opts),
1399-
column_options(table, name, ref.type, opts),
1399+
column_options(table, name, opts),
14001400
"; "
14011401
],
14021402
[statement_prefix, "ADD", constraint_expr(ref, table, name), "; "]
@@ -1411,7 +1411,7 @@ if Code.ensure_loaded?(Tds) do
14111411
quote_name(name),
14121412
" ",
14131413
column_type(type, opts),
1414-
column_options(table, name, type, opts),
1414+
column_options(table, name, opts),
14151415
"; "
14161416
]
14171417
]
@@ -1430,7 +1430,7 @@ if Code.ensure_loaded?(Tds) do
14301430
quote_name(column_name),
14311431
" ",
14321432
column_type(type, opts),
1433-
column_options(table, column_name, type, opts),
1433+
column_options(table, column_name, opts),
14341434
"; "
14351435
]
14361436
]
@@ -1446,7 +1446,7 @@ if Code.ensure_loaded?(Tds) do
14461446
quote_name(name),
14471447
" ",
14481448
reference_column_type(ref.type, opts),
1449-
column_options(table, name, ref.type, opts),
1449+
column_options(table, name, opts),
14501450
"; "
14511451
],
14521452
[statement_prefix, "ADD", constraint_expr(ref, table, name), "; "],
@@ -1467,7 +1467,7 @@ if Code.ensure_loaded?(Tds) do
14671467
" ",
14681468
column_type(type, opts),
14691469
null_expr(Keyword.get(opts, :null)),
1470-
collation_expr(collation, type),
1470+
collation_expr(collation),
14711471
"; "
14721472
],
14731473
[column_default_value(statement_prefix, table, name, opts)]
@@ -1500,14 +1500,12 @@ if Code.ensure_loaded?(Tds) do
15001500
]
15011501
end
15021502

1503-
defp column_options(table, name, type, opts) do
1503+
defp column_options(table, name, opts) do
15041504
default = Keyword.fetch(opts, :default)
15051505
null = Keyword.get(opts, :null)
1506+
collation = Keyword.fetch(opts, :collation)
15061507

1507-
collation =
1508-
Keyword.fetch(opts, :collation)
1509-
1510-
[null_expr(null), default_expr(table, name, default), collation_expr(collation, type)]
1508+
[null_expr(null), default_expr(table, name, default), collation_expr(collation)]
15111509
end
15121510

15131511
defp column_default_value(statement_prefix, table, name, opts) do
@@ -1523,12 +1521,8 @@ if Code.ensure_loaded?(Tds) do
15231521
defp null_expr(true), do: [" NULL"]
15241522
defp null_expr(_), do: []
15251523

1526-
defp collation_expr({:ok, collation_name}, text_type)
1527-
when text_type in ~w/string char varchar nchar nvarchar text ntext/a do
1528-
" COLLATE #{collation_name}"
1529-
end
1530-
1531-
defp collation_expr(_, _), do: []
1524+
defp collation_expr({:ok, collation_name}), do: " COLLATE #{collation_name}"
1525+
defp collation_expr(_), do: []
15321526

15331527
defp default_expr(_table, _name, {:ok, nil}),
15341528
do: []

0 commit comments

Comments
 (0)