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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
efba978f
Commit
efba978f
authored
May 18, 2021
by
Jonas Wälter
Committed by
Steve Abrams
May 18, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Data migration ('tags' to 'topics') for projects [RUN ALL RSPEC]
parent
ffac03a2
Changes
16
Show whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
220 additions
and
8 deletions
+220
-8
app/models/project.rb
app/models/project.rb
+35
-2
app/presenters/project_presenter.rb
app/presenters/project_presenter.rb
+4
-4
changelogs/unreleased/project-topics-data-migration.yml
changelogs/unreleased/project-topics-data-migration.yml
+5
-0
db/post_migrate/20210511095657_add_temporary_index_for_project_topics_to_taggings.rb
...657_add_temporary_index_for_project_topics_to_taggings.rb
+19
-0
db/post_migrate/20210511095658_schedule_migrate_project_taggings_context_from_tags_to_topics.rb
...e_migrate_project_taggings_context_from_tags_to_topics.rb
+30
-0
db/post_migrate/20210517075444_remove_temporary_index_for_project_topics_to_taggings.rb
..._remove_temporary_index_for_project_topics_to_taggings.rb
+19
-0
db/schema_migrations/20210511095657
db/schema_migrations/20210511095657
+1
-0
db/schema_migrations/20210511095658
db/schema_migrations/20210511095658
+1
-0
db/schema_migrations/20210517075444
db/schema_migrations/20210517075444
+1
-0
lib/gitlab/background_migration/migrate_project_taggings_context_from_tags_to_topics.rb
...n/migrate_project_taggings_context_from_tags_to_topics.rb
+21
-0
lib/gitlab/import_export/project/import_export.yml
lib/gitlab/import_export/project/import_export.yml
+1
-0
spec/finders/projects_finder_spec.rb
spec/finders/projects_finder_spec.rb
+1
-1
spec/lib/gitlab/background_migration/migrate_project_taggings_context_from_tags_to_topics_spec.rb
...rate_project_taggings_context_from_tags_to_topics_spec.rb
+29
-0
spec/lib/gitlab/import_export/all_models.yml
spec/lib/gitlab/import_export/all_models.yml
+2
-1
spec/models/project_spec.rb
spec/models/project_spec.rb
+49
-0
spec/requests/api/project_attributes.yml
spec/requests/api/project_attributes.yml
+2
-0
No files found.
app/models/project.rb
View file @
efba978f
...
@@ -128,8 +128,41 @@ class Project < ApplicationRecord
...
@@ -128,8 +128,41 @@ class Project < ApplicationRecord
after_initialize
:use_hashed_storage
after_initialize
:use_hashed_storage
after_create
:check_repository_absence!
after_create
:check_repository_absence!
acts_as_ordered_taggable
acts_as_ordered_taggable_on
:topics
alias_method
:topics
,
:tag_list
# The 'tag_list' alias and the 'has_many' associations are required during the 'tags -> topics' migration
# TODO: eliminate 'tag_list', 'topic_taggings' and 'tags' in the further process of the migration
# https://gitlab.com/gitlab-org/gitlab/-/issues/331081
alias_attribute
:tag_list
,
:topic_list
has_many
:topic_taggings
,
->
{
includes
(
:tag
).
order
(
"
#{
ActsAsTaggableOn
::
Tagging
.
table_name
}
.id"
)
},
as: :taggable
,
class_name:
'ActsAsTaggableOn::Tagging'
,
after_add: :dirtify_tag_list
,
after_remove: :dirtify_tag_list
has_many
:topics
,
->
{
order
(
"
#{
ActsAsTaggableOn
::
Tagging
.
table_name
}
.id"
)
},
class_name:
'ActsAsTaggableOn::Tag'
,
through: :topic_taggings
,
source: :tag
has_many
:tags
,
->
{
order
(
"
#{
ActsAsTaggableOn
::
Tagging
.
table_name
}
.id"
)
},
class_name:
'ActsAsTaggableOn::Tag'
,
through: :topic_taggings
,
source: :tag
# Overwriting 'topic_list' and 'topic_list=' is necessary to ensure functionality during the background migration [1].
# [1] https://gitlab.com/gitlab-org/gitlab/-/merge_requests/61237
# TODO: remove 'topic_list' and 'topic_list=' once the background migration is complete
# https://gitlab.com/gitlab-org/gitlab/-/issues/331081
def
topic_list
# Return both old topics (context 'tags') and new topics (context 'topics')
tag_list_on
(
'tags'
)
+
tag_list_on
(
'topics'
)
end
def
topic_list
=
(
new_tags
)
# Old topics with context 'tags' are added as new topics with context 'topics'
super
(
new_tags
)
# Remove old topics with context 'tags'
set_tag_list_on
(
'tags'
,
''
)
end
attr_accessor
:old_path_with_namespace
attr_accessor
:old_path_with_namespace
attr_accessor
:template_name
attr_accessor
:template_name
...
...
app/presenters/project_presenter.rb
View file @
efba978f
...
@@ -401,16 +401,16 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated
...
@@ -401,16 +401,16 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated
end
end
def
topics_to_show
def
topics_to_show
project
.
topic
s
.
take
(
MAX_TOPICS_TO_SHOW
)
# rubocop: disable CodeReuse/ActiveRecord
project
.
topic
_list
.
take
(
MAX_TOPICS_TO_SHOW
)
# rubocop: disable CodeReuse/ActiveRecord
end
end
def
topics_not_shown
def
topics_not_shown
project
.
topic
s
-
topics_to_show
project
.
topic
_list
-
topics_to_show
end
end
def
count_of_extra_topics_not_shown
def
count_of_extra_topics_not_shown
if
project
.
topic
s
.
count
>
MAX_TOPICS_TO_SHOW
if
project
.
topic
_list
.
count
>
MAX_TOPICS_TO_SHOW
project
.
topic
s
.
count
-
MAX_TOPICS_TO_SHOW
project
.
topic
_list
.
count
-
MAX_TOPICS_TO_SHOW
else
else
0
0
end
end
...
...
changelogs/unreleased/project-topics-data-migration.yml
0 → 100644
View file @
efba978f
---
title
:
Migrate 'tags' to 'topics' for project in the database context
merge_request
:
61237
author
:
Jonas Wälter @wwwjon
type
:
changed
db/post_migrate/20210511095657_add_temporary_index_for_project_topics_to_taggings.rb
0 → 100644
View file @
efba978f
# frozen_string_literal: true
class
AddTemporaryIndexForProjectTopicsToTaggings
<
ActiveRecord
::
Migration
[
6.0
]
include
Gitlab
::
Database
::
MigrationHelpers
INDEX_NAME
=
'tmp_index_taggings_on_id_where_taggable_type_project_and_tags'
INDEX_CONDITION
=
"taggable_type = 'Project' AND context = 'tags'"
disable_ddl_transaction!
def
up
# this index is used in 20210511095658_schedule_migrate_project_taggings_context_from_tags_to_topics
add_concurrent_index
:taggings
,
:id
,
where:
INDEX_CONDITION
,
name:
INDEX_NAME
end
def
down
remove_concurrent_index_by_name
:taggings
,
INDEX_NAME
end
end
db/post_migrate/20210511095658_schedule_migrate_project_taggings_context_from_tags_to_topics.rb
0 → 100644
View file @
efba978f
# frozen_string_literal: true
class
ScheduleMigrateProjectTaggingsContextFromTagsToTopics
<
ActiveRecord
::
Migration
[
6.0
]
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
BATCH_SIZE
=
30_000
DELAY_INTERVAL
=
2
.
minutes
MIGRATION
=
'MigrateProjectTaggingsContextFromTagsToTopics'
disable_ddl_transaction!
class
Tagging
<
ActiveRecord
::
Base
include
::
EachBatch
self
.
table_name
=
'taggings'
end
def
up
queue_background_migration_jobs_by_range_at_intervals
(
Tagging
.
where
(
taggable_type:
'Project'
,
context:
'tags'
),
MIGRATION
,
DELAY_INTERVAL
,
batch_size:
BATCH_SIZE
)
end
def
down
end
end
db/post_migrate/20210517075444_remove_temporary_index_for_project_topics_to_taggings.rb
0 → 100644
View file @
efba978f
# frozen_string_literal: true
class
RemoveTemporaryIndexForProjectTopicsToTaggings
<
ActiveRecord
::
Migration
[
6.0
]
include
Gitlab
::
Database
::
MigrationHelpers
INDEX_NAME
=
'tmp_index_taggings_on_id_where_taggable_type_project_and_tags'
INDEX_CONDITION
=
"taggable_type = 'Project' AND context = 'tags'"
disable_ddl_transaction!
def
up
# this index was used in 20210511095658_schedule_migrate_project_taggings_context_from_tags_to_topics
remove_concurrent_index_by_name
:taggings
,
INDEX_NAME
end
def
down
add_concurrent_index
:taggings
,
:id
,
where:
INDEX_CONDITION
,
name:
INDEX_NAME
end
end
db/schema_migrations/20210511095657
0 → 100644
View file @
efba978f
4d11cdf876786db5e827ea1a50b70e2d5b3814fd7c0b0c083ab61adad9685364
\ No newline at end of file
db/schema_migrations/20210511095658
0 → 100644
View file @
efba978f
7387c23bbbc376e26c057179ebe2796be183462acb1fc509d451f0fede13ed93
\ No newline at end of file
db/schema_migrations/20210517075444
0 → 100644
View file @
efba978f
ec08c18ac37f2ae7298650df58345755eada20aaa5b7ed3dfd54ee5cea88ebdd
\ No newline at end of file
lib/gitlab/background_migration/migrate_project_taggings_context_from_tags_to_topics.rb
0 → 100644
View file @
efba978f
# frozen_string_literal: true
module
Gitlab
module
BackgroundMigration
# The class to migrate the context of project taggings from `tags` to `topics`
class
MigrateProjectTaggingsContextFromTagsToTopics
# Temporary AR table for taggings
class
Tagging
<
ActiveRecord
::
Base
include
EachBatch
self
.
table_name
=
'taggings'
end
def
perform
(
start_id
,
stop_id
)
Tagging
.
where
(
taggable_type:
'Project'
,
context:
'tags'
,
id:
start_id
..
stop_id
).
each_batch
(
of:
500
)
do
|
relation
|
relation
.
update_all
(
context:
'topics'
)
end
end
end
end
end
lib/gitlab/import_export/project/import_export.yml
View file @
efba978f
...
@@ -153,6 +153,7 @@ excluded_attributes:
...
@@ -153,6 +153,7 @@ excluded_attributes:
-
:bfg_object_map
-
:bfg_object_map
-
:detected_repository_languages
-
:detected_repository_languages
-
:tag_list
-
:tag_list
-
:topic_list
-
:mirror_user_id
-
:mirror_user_id
-
:mirror_trigger_builds
-
:mirror_trigger_builds
-
:only_mirror_protected_branches
-
:only_mirror_protected_branches
...
...
spec/finders/projects_finder_spec.rb
View file @
efba978f
...
@@ -139,7 +139,7 @@ RSpec.describe ProjectsFinder do
...
@@ -139,7 +139,7 @@ RSpec.describe ProjectsFinder do
describe
'filter by tags'
do
describe
'filter by tags'
do
before
do
before
do
public_project
.
tag_list
.
add
(
'foo'
)
public_project
.
tag_list
=
'foo'
public_project
.
save!
public_project
.
save!
end
end
...
...
spec/lib/gitlab/background_migration/migrate_project_taggings_context_from_tags_to_topics_spec.rb
0 → 100644
View file @
efba978f
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Gitlab
::
BackgroundMigration
::
MigrateProjectTaggingsContextFromTagsToTopics
,
schema:
20210511095658
do
it
'correctly migrates project taggings context from tags to topics'
do
taggings
=
table
(
:taggings
)
project_old_tagging_1
=
taggings
.
create!
(
taggable_type:
'Project'
,
context:
'tags'
)
project_new_tagging_1
=
taggings
.
create!
(
taggable_type:
'Project'
,
context:
'topics'
)
project_other_context_tagging_1
=
taggings
.
create!
(
taggable_type:
'Project'
,
context:
'other'
)
project_old_tagging_2
=
taggings
.
create!
(
taggable_type:
'Project'
,
context:
'tags'
)
project_old_tagging_3
=
taggings
.
create!
(
taggable_type:
'Project'
,
context:
'tags'
)
subject
.
perform
(
project_old_tagging_1
.
id
,
project_old_tagging_2
.
id
)
project_old_tagging_1
.
reload
project_new_tagging_1
.
reload
project_other_context_tagging_1
.
reload
project_old_tagging_2
.
reload
project_old_tagging_3
.
reload
expect
(
project_old_tagging_1
.
context
).
to
eq
(
'topics'
)
expect
(
project_new_tagging_1
.
context
).
to
eq
(
'topics'
)
expect
(
project_other_context_tagging_1
.
context
).
to
eq
(
'other'
)
expect
(
project_old_tagging_2
.
context
).
to
eq
(
'topics'
)
expect
(
project_old_tagging_3
.
context
).
to
eq
(
'tags'
)
end
end
spec/lib/gitlab/import_export/all_models.yml
View file @
efba978f
...
@@ -343,8 +343,9 @@ project:
...
@@ -343,8 +343,9 @@ project:
-
external_approval_rules
-
external_approval_rules
-
taggings
-
taggings
-
base_tags
-
base_tags
-
tag_taggings
-
tags
-
tags
-
topic_taggings
-
topics
-
chat_services
-
chat_services
-
cluster
-
cluster
-
clusters
-
clusters
...
...
spec/models/project_spec.rb
View file @
efba978f
...
@@ -6964,6 +6964,55 @@ RSpec.describe Project, factory_default: :keep do
...
@@ -6964,6 +6964,55 @@ RSpec.describe Project, factory_default: :keep do
end
end
end
end
describe
'topics'
do
let_it_be
(
:project
)
{
create
(
:project
,
tag_list:
'topic1, topic2, topic3'
)
}
it
'topic_list returns correct string array'
do
expect
(
project
.
topic_list
).
to
match_array
(
%w[topic1 topic2 topic3]
)
end
it
'topics returns correct tag records'
do
expect
(
project
.
topics
.
first
.
class
.
name
).
to
eq
(
'ActsAsTaggableOn::Tag'
)
expect
(
project
.
topics
.
map
(
&
:name
)).
to
match_array
(
%w[topic1 topic2 topic3]
)
end
context
'aliases'
do
it
'tag_list returns correct string array'
do
expect
(
project
.
tag_list
).
to
match_array
(
%w[topic1 topic2 topic3]
)
end
it
'tags returns correct tag records'
do
expect
(
project
.
tags
.
first
.
class
.
name
).
to
eq
(
'ActsAsTaggableOn::Tag'
)
expect
(
project
.
tags
.
map
(
&
:name
)).
to
match_array
(
%w[topic1 topic2 topic3]
)
end
end
context
'intermediate state during background migration'
do
before
do
project
.
taggings
.
first
.
update!
(
context:
'tags'
)
project
.
instance_variable_set
(
"@tag_list"
,
nil
)
project
.
reload
end
it
'tag_list returns string array including old and new topics'
do
expect
(
project
.
tag_list
).
to
match_array
(
%w[topic1 topic2 topic3]
)
end
it
'tags returns old and new tag records'
do
expect
(
project
.
tags
.
first
.
class
.
name
).
to
eq
(
'ActsAsTaggableOn::Tag'
)
expect
(
project
.
tags
.
map
(
&
:name
)).
to
match_array
(
%w[topic1 topic2 topic3]
)
expect
(
project
.
taggings
.
map
(
&
:context
)).
to
match_array
(
%w[tags topics topics]
)
end
it
'update tag_list adds new topics and removes old topics'
do
project
.
update!
(
tag_list:
'topic1, topic2, topic3, topic4'
)
expect
(
project
.
tags
.
map
(
&
:name
)).
to
match_array
(
%w[topic1 topic2 topic3 topic4]
)
expect
(
project
.
taggings
.
map
(
&
:context
)).
to
match_array
(
%w[topics topics topics topics]
)
end
end
end
def
finish_job
(
export_job
)
def
finish_job
(
export_job
)
export_job
.
start
export_job
.
start
export_job
.
finish
export_job
.
finish
...
...
spec/requests/api/project_attributes.yml
View file @
efba978f
...
@@ -41,6 +41,7 @@ itself: # project
...
@@ -41,6 +41,7 @@ itself: # project
-
reset_approvals_on_push
-
reset_approvals_on_push
-
runners_token_encrypted
-
runners_token_encrypted
-
storage_version
-
storage_version
-
topic_list
-
updated_at
-
updated_at
remapped_attributes
:
remapped_attributes
:
avatar
:
avatar_url
avatar
:
avatar_url
...
@@ -67,6 +68,7 @@ itself: # project
...
@@ -67,6 +68,7 @@ itself: # project
-
readme_url
-
readme_url
-
shared_with_groups
-
shared_with_groups
-
ssh_url_to_repo
-
ssh_url_to_repo
-
tag_list
-
web_url
-
web_url
build_auto_devops
:
# auto_devops
build_auto_devops
:
# auto_devops
...
...
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