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
fc59df67
Commit
fc59df67
authored
Aug 29, 2018
by
Jasper Maes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rails 5: include opclasses in rails 5 schema dump
parent
380c7169
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
19 deletions
+36
-19
changelogs/unreleased/rails5-include-opclasses-in-schema-dump.yml
...gs/unreleased/rails5-include-opclasses-in-schema-dump.yml
+5
-0
config/initializers/postgresql_opclasses_support.rb
config/initializers/postgresql_opclasses_support.rb
+31
-19
No files found.
changelogs/unreleased/rails5-include-opclasses-in-schema-dump.yml
0 → 100644
View file @
fc59df67
---
title
:
'
Rails
5:
include
opclasses
in
rails
5
schema
dump'
merge_request
:
21416
author
:
Jasper Maes
type
:
fixed
config/initializers/postgresql_opclasses_support.rb
View file @
fc59df67
...
...
@@ -144,7 +144,10 @@ module ActiveRecord
[
column
,
opclass
]
if
opclass
end
.
compact
]
IndexDefinition
.
new
(
table_name
,
index_name
,
unique
,
column_names
,
[],
orders
,
where
,
nil
,
using
,
opclasses
)
index_attrs
=
[
table_name
,
index_name
,
unique
,
column_names
,
[],
orders
,
where
,
nil
,
using
,
opclasses
]
index_attrs
.
insert
(
-
2
,
nil
)
if
Gitlab
.
rails5?
# include index comment for Rails 5
IndexDefinition
.
new
(
*
index_attrs
)
end
end
.
compact
end
...
...
@@ -172,29 +175,38 @@ module ActiveRecord
def
indexes
(
table
,
stream
)
if
(
indexes
=
@connection
.
indexes
(
table
)).
any?
add_index_statements
=
indexes
.
map
do
|
index
|
statement_parts
=
[
"add_index
#{
remove_prefix_and_suffix
(
index
.
table
).
inspect
}
"
,
index
.
columns
.
inspect
,
"name:
#{
index
.
name
.
inspect
}
"
,
]
statement_parts
<<
'unique: true'
if
index
.
unique
index_lengths
=
(
index
.
lengths
||
[]).
compact
statement_parts
<<
"length:
#{
Hash
[
index
.
columns
.
zip
(
index
.
lengths
)].
inspect
}
"
if
index_lengths
.
any?
index_orders
=
index
.
orders
||
{}
statement_parts
<<
"order:
#{
index
.
orders
.
inspect
}
"
if
index_orders
.
any?
statement_parts
<<
"where:
#{
index
.
where
.
inspect
}
"
if
index
.
where
statement_parts
<<
"using:
#{
index
.
using
.
inspect
}
"
if
index
.
using
statement_parts
<<
"type:
#{
index
.
type
.
inspect
}
"
if
index
.
type
statement_parts
<<
"opclasses:
#{
index
.
opclasses
}
"
if
index
.
opclasses
.
present?
"
#{
statement_parts
.
join
(
', '
)
}
"
table_name
=
remove_prefix_and_suffix
(
index
.
table
).
inspect
" add_index
#{
([
table_name
]
+
index_parts
(
index
)).
join
(
', '
)
}
"
end
stream
.
puts
add_index_statements
.
sort
.
join
(
"
\n
"
)
stream
.
puts
end
end
def
indexes_in_create
(
table
,
stream
)
if
(
indexes
=
@connection
.
indexes
(
table
)).
any?
index_statements
=
indexes
.
map
do
|
index
|
" t.index
#{
index_parts
(
index
).
join
(
', '
)
}
"
end
stream
.
puts
index_statements
.
sort
.
join
(
"
\n
"
)
end
end
def
index_parts
(
index
)
index_parts
=
[
index
.
columns
.
inspect
,
"name:
#{
index
.
name
.
inspect
}
"
,
]
index_parts
<<
"unique: true"
if
index
.
unique
index_parts
<<
"length: {
#{
format_options
(
index
.
lengths
)
}
}"
if
index
.
lengths
.
present?
index_parts
<<
"order: {
#{
format_options
(
index
.
orders
)
}
}"
if
index
.
orders
.
present?
index_parts
<<
"where:
#{
index
.
where
.
inspect
}
"
if
index
.
where
index_parts
<<
"using:
#{
index
.
using
.
inspect
}
"
if
index
.
using
index_parts
<<
"type:
#{
index
.
type
.
inspect
}
"
if
index
.
type
index_parts
<<
"opclasses:
#{
index
.
opclasses
.
inspect
}
"
if
index
.
opclasses
.
present?
index_parts
<<
"comment:
#{
index
.
comment
.
inspect
}
"
if
Gitlab
.
rails5?
&&
index
.
comment
index_parts
end
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