-
Notifications
You must be signed in to change notification settings - Fork 322
Add support in migrations for collations in Postgres #662
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
d741e18
55c31cf
1727f2e
c520dc5
586900b
b94a1e3
1eb3957
4fe02c4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1171,13 +1171,13 @@ if Code.ensure_loaded?(MyXQL) do | |
quote_name(name), | ||
?\s, | ||
reference_column_type(ref.type, opts), | ||
column_options(opts), | ||
column_options(ref.type, opts), | ||
reference_expr(ref, table, name) | ||
] | ||
end | ||
|
||
defp column_definition(_table, {:add, name, type, opts}) do | ||
[quote_name(name), ?\s, column_type(type, opts), column_options(opts)] | ||
[quote_name(name), ?\s, column_type(type, opts), column_options(type, opts)] | ||
end | ||
|
||
defp column_changes(table, columns) do | ||
|
@@ -1194,13 +1194,13 @@ if Code.ensure_loaded?(MyXQL) do | |
quote_name(name), | ||
?\s, | ||
reference_column_type(ref.type, opts), | ||
column_options(opts), | ||
column_options(ref.type, opts), | ||
constraint_expr(ref, table, name) | ||
] | ||
end | ||
|
||
defp column_change(_table, {:add, name, type, opts}) do | ||
["ADD ", quote_name(name), ?\s, column_type(type, opts), column_options(opts)] | ||
["ADD ", quote_name(name), ?\s, column_type(type, opts), column_options(type, opts)] | ||
end | ||
|
||
defp column_change(table, {:add_if_not_exists, name, %Reference{} = ref, opts}) do | ||
|
@@ -1209,13 +1209,19 @@ if Code.ensure_loaded?(MyXQL) do | |
quote_name(name), | ||
?\s, | ||
reference_column_type(ref.type, opts), | ||
column_options(opts), | ||
column_options(ref.type, opts), | ||
constraint_if_not_exists_expr(ref, table, name) | ||
] | ||
end | ||
|
||
defp column_change(_table, {:add_if_not_exists, name, type, opts}) do | ||
["ADD IF NOT EXISTS ", quote_name(name), ?\s, column_type(type, opts), column_options(opts)] | ||
[ | ||
"ADD IF NOT EXISTS ", | ||
quote_name(name), | ||
?\s, | ||
column_type(type, opts), | ||
column_options(type, opts) | ||
] | ||
end | ||
|
||
defp column_change(table, {:modify, name, %Reference{} = ref, opts}) do | ||
|
@@ -1225,7 +1231,7 @@ if Code.ensure_loaded?(MyXQL) do | |
quote_name(name), | ||
?\s, | ||
reference_column_type(ref.type, opts), | ||
column_options(opts), | ||
column_options(ref.type, opts), | ||
constraint_expr(ref, table, name) | ||
] | ||
end | ||
|
@@ -1237,7 +1243,7 @@ if Code.ensure_loaded?(MyXQL) do | |
quote_name(name), | ||
?\s, | ||
column_type(type, opts), | ||
column_options(opts) | ||
column_options(type, opts) | ||
] | ||
end | ||
|
||
|
@@ -1259,13 +1265,20 @@ if Code.ensure_loaded?(MyXQL) do | |
defp column_change(_table, {:remove_if_exists, name}), | ||
do: ["DROP IF EXISTS ", quote_name(name)] | ||
|
||
defp column_options(opts) do | ||
defp column_options(type, opts) do | ||
default = Keyword.fetch(opts, :default) | ||
null = Keyword.get(opts, :null) | ||
after_column = Keyword.get(opts, :after) | ||
comment = Keyword.get(opts, :comment) | ||
collation = Keyword.fetch(opts, :collation) | ||
|
||
[default_expr(default), null_expr(null), comment_expr(comment), after_expr(after_column)] | ||
[ | ||
default_expr(default), | ||
collation_expr(collation, type), | ||
null_expr(null), | ||
comment_expr(comment), | ||
after_expr(after_column) | ||
] | ||
end | ||
|
||
defp comment_expr(comment, create_table? \\ false) | ||
|
@@ -1286,6 +1299,13 @@ if Code.ensure_loaded?(MyXQL) do | |
defp null_expr(true), do: " NULL" | ||
defp null_expr(_), do: [] | ||
|
||
defp collation_expr({:ok, collation_name}, text_type) | ||
when text_type in ~w/string char varchar text tinytext mediumtext longtext/a do | ||
" COLLATE \"#{collation_name}\"" | ||
end | ||
|
||
defp collation_expr(_, _), do: [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should either raise or not check the type and let the underlying SQL operation fail. Perhaps the second option is best, because I don’t know if Postgres supports collations for custom types (which would then be impossible to check). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Postgres does support collations for custom types, so letting the SQL fail is the best option. |
||
|
||
defp new_constraint_expr(%Constraint{check: check} = constraint) when is_binary(check) do | ||
[ | ||
"CONSTRAINT ", | ||
|
Uh oh!
There was an error while loading. Please reload this page.