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
a5d06643
Commit
a5d06643
authored
Mar 01, 2019
by
Heinrich Lee Yu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
EE-port for 54924-clean-up-data
Fixes merge conflict in db/schema.rb
parent
99a00859
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
68 additions
and
1 deletion
+68
-1
db/migrate/20190228092516_clean_up_noteable_id_for_notes_on_commits.rb
...190228092516_clean_up_noteable_id_for_notes_on_commits.rb
+33
-0
db/schema.rb
db/schema.rb
+1
-1
spec/migrations/clean_up_noteable_id_for_notes_on_commits_spec.rb
...rations/clean_up_noteable_id_for_notes_on_commits_spec.rb
+34
-0
No files found.
db/migrate/20190228092516_clean_up_noteable_id_for_notes_on_commits.rb
0 → 100644
View file @
a5d06643
# frozen_string_literal: true
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class
CleanUpNoteableIdForNotesOnCommits
<
ActiveRecord
::
Migration
[
5.0
]
include
Gitlab
::
Database
::
MigrationHelpers
# Set this constant to true if this migration requires downtime.
DOWNTIME
=
false
TEMP_INDEX_NAME
=
'index_notes_on_commit_with_null_noteable_id'
disable_ddl_transaction!
def
up
remove_concurrent_index_by_name
(
:notes
,
TEMP_INDEX_NAME
)
add_concurrent_index
(
:notes
,
:id
,
where:
"noteable_type = 'Commit' AND noteable_id IS NOT NULL"
,
name:
TEMP_INDEX_NAME
)
# rubocop:disable Migration/UpdateLargeTable
update_column_in_batches
(
:notes
,
:noteable_id
,
nil
)
do
|
table
,
query
|
query
.
where
(
table
[
:noteable_type
].
eq
(
'Commit'
).
and
(
table
[
:noteable_id
].
not_eq
(
nil
))
)
end
remove_concurrent_index_by_name
(
:notes
,
TEMP_INDEX_NAME
)
end
def
down
end
end
db/schema.rb
View file @
a5d06643
...
@@ -10,7 +10,7 @@
...
@@ -10,7 +10,7 @@
#
#
# It's strongly recommended that you check this file into your version control system.
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
2019022
2110418
)
do
ActiveRecord
::
Schema
.
define
(
version:
2019022
8092516
)
do
# These are extensions that must be enabled in order to support this database
# These are extensions that must be enabled in order to support this database
enable_extension
"plpgsql"
enable_extension
"plpgsql"
...
...
spec/migrations/clean_up_noteable_id_for_notes_on_commits_spec.rb
0 → 100644
View file @
a5d06643
# frozen_string_literal: true
require
'spec_helper'
require
Rails
.
root
.
join
(
'db'
,
'migrate'
,
'20190228092516_clean_up_noteable_id_for_notes_on_commits.rb'
)
describe
CleanUpNoteableIdForNotesOnCommits
,
:migration
do
let
(
:notes
)
{
table
(
:notes
)
}
before
do
notes
.
create!
(
noteable_type:
'Commit'
,
commit_id:
'3d0a182204cece4857f81c6462720e0ad1af39c9'
,
noteable_id:
3
,
note:
'Test'
)
notes
.
create!
(
noteable_type:
'Commit'
,
commit_id:
'3d0a182204cece4857f81c6462720e0ad1af39c9'
,
noteable_id:
3
,
note:
'Test'
)
notes
.
create!
(
noteable_type:
'Commit'
,
commit_id:
'3d0a182204cece4857f81c6462720e0ad1af39c9'
,
noteable_id:
3
,
note:
'Test'
)
notes
.
create!
(
noteable_type:
'Issue'
,
noteable_id:
1
,
note:
'Test'
)
notes
.
create!
(
noteable_type:
'MergeRequest'
,
noteable_id:
1
,
note:
'Test'
)
notes
.
create!
(
noteable_type:
'Snippet'
,
noteable_id:
1
,
note:
'Test'
)
end
it
'clears noteable_id for notes on commits'
do
expect
{
migrate!
}.
to
change
{
dirty_notes_on_commits
.
count
}.
from
(
3
).
to
(
0
)
end
it
'does not clear noteable_id for other notes'
do
expect
{
migrate!
}.
not_to
change
{
other_notes
.
count
}
end
def
dirty_notes_on_commits
notes
.
where
(
noteable_type:
'Commit'
).
where
(
'noteable_id IS NOT NULL'
)
end
def
other_notes
notes
.
where
(
"noteable_type != 'Commit' AND noteable_id IS NOT NULL"
)
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