Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
heptapod
Commits
9faaf3eed5f6
Commit
07dbd564
authored
Jul 25, 2017
by
Alexis Reigel
Browse files
use Module#prepend instead of alias_method_chain
parent
3631400852ff
Changes
1
Hide whitespace changes
Inline
Side-by-side
config/initializers/mysql_set_length_for_binary_indexes.rb
View file @
9faaf3ee
...
...
@@ -2,24 +2,20 @@
# MySQL adapter apply a length of 20. Otherwise MySQL can't create an index on
# binary columns.
if
defined?
(
ActiveRecord
::
ConnectionAdapters
::
Mysql2Adapter
)
module
ActiveRecord
module
ConnectionAdapters
class
Mysql2Adapter
<
AbstractMysqlAdapter
alias_method
:__gitlab_add_index2
,
:add_index
def
add_index
(
table_name
,
column_names
,
options
=
{})
Array
(
column_names
).
each
do
|
column_name
|
column
=
ActiveRecord
::
Base
.
connection
.
columns
(
table_name
).
find
{
|
c
|
c
.
name
==
column_name
}
module
MysqlSetLengthForBinaryIndex
def
add_index
(
table_name
,
column_names
,
options
=
{})
Array
(
column_names
).
each
do
|
column_name
|
column
=
ActiveRecord
::
Base
.
connection
.
columns
(
table_name
).
find
{
|
c
|
c
.
name
==
column_name
}
if
column
&
.
type
==
:binary
options
[
:length
]
=
20
end
end
__gitlab_add_index2
(
table_name
,
column_names
,
options
)
end
if
column
&
.
type
==
:binary
options
[
:length
]
=
20
end
end
super
(
table_name
,
column_names
,
options
)
end
end
if
defined?
(
ActiveRecord
::
ConnectionAdapters
::
Mysql2Adapter
)
ActiveRecord
::
ConnectionAdapters
::
Mysql2Adapter
.
send
(
:prepend
,
MysqlSetLengthForBinaryIndex
)
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment