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
iv
gitlab-ce
Commits
ae7bd9f7
Commit
ae7bd9f7
authored
Apr 24, 2014
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate invalid rows with missing iids or duplicates
parent
3bf1cff4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
0 deletions
+26
-0
app/models/milestone.rb
app/models/milestone.rb
+1
-0
db/migrate/20140416074002_add_index_on_iid.rb
db/migrate/20140416074002_add_index_on_iid.rb
+25
-0
No files found.
app/models/milestone.rb
View file @
ae7bd9f7
...
@@ -25,6 +25,7 @@ class Milestone < ActiveRecord::Base
...
@@ -25,6 +25,7 @@ class Milestone < ActiveRecord::Base
scope
:active
,
->
{
with_state
(
:active
)
}
scope
:active
,
->
{
with_state
(
:active
)
}
scope
:closed
,
->
{
with_state
(
:closed
)
}
scope
:closed
,
->
{
with_state
(
:closed
)
}
scope
:of_projects
,
->
(
ids
)
{
where
(
project_id:
ids
)
}
validates
:title
,
presence:
true
validates
:title
,
presence:
true
validates
:project
,
presence:
true
validates
:project
,
presence:
true
...
...
db/migrate/20140416074002_add_index_on_iid.rb
View file @
ae7bd9f7
class
AddIndexOnIid
<
ActiveRecord
::
Migration
class
AddIndexOnIid
<
ActiveRecord
::
Migration
def
change
def
change
RemoveDuplicateIid
.
clean
(
Issue
)
RemoveDuplicateIid
.
clean
(
MergeRequest
,
'target_project_id'
)
RemoveDuplicateIid
.
clean
(
Milestone
)
add_index
:issues
,
[
:project_id
,
:iid
],
unique:
true
add_index
:issues
,
[
:project_id
,
:iid
],
unique:
true
add_index
:merge_requests
,
[
:target_project_id
,
:iid
],
unique:
true
add_index
:merge_requests
,
[
:target_project_id
,
:iid
],
unique:
true
add_index
:milestones
,
[
:project_id
,
:iid
],
unique:
true
add_index
:milestones
,
[
:project_id
,
:iid
],
unique:
true
end
end
end
end
class
RemoveDuplicateIid
def
self
.
clean
(
klass
,
project_field
=
'project_id'
)
duplicates
=
klass
.
find_by_sql
(
"SELECT iid,
#{
project_field
}
FROM
#{
klass
.
table_name
}
GROUP BY
#{
project_field
}
, iid HAVING COUNT(*) > 1"
)
duplicates
.
each
do
|
duplicate
|
project_id
=
duplicate
.
send
(
project_field
)
iid
=
duplicate
.
iid
items
=
klass
.
of_projects
(
project_id
).
where
(
iid:
iid
)
if
items
.
size
>
1
puts
"Remove
#{
klass
.
name
}
duplicates for iid:
#{
iid
}
and project_id:
#{
project_id
}
"
items
.
shift
items
.
each
do
|
item
|
item
.
destroy
puts
'.'
end
end
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