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
Boxiang Sun
gitlab-ce
Commits
45a105b1
Commit
45a105b1
authored
Sep 20, 2015
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use pure SQL queries to migrate CI tags
parent
a6f2caf7
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
33 deletions
+25
-33
lib/ci/migrate/tags.rb
lib/ci/migrate/tags.rb
+25
-33
No files found.
lib/ci/migrate/tags.rb
View file @
45a105b1
...
...
@@ -4,45 +4,37 @@ module Ci
module
Migrate
class
Tags
def
restore
puts
'Migrating tags for Runners... '
list_objects
(
'Runner'
).
each
do
|
id
|
putc
'.'
runner
=
Ci
::
Runner
.
find_by_id
(
id
)
if
runner
tags
=
list_tags
(
'Runner'
,
id
)
runner
.
update_attributes
(
tag_list:
tags
)
end
end
puts
''
ActiveRecord
::
Base
.
transaction
do
puts
'Inserting tags...'
connection
.
execute
(
'INSERT INTO tags (name) '
+
'SELECT ci_tags.name FROM ci_tags '
+
'WHERE (SELECT COUNT(*) FROM tags WHERE tags.name = ci_tags.name)=0'
)
puts
'Migrating tags for Builds... '
list_objects
(
'Build'
).
each
do
|
id
|
putc
'.'
build
=
Ci
::
Build
.
find_by_id
(
id
)
if
build
tags
=
list_tags
(
'Build'
,
id
)
build
.
update_attributes
(
tag_list:
tags
)
end
end
puts
''
end
puts
'Deleting old records'
connection
.
execute
"DELETE FROM taggings WHERE context = 'tags' AND taggable_type LIKE 'Ci::%'"
protected
puts
'Inserting tags...'
connection
.
execute
(
'INSERT INTO taggings (taggable_type, taggable_id, tag_id, context) '
+
"SELECT CONCAT('Ci::', ci_taggings.taggable_type), ci_taggings.taggable_id, tags.id, 'tags' FROM ci_taggings "
+
'JOIN ci_tags ON ci_tags.id = ci_taggings.tag_id '
+
'JOIN tags ON tags.name = ci_tags.name '
)
def
list_objects
(
type
)
ids
=
ActiveRecord
::
Base
.
connection
.
select_all
(
"select distinct taggable_id from ci_taggings where taggable_type =
#{
ActiveRecord
::
Base
::
sanitize
(
type
)
}
"
puts
'Resetting counters... '
connection
.
execute
(
'UPDATE tags SET '
+
'taggings_count = (SELECT COUNT(*) FROM taggings WHERE tags.id = taggings.tag_id)'
)
ids
.
map
{
|
id
|
id
[
'taggable_id'
]
}
end
end
def
list_tags
(
type
,
id
)
tags
=
ActiveRecord
::
Base
.
connection
.
select_all
(
'select ci_tags.name from ci_tags '
+
'join ci_taggings on ci_tags.id = ci_taggings.tag_id '
+
"where taggable_type =
#{
ActiveRecord
::
Base
::
sanitize
(
type
)
}
and taggable_id =
#{
ActiveRecord
::
Base
::
sanitize
(
id
)
}
and context = 'tags'"
)
tags
.
map
{
|
tag
|
tag
[
'name'
]
}
protected
def
connection
ActiveRecord
::
Base
.
connection
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