Skip to content
代码片段 群组 项目
未验证 提交 c3e3bf2a 编辑于 作者: Dmitry Gruzd's avatar Dmitry Gruzd 提交者: GitLab
浏览文件

Refactor some of our elastic helpers and specs

上级 1942b294
No related branches found
No related tags found
无相关合并请求
显示
29 个添加83 个删除
......@@ -66,17 +66,15 @@ The following migration helpers are available in `ee/app/workers/concerns/elasti
Backfills a specific field in an index. In most cases, the mapping for the field should already be added.
Requires the `index_name` and `field_name` methods to backfill a single field.
Requires the `field_name` method and `DOCUMENT_TYPE` constant to backfill a single field.
```ruby
class MigrationName < Elastic::Migration
include Elastic::MigrationBackfillHelper
private
DOCUMENT_TYPE = Issue
def index_name
Issue.__elasticsearch__.index_name
end
private
def field_name
:schema_version
......@@ -84,17 +82,15 @@ class MigrationName < Elastic::Migration
end
```
Requires the `index_name` and `field_names` methods to backfill multiple fields if any field is null.
Requires the `field_names` method and `DOCUMENT_TYPE` constant to backfill multiple fields if any field is null.
```ruby
class MigrationName < Elastic::Migration
include Elastic::MigrationBackfillHelper
private
DOCUMENT_TYPE = Issue
def index_name
Issue.__elasticsearch__.index_name
end
private
def field_names
%w[schema_version visibility_level]
......@@ -106,17 +102,15 @@ end
Updates a mapping in an index by calling `put_mapping` with the mapping specified.
Requires the `index_name` and `new_mappings` methods.
Requires the `new_mappings` method and `DOCUMENT_TYPE` constant.
```ruby
class MigrationName < Elastic::Migration
include Elastic::MigrationUpdateMappingsHelper
private
DOCUMENT_TYPE = Issue
def index_name
Issue.__elasticsearch__.index_name
end
private
def new_mappings
{
......
......@@ -31,6 +31,8 @@ def completed?
private
def index_name
return self.class::DOCUMENT_TYPE.__elasticsearch__.index_name if self.class.const_defined?(:DOCUMENT_TYPE)
raise NotImplementedError
end
......
......@@ -24,6 +24,8 @@ def completed?
private
def index_name
return self.class::DOCUMENT_TYPE.__elasticsearch__.index_name if self.class.const_defined?(:DOCUMENT_TYPE)
raise NotImplementedError
end
......
......@@ -12,10 +12,6 @@ class BackfillHashedRootNamespaceIdOnNotes < Elastic::Migration
private
def index_name
DOCUMENT_TYPE.__elasticsearch__.index_name
end
def field_name
'hashed_root_namespace_id'
end
......
......@@ -3,11 +3,9 @@
class AddHashedRootNamespaceIdToMergeRequests < Elastic::Migration
include Elastic::MigrationUpdateMappingsHelper
private
DOCUMENT_TYPE = MergeRequest
def index_name
MergeRequest.__elasticsearch__.index_name
end
private
def new_mappings
{
......
......@@ -3,11 +3,9 @@
class AddHashedRootNamespaceIdToIssues < Elastic::Migration
include Elastic::MigrationUpdateMappingsHelper
private
DOCUMENT_TYPE = Issue
def index_name
Issue.__elasticsearch__.index_name
end
private
def new_mappings
{
......
......@@ -12,10 +12,6 @@ class BackfillHashedRootNamespaceIdOnIssues < Elastic::Migration
private
def index_name
DOCUMENT_TYPE.__elasticsearch__.index_name
end
def field_name
'hashed_root_namespace_id'
end
......
......@@ -12,10 +12,6 @@ class BackfillHashedRootNamespaceIdOnMergeRequests < Elastic::Migration
private
def index_name
DOCUMENT_TYPE.__elasticsearch__.index_name
end
def field_name
'hashed_root_namespace_id'
end
......
......@@ -3,11 +3,9 @@
class AddHiddenToMergeRequests < Elastic::Migration
include Elastic::MigrationUpdateMappingsHelper
private
DOCUMENT_TYPE = MergeRequest
def index_name
MergeRequest.__elasticsearch__.index_name
end
private
def new_mappings
{
......
......@@ -12,10 +12,6 @@ class BackfillHiddenOnMergeRequests < Elastic::Migration
private
def index_name
DOCUMENT_TYPE.__elasticsearch__.index_name
end
def field_name
:hidden
end
......
......@@ -3,11 +3,9 @@
class AddCiCatalogToProject < Elastic::Migration
include Elastic::MigrationUpdateMappingsHelper
private
DOCUMENT_TYPE = Project
def index_name
Project.__elasticsearch__.index_name
end
private
def new_mappings
{
......
......@@ -11,10 +11,6 @@ class BackfillMilestonePermissionsToMilestoneDocuments < Elastic::Migration
private
def index_name
DOCUMENT_TYPE.__elasticsearch__.index_name
end
def field_names
%w[merge_requests_access_level issues_access_level visibility_level]
end
......
......@@ -3,11 +3,9 @@
class AddArchivedToIssues < Elastic::Migration
include Elastic::MigrationUpdateMappingsHelper
private
DOCUMENT_TYPE = Issue
def index_name
Issue.__elasticsearch__.index_name
end
private
def new_mappings
{
......
......@@ -12,10 +12,6 @@ class BackfillArchivedOnIssues < Elastic::Migration
private
def index_name
DOCUMENT_TYPE.__elasticsearch__.index_name
end
def field_name
'archived'
end
......
......@@ -3,11 +3,9 @@
class AddArchivedToMergeRequests < Elastic::Migration
include Elastic::MigrationUpdateMappingsHelper
private
DOCUMENT_TYPE = MergeRequest
def index_name
MergeRequest.__elasticsearch__.index_name
end
private
def new_mappings
{
......
......@@ -12,10 +12,6 @@ class BackfillArchivedOnMergeRequests < Elastic::Migration
private
def index_name
DOCUMENT_TYPE.__elasticsearch__.index_name
end
def field_name
'archived'
end
......
......@@ -12,10 +12,6 @@ class BackfillArchivedOnWorkItems < Elastic::Migration
private
def index_name
DOCUMENT_TYPE.__elasticsearch__.index_name
end
def field_name
'archived'
end
......
......@@ -3,11 +3,9 @@
class AddArchivedToNotes < Elastic::Migration
include Elastic::MigrationUpdateMappingsHelper
private
DOCUMENT_TYPE = Note
def index_name
::Elastic::Latest::NoteConfig.index_name
end
private
def new_mappings
{ archived: { type: 'boolean' } }
......
......@@ -11,10 +11,6 @@ class BackfillArchivedOnNotes < Elastic::Migration
private
def index_name
DOCUMENT_TYPE.__elasticsearch__.index_name
end
def field_name
'archived'
end
......
......@@ -3,11 +3,9 @@
class AddSchemaVersionToMergeRequest < Elastic::Migration
include Elastic::MigrationUpdateMappingsHelper
private
DOCUMENT_TYPE = MergeRequest
def index_name
::Elastic::Latest::MergeRequestConfig.index_name
end
private
def new_mappings
{
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册