summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2018-09-04 15:46:48 +0000
committerYorick Peterse <yorickpeterse@gmail.com>2018-09-04 15:46:48 +0000
commitb5272bc2b6469009a2243ad759c6792e3e2b9a15 (patch)
treeeb3ddf5f1ded042a14614fe7708d9f21d84e8a8f
parentf17e48c84ebf3eb9a65f396f48195caad30dcb64 (diff)
parentfc59df67e278b5a874c6ce258038d277acc100d1 (diff)
downloadgitlab-ce-b5272bc2b6469009a2243ad759c6792e3e2b9a15.tar.gz
Merge branch 'rails5-include-opclasses-in-schema-dump' into 'master'
Rails 5: include opclasses in rails 5 schema dump See merge request gitlab-org/gitlab-ce!21416
-rw-r--r--changelogs/unreleased/rails5-include-opclasses-in-schema-dump.yml5
-rw-r--r--config/initializers/postgresql_opclasses_support.rb50
2 files changed, 36 insertions, 19 deletions
diff --git a/changelogs/unreleased/rails5-include-opclasses-in-schema-dump.yml b/changelogs/unreleased/rails5-include-opclasses-in-schema-dump.yml
new file mode 100644
index 00000000000..2dea84bc266
--- /dev/null
+++ b/changelogs/unreleased/rails5-include-opclasses-in-schema-dump.yml
@@ -0,0 +1,5 @@
+---
+title: 'Rails 5: include opclasses in rails 5 schema dump'
+merge_request: 21416
+author: Jasper Maes
+type: fixed
diff --git a/config/initializers/postgresql_opclasses_support.rb b/config/initializers/postgresql_opclasses_support.rb
index 7b8afc78817..12a0770a455 100644
--- a/config/initializers/postgresql_opclasses_support.rb
+++ b/config/initializers/postgresql_opclasses_support.rb
@@ -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