Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
ba914c32
Commit
ba914c32
authored
Sep 03, 2018
by
Jasper Maes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rails 5: support schema t.index for mysql
parent
48541cac
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
0 deletions
+33
-0
changelogs/unreleased/rails5-mysql-binary-column-index-length.yml
...gs/unreleased/rails5-mysql-binary-column-index-length.yml
+5
-0
config/initializers/mysql_set_length_for_binary_indexes.rb
config/initializers/mysql_set_length_for_binary_indexes.rb
+28
-0
No files found.
changelogs/unreleased/rails5-mysql-binary-column-index-length.yml
0 → 100644
View file @
ba914c32
---
title
:
'
Rails
5:
support
schema
t.index
for
mysql'
merge_request
:
21485
author
:
Jasper Maes
type
:
other
config/initializers/mysql_set_length_for_binary_indexes.rb
View file @
ba914c32
...
...
@@ -2,6 +2,9 @@
# MySQL adapter apply a length of 20. Otherwise MySQL can't create an index on
# binary columns.
# This module can be removed once a Rails 5 schema is used.
# It can't be wrapped in a check that checks Gitlab.rails5? because
# the old Rails 4 schema layout is still used
module
MysqlSetLengthForBinaryIndex
def
add_index
(
table_name
,
column_names
,
options
=
{})
Array
(
column_names
).
each
do
|
column_name
|
...
...
@@ -19,3 +22,28 @@ end
if
defined?
(
ActiveRecord
::
ConnectionAdapters
::
Mysql2Adapter
)
ActiveRecord
::
ConnectionAdapters
::
Mysql2Adapter
.
send
(
:prepend
,
MysqlSetLengthForBinaryIndex
)
end
if
Gitlab
.
rails5?
module
MysqlSetLengthForBinaryIndexAndIgnorePostgresOptionsForSchema
# This method is used in Rails 5 schema loading as t.index
def
index
(
column_names
,
options
=
{})
Array
(
column_names
).
each
do
|
column_name
|
column
=
columns
.
find
{
|
c
|
c
.
name
==
column_name
}
if
column
&
.
type
==
:binary
options
[
:length
]
=
20
end
end
# Ignore indexes that use opclasses,
# also see config/initializers/mysql_ignore_postgresql_options.rb
unless
options
[
:opclasses
]
super
(
column_names
,
options
)
end
end
end
if
defined?
(
ActiveRecord
::
ConnectionAdapters
::
MySQL
::
TableDefinition
)
ActiveRecord
::
ConnectionAdapters
::
MySQL
::
TableDefinition
.
send
(
:prepend
,
MysqlSetLengthForBinaryIndexAndIgnorePostgresOptionsForSchema
)
end
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