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
Léo-Paul Géneau
gitlab-ce
Commits
02ed61c4
Commit
02ed61c4
authored
Mar 06, 2015
by
Valery Sizov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove duplication
parent
ed4c7190
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
2 deletions
+23
-2
db/migrate/20150306023106_fix_namespace_duplication.rb
db/migrate/20150306023106_fix_namespace_duplication.rb
+21
-0
db/migrate/20150306023112_add_unique_index_to_namespace.rb
db/migrate/20150306023112_add_unique_index_to_namespace.rb
+2
-2
No files found.
db/migrate/20150306023106_fix_namespace_duplication.rb
0 → 100644
View file @
02ed61c4
class
FixNamespaceDuplication
<
ActiveRecord
::
Migration
def
up
#fixes path duplication
select_all
(
'SELECT MAX(id) max, COUNT(id) cnt, path FROM namespaces GROUP BY path HAVING COUNT(id) > 1'
).
each
do
|
nms
|
bad_nms_ids
=
select_all
(
"SELECT id FROM namespaces WHERE path = '
#{
nms
[
'path'
]
}
' AND id <>
#{
nms
[
'max'
]
}
"
).
map
{
|
x
|
x
[
"id"
]}
execute
(
"UPDATE projects SET namespace_id =
#{
nms
[
"max"
]
}
WHERE namespace_id IN(
#{
bad_nms_ids
.
join
(
', '
)
}
)"
)
execute
(
"DELETE FROM namespaces WHERE id IN(
#{
bad_nms_ids
.
join
(
', '
)
}
)"
)
end
#fixes name duplication
select_all
(
'SELECT MAX(id) max, COUNT(id) cnt, name FROM namespaces GROUP BY name HAVING COUNT(id) > 1'
).
each
do
|
nms
|
bad_nms_ids
=
select_all
(
"SELECT id FROM namespaces WHERE name = '
#{
nms
[
'name'
]
}
' AND id <>
#{
nms
[
'max'
]
}
"
).
map
{
|
x
|
x
[
"id"
]}
execute
(
"UPDATE projects SET namespace_id =
#{
nms
[
"max"
]
}
WHERE namespace_id IN(
#{
bad_nms_ids
.
join
(
', '
)
}
)"
)
execute
(
"DELETE FROM namespaces WHERE id IN(
#{
bad_nms_ids
.
join
(
', '
)
}
)"
)
end
end
def
down
# not implemented
end
end
db/migrate/20150306023112_add_unique_index_to_namespace.rb
View file @
02ed61c4
class
AddUniqueIndexToNamespace
<
ActiveRecord
::
Migration
def
change
remove_index
:namespaces
,
:name
remove_index
:namespaces
,
:path
remove_index
:namespaces
,
column: :name
if
index_exists?
(
:namespaces
,
:name
)
remove_index
:namespaces
,
column: :path
if
index_exists?
(
:namespaces
,
:path
)
add_index
:namespaces
,
:name
,
unique:
true
add_index
:namespaces
,
:path
,
unique:
true
...
...
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