Skip to content

Commit 629b663

Browse files
Change prefix type to string (#594)
1 parent 38d2f7e commit 629b663

6 files changed

Lines changed: 53 additions & 53 deletions

File tree

lib/ecto/migration.ex

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ defmodule Ecto.Migration do
395395

396396
@type t :: %__MODULE__{
397397
table: String.t(),
398-
prefix: atom,
398+
prefix: String.t() | nil,
399399
name: atom,
400400
columns: [atom | String.t()],
401401
unique: boolean,
@@ -420,7 +420,7 @@ defmodule Ecto.Migration do
420420

421421
@type t :: %__MODULE__{
422422
name: String.t(),
423-
prefix: atom | nil,
423+
prefix: String.t() | nil,
424424
comment: String.t() | nil,
425425
primary_key: boolean | keyword(),
426426
engine: atom,
@@ -453,15 +453,15 @@ defmodule Ecto.Migration do
453453
"""
454454
@type t :: %__MODULE__{
455455
table: String.t(),
456-
prefix: atom | nil,
456+
prefix: String.t() | nil,
457457
column: atom,
458458
type: atom,
459459
on_delete: atom,
460460
on_update: atom,
461461
validate: boolean,
462462
with: list,
463463
match: atom | nil,
464-
options: [{:prefix, atom | nil}]
464+
options: [{:prefix, String.t() | nil}]
465465
}
466466
end
467467

@@ -482,7 +482,7 @@ defmodule Ecto.Migration do
482482
@type t :: %__MODULE__{
483483
name: atom,
484484
table: String.t(),
485-
prefix: atom | nil,
485+
prefix: String.t() | nil,
486486
check: String.t() | nil,
487487
exclude: String.t() | nil,
488488
comment: String.t() | nil,

test/ecto/adapters/myxql_test.exs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,7 +1609,7 @@ defmodule Ecto.Adapters.MyXQLTest do
16091609

16101610
test "create table with prefix" do
16111611
create =
1612-
{:create, table(:posts, prefix: :foo),
1612+
{:create, table(:posts, prefix: "foo"),
16131613
[{:add, :category_0, %Reference{table: :categories}, []}]}
16141614

16151615
assert execute_ddl(create) == [
@@ -1623,7 +1623,7 @@ defmodule Ecto.Adapters.MyXQLTest do
16231623

16241624
test "create table with comment on columns and table" do
16251625
create =
1626-
{:create, table(:posts, comment: "comment", prefix: :foo),
1626+
{:create, table(:posts, comment: "comment", prefix: "foo"),
16271627
[
16281628
{:add, :category_0, %Reference{table: :categories}, [comment: "column comment"]},
16291629
{:add, :created_at, :datetime, []},
@@ -1662,7 +1662,7 @@ defmodule Ecto.Adapters.MyXQLTest do
16621662
[null: false]},
16631663
{:add, :category_4, %Reference{table: :categories, on_delete: :nilify_all}, []},
16641664
{:add, :category_5,
1665-
%Reference{table: :categories, options: [prefix: :foo], on_delete: :nilify_all}, []},
1665+
%Reference{table: :categories, options: [prefix: "foo"], on_delete: :nilify_all}, []},
16661666
{:add, :category_6,
16671667
%Reference{table: :categories, with: [here: :there], on_delete: :nilify_all}, []}
16681668
]}
@@ -1901,22 +1901,22 @@ defmodule Ecto.Adapters.MyXQLTest do
19011901
end
19021902

19031903
test "drop table with prefixes" do
1904-
drop = {:drop, table(:posts, prefix: :foo), :restrict}
1904+
drop = {:drop, table(:posts, prefix: "foo"), :restrict}
19051905
assert execute_ddl(drop) == [~s|DROP TABLE `foo`.`posts`|]
19061906
end
19071907

19081908
test "drop constraint" do
19091909
assert_raise ArgumentError, ~r/MySQL adapter does not support constraints/, fn ->
19101910
execute_ddl(
1911-
{:drop, constraint(:products, "price_must_be_positive", prefix: :foo), :restrict}
1911+
{:drop, constraint(:products, "price_must_be_positive", prefix: "foo"), :restrict}
19121912
)
19131913
end
19141914
end
19151915

19161916
test "drop_if_exists constraint" do
19171917
assert_raise ArgumentError, ~r/MySQL adapter does not support constraints/, fn ->
19181918
execute_ddl(
1919-
{:drop_if_exists, constraint(:products, "price_must_be_positive", prefix: :foo),
1919+
{:drop_if_exists, constraint(:products, "price_must_be_positive", prefix: "foo"),
19201920
:restrict}
19211921
)
19221922
end
@@ -2008,7 +2008,7 @@ defmodule Ecto.Adapters.MyXQLTest do
20082008

20092009
test "alter table with prefix" do
20102010
alter =
2011-
{:alter, table(:posts, prefix: :foo),
2011+
{:alter, table(:posts, prefix: "foo"),
20122012
[
20132013
{:add, :author_id, %Reference{table: :author}, []},
20142014
{:modify, :permalink_id, %Reference{table: :permalinks}, null: false}
@@ -2071,7 +2071,7 @@ defmodule Ecto.Adapters.MyXQLTest do
20712071
end
20722072

20732073
test "create index with prefix" do
2074-
create = {:create, index(:posts, [:category_id, :permalink], prefix: :foo)}
2074+
create = {:create, index(:posts, [:category_id, :permalink], prefix: "foo")}
20752075

20762076
assert execute_ddl(create) ==
20772077
[
@@ -2128,7 +2128,7 @@ defmodule Ecto.Adapters.MyXQLTest do
21282128
end
21292129

21302130
test "drop index with prefix" do
2131-
drop = {:drop, index(:posts, [:id], name: "posts$main", prefix: :foo), :restrict}
2131+
drop = {:drop, index(:posts, [:id], name: "posts$main", prefix: "foo"), :restrict}
21322132
assert execute_ddl(drop) == [~s|DROP INDEX `posts$main` ON `foo`.`posts`|]
21332133
end
21342134

@@ -2146,7 +2146,7 @@ defmodule Ecto.Adapters.MyXQLTest do
21462146
end
21472147

21482148
test "rename table with prefix" do
2149-
rename = {:rename, table(:posts, prefix: :foo), table(:new_posts, prefix: :foo)}
2149+
rename = {:rename, table(:posts, prefix: "foo"), table(:new_posts, prefix: "foo")}
21502150
assert execute_ddl(rename) == [~s|RENAME TABLE `foo`.`posts` TO `foo`.`new_posts`|]
21512151
end
21522152

@@ -2159,7 +2159,7 @@ defmodule Ecto.Adapters.MyXQLTest do
21592159
end
21602160

21612161
test "rename column in prefixed table" do
2162-
rename = {:rename, table(:posts, prefix: :foo), :given_name, :first_name}
2162+
rename = {:rename, table(:posts, prefix: "foo"), :given_name, :first_name}
21632163

21642164
assert execute_ddl(rename) == [
21652165
~s|ALTER TABLE `foo`.`posts` RENAME COLUMN `given_name` TO `first_name`|

test/ecto/adapters/postgres_test.exs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2012,7 +2012,7 @@ defmodule Ecto.Adapters.PostgresTest do
20122012

20132013
test "create table with prefix" do
20142014
create =
2015-
{:create, table(:posts, prefix: :foo),
2015+
{:create, table(:posts, prefix: "foo"),
20162016
[{:add, :category_0, %Reference{table: :categories}, []}]}
20172017

20182018
assert execute_ddl(create) == [
@@ -2406,15 +2406,15 @@ defmodule Ecto.Adapters.PostgresTest do
24062406
end
24072407

24082408
test "drop table with prefix" do
2409-
drop = {:drop, table(:posts, prefix: :foo), :restrict}
2409+
drop = {:drop, table(:posts, prefix: "foo"), :restrict}
24102410
assert execute_ddl(drop) == [~s|DROP TABLE "foo"."posts"|]
24112411
end
24122412

24132413
test "drop table with cascade" do
24142414
drop = {:drop, table(:posts), :cascade}
24152415
assert execute_ddl(drop) == [~s|DROP TABLE "posts" CASCADE|]
24162416

2417-
drop = {:drop, table(:posts, prefix: :foo), :cascade}
2417+
drop = {:drop, table(:posts, prefix: "foo"), :cascade}
24182418
assert execute_ddl(drop) == [~s|DROP TABLE "foo"."posts" CASCADE|]
24192419
end
24202420

@@ -2518,7 +2518,7 @@ defmodule Ecto.Adapters.PostgresTest do
25182518

25192519
test "alter table with prefix" do
25202520
alter =
2521-
{:alter, table(:posts, prefix: :foo),
2521+
{:alter, table(:posts, prefix: "foo"),
25222522
[
25232523
{:add, :author_id, %Reference{table: :author}, []},
25242524
{:modify, :permalink_id, %Reference{table: :permalinks}, null: false}
@@ -2586,22 +2586,22 @@ defmodule Ecto.Adapters.PostgresTest do
25862586
end
25872587

25882588
test "create index with prefix" do
2589-
create = {:create, index(:posts, [:category_id, :permalink], prefix: :foo)}
2589+
create = {:create, index(:posts, [:category_id, :permalink], prefix: "foo")}
25902590

25912591
assert execute_ddl(create) ==
25922592
[
25932593
~s|CREATE INDEX "posts_category_id_permalink_index" ON "foo"."posts" ("category_id", "permalink")|
25942594
]
25952595

2596-
create = {:create, index(:posts, ["lower(permalink)"], name: "posts$main", prefix: :foo)}
2596+
create = {:create, index(:posts, ["lower(permalink)"], name: "posts$main", prefix: "foo")}
25972597

25982598
assert execute_ddl(create) ==
25992599
[~s|CREATE INDEX "posts$main" ON "foo"."posts" (lower(permalink))|]
26002600
end
26012601

26022602
test "create index with comment" do
26032603
create =
2604-
{:create, index(:posts, [:category_id, :permalink], prefix: :foo, comment: "comment")}
2604+
{:create, index(:posts, [:category_id, :permalink], prefix: "foo", comment: "comment")}
26052605

26062606
assert execute_ddl(create) == [
26072607
remove_newlines("""
@@ -2727,7 +2727,7 @@ defmodule Ecto.Adapters.PostgresTest do
27272727
end
27282728

27292729
test "drop index with prefix" do
2730-
drop = {:drop, index(:posts, [:id], name: "posts$main", prefix: :foo), :restrict}
2730+
drop = {:drop, index(:posts, [:id], name: "posts$main", prefix: "foo"), :restrict}
27312731
assert execute_ddl(drop) == [~s|DROP INDEX "foo"."posts$main"|]
27322732
end
27332733

@@ -2741,7 +2741,7 @@ defmodule Ecto.Adapters.PostgresTest do
27412741
drop = {:drop, index(:posts, [:id], name: "posts$main"), :cascade}
27422742
assert execute_ddl(drop) == [~s|DROP INDEX "posts$main" CASCADE|]
27432743

2744-
drop = {:drop, index(:posts, [:id], name: "posts$main", prefix: :foo), :cascade}
2744+
drop = {:drop, index(:posts, [:id], name: "posts$main", prefix: "foo"), :cascade}
27452745
assert execute_ddl(drop) == [~s|DROP INDEX "foo"."posts$main" CASCADE|]
27462746
end
27472747

@@ -2755,7 +2755,7 @@ defmodule Ecto.Adapters.PostgresTest do
27552755

27562756
test "rename index with prefix" do
27572757
rename =
2758-
{:rename, index(:people, [:name], name: "persons_name_index", prefix: :foo),
2758+
{:rename, index(:people, [:name], name: "persons_name_index", prefix: "foo"),
27592759
"people_name_index"}
27602760

27612761
assert execute_ddl(rename) == [
@@ -2868,7 +2868,7 @@ defmodule Ecto.Adapters.PostgresTest do
28682868
end
28692869

28702870
test "rename table with prefix" do
2871-
rename = {:rename, table(:posts, prefix: :foo), table(:new_posts, prefix: :foo)}
2871+
rename = {:rename, table(:posts, prefix: "foo"), table(:new_posts, prefix: "foo")}
28722872
assert execute_ddl(rename) == [~s|ALTER TABLE "foo"."posts" RENAME TO "new_posts"|]
28732873
end
28742874

@@ -2878,7 +2878,7 @@ defmodule Ecto.Adapters.PostgresTest do
28782878
end
28792879

28802880
test "rename column in prefixed table" do
2881-
rename = {:rename, table(:posts, prefix: :foo), :given_name, :first_name}
2881+
rename = {:rename, table(:posts, prefix: "foo"), :given_name, :first_name}
28822882

28832883
assert execute_ddl(rename) == [
28842884
~s|ALTER TABLE "foo"."posts" RENAME "given_name" TO "first_name"|

test/ecto/adapters/tds_test.exs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,7 +1433,7 @@ defmodule Ecto.Adapters.TdsTest do
14331433

14341434
test "create table with prefix" do
14351435
create =
1436-
{:create, table(:posts, prefix: :foo),
1436+
{:create, table(:posts, prefix: "foo"),
14371437
[{:add, :category_0, %Reference{table: :categories}, []}]}
14381438

14391439
assert execute_ddl(create) == [
@@ -1458,7 +1458,7 @@ defmodule Ecto.Adapters.TdsTest do
14581458
[null: false]},
14591459
{:add, :category_4, %Reference{table: :categories, on_delete: :nilify_all}, []},
14601460
{:add, :category_5,
1461-
%Reference{table: :categories, options: [prefix: :foo], on_delete: :nilify_all}, []},
1461+
%Reference{table: :categories, options: [prefix: "foo"], on_delete: :nilify_all}, []},
14621462
{:add, :category_6,
14631463
%Reference{table: :categories, with: [here: :there], on_delete: :nilify_all}, []}
14641464
]}
@@ -1593,7 +1593,7 @@ defmodule Ecto.Adapters.TdsTest do
15931593
end
15941594

15951595
test "drop table with prefixes" do
1596-
drop = {:drop, table(:posts, prefix: :foo), :restrict}
1596+
drop = {:drop, table(:posts, prefix: "foo"), :restrict}
15971597
assert execute_ddl(drop) == ["DROP TABLE [foo].[posts]; "]
15981598
end
15991599

@@ -1766,7 +1766,7 @@ defmodule Ecto.Adapters.TdsTest do
17661766
end
17671767

17681768
test "rename table with prefix" do
1769-
rename = {:rename, table(:posts, prefix: :foo), table(:new_posts, prefix: :foo)}
1769+
rename = {:rename, table(:posts, prefix: "foo"), table(:new_posts, prefix: "foo")}
17701770
assert execute_ddl(rename) == [~s|EXEC sp_rename 'foo.posts', 'foo.new_posts'|]
17711771
end
17721772

@@ -1778,7 +1778,7 @@ defmodule Ecto.Adapters.TdsTest do
17781778
end
17791779

17801780
test "rename column in table with prefixes" do
1781-
rename = {:rename, table(:posts, prefix: :foo), :given_name, :first_name}
1781+
rename = {:rename, table(:posts, prefix: "foo"), :given_name, :first_name}
17821782

17831783
assert execute_ddl(rename) ==
17841784
["EXEC sp_rename 'foo.posts.given_name', 'first_name', 'COLUMN'"]
@@ -1803,7 +1803,7 @@ defmodule Ecto.Adapters.TdsTest do
18031803
end
18041804

18051805
test "create index with prefix" do
1806-
create = {:create, index(:posts, [:category_id, :permalink], prefix: :foo)}
1806+
create = {:create, index(:posts, [:category_id, :permalink], prefix: "foo")}
18071807

18081808
assert execute_ddl(create) ==
18091809
[
@@ -1812,7 +1812,7 @@ defmodule Ecto.Adapters.TdsTest do
18121812
end
18131813

18141814
test "create index with prefix if not exists" do
1815-
create = {:create_if_not_exists, index(:posts, [:category_id, :permalink], prefix: :foo)}
1815+
create = {:create_if_not_exists, index(:posts, [:category_id, :permalink], prefix: "foo")}
18161816

18171817
assert execute_ddl(create) ==
18181818
[
@@ -1839,7 +1839,7 @@ defmodule Ecto.Adapters.TdsTest do
18391839
assert execute_ddl(create) ==
18401840
[~s|CREATE UNIQUE INDEX [posts_permalink_index] ON [posts] ([permalink]);|]
18411841

1842-
create = {:create, index(:posts, [:permalink], unique: true, prefix: :foo)}
1842+
create = {:create, index(:posts, [:permalink], unique: true, prefix: "foo")}
18431843

18441844
assert execute_ddl(create) ==
18451845
[~s|CREATE UNIQUE INDEX [posts_permalink_index] ON [foo].[posts] ([permalink]);|]
@@ -1866,7 +1866,7 @@ defmodule Ecto.Adapters.TdsTest do
18661866

18671867
test "drop index with prefix" do
18681868
drop =
1869-
{:drop, index(:posts, [:id], name: "posts_category_id_permalink_index", prefix: :foo),
1869+
{:drop, index(:posts, [:id], name: "posts_category_id_permalink_index", prefix: "foo"),
18701870
:restrict}
18711871

18721872
assert execute_ddl(drop) ==
@@ -1876,7 +1876,7 @@ defmodule Ecto.Adapters.TdsTest do
18761876
test "drop index with prefix if exists" do
18771877
drop =
18781878
{:drop_if_exists,
1879-
index(:posts, [:id], name: "posts_category_id_permalink_index", prefix: :foo), :restrict}
1879+
index(:posts, [:id], name: "posts_category_id_permalink_index", prefix: "foo"), :restrict}
18801880

18811881
assert execute_ddl(drop) ==
18821882
[
@@ -1892,7 +1892,7 @@ defmodule Ecto.Adapters.TdsTest do
18921892

18931893
drop_cascade =
18941894
{:drop_if_exists,
1895-
index(:posts, [:id], name: "posts_category_id_permalink_index", prefix: :foo), :cascade}
1895+
index(:posts, [:id], name: "posts_category_id_permalink_index", prefix: "foo"), :cascade}
18961896

18971897
assert_raise ArgumentError, ~r"MSSQL does not support `CASCADE` in DROP INDEX commands", fn ->
18981898
execute_ddl(drop_cascade)

test/ecto/migration_test.exs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,20 +129,20 @@ defmodule Ecto.MigrationTest do
129129
assert references(:posts, type: :uuid, column: :other) ==
130130
%Reference{table: "posts", column: :other, type: :uuid, prefix: nil}
131131

132-
assert references(:posts, type: :uuid, column: :other, prefix: :blog) ==
132+
assert references(:posts, type: :uuid, column: :other, prefix: "blog") ==
133133
%Reference{
134134
table: "posts",
135135
column: :other,
136136
type: :uuid,
137-
prefix: :blog,
138-
options: [prefix: :blog]
137+
prefix: "blog",
138+
options: [prefix: "blog"]
139139
}
140140
end
141141

142-
@tag repo_config: [migration_foreign_key: [type: :uuid, column: :other, prefix: :blog]]
142+
@tag repo_config: [migration_foreign_key: [type: :uuid, column: :other, prefix: "blog"]]
143143
test "create a reference with using the foreign key repo config" do
144144
assert references(:posts) ==
145-
%Reference{table: "posts", column: :other, type: :uuid, prefix: :blog}
145+
%Reference{table: "posts", column: :other, type: :uuid, prefix: "blog"}
146146
end
147147

148148
@tag repo_config: [migration_primary_key: [type: :binary_id]]
@@ -711,7 +711,7 @@ defmodule Ecto.MigrationTest do
711711
assert table.prefix == :foo
712712
end
713713

714-
@tag prefix: :bar
714+
@tag prefix: "bar"
715715
test "raise error when prefixes don't match" do
716716
assert_raise Ecto.MigrationError,
717717
"the :prefix option `foo` does not match the migrator prefix `bar`",

0 commit comments

Comments
 (0)