Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
gpt
large_projects
gitlabhq1
Commits
0702bd67
Commit
0702bd67
authored
12 years ago
by
Dmitriy Zaporozhets
Browse files
Options
Download
Plain Diff
Merge pull request #3719 from DanKnox/add_safe_wiki_migration
Add a safe migration mode to the wiki migrator.
parents
951273ff
58ca7553
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
114 additions
and
3 deletions
+114
-3
lib/tasks/gitlab/migrate_wiki.rake
lib/tasks/gitlab/migrate_wiki.rake
+7
-1
lib/wiki_to_gollum_migrator.rb
lib/wiki_to_gollum_migrator.rb
+12
-2
spec/lib/wiki_to_gollum_migrator_spec.rb
spec/lib/wiki_to_gollum_migrator_spec.rb
+95
-0
No files found.
lib/tasks/gitlab/migrate_wiki.rake
View file @
0702bd67
...
...
@@ -11,7 +11,13 @@ namespace :gitlab do
# Notes:
# * The existing Wiki content will remain in your
# database in-tact.
desc
"GITLAB | Migrate Wiki content from database to Gollum repositories."
# * If the migration does not work the first time,
# run the `RAILS_ENV=production rake gitlab:wiki:rollback`
# command and then execute the migration again with
# the safe_migrate=true environment variable:
#
# `RAILS_ENV=production rake gitlab:wiki:migrate safe_migrate=true`
desc
"GITLAB | Migrate Wiki content from database to Gollum repositories. Use the safe_migrate=true argument if initial migration fails."
task
:migrate
=>
:environment
do
wiki_migrator
=
WikiToGollumMigrator
.
new
wiki_migrator
.
migrate!
...
...
This diff is collapsed.
Click to expand it.
lib/wiki_to_gollum_migrator.rb
View file @
0702bd67
# encoding: UTF-8
class
WikiToGollumMigrator
attr_reader
:projects
...
...
@@ -53,7 +55,7 @@ class WikiToGollumMigrator
def
create_page_and_revisions
(
project
,
page
)
# Grab all revisions of the page
revisions
=
project
.
wikis
.
where
(
slug:
page
.
slug
).
order
ed
.
all
revisions
=
project
.
wikis
.
where
(
slug:
page
.
slug
).
order
(
'id desc'
)
.
all
# Remove the first revision created from the array
# and use it to create the Gollum page. Each successive revision
...
...
@@ -84,7 +86,7 @@ class WikiToGollumMigrator
# and revision created so the correct User is shown in
# the commit message.
wiki
=
GollumWiki
.
new
(
project
,
revision
.
user
)
wiki_page
=
wiki
.
find_page
(
page
.
slug
)
wiki_page
=
wiki
.
find_page
(
page
.
title
)
attributes
=
extract_attributes_from_page
(
revision
,
project
)
...
...
@@ -103,6 +105,10 @@ class WikiToGollumMigrator
.
with_indifferent_access
.
slice
(
:title
,
:content
)
if
ENV
[
"safe_migrate"
]
==
"true"
attributes
[
:title
]
=
gollum_safe_title
(
attributes
[
:title
])
end
slug
=
page
.
slug
# Change 'index' pages to 'home' pages to match Gollum standards
...
...
@@ -113,6 +119,10 @@ class WikiToGollumMigrator
attributes
end
def
gollum_safe_title
(
title
)
title
.
parameterize
.
titleize
end
def
home_already_exists?
(
project
)
project
.
wikis
.
where
(
slug:
'home'
).
any?
||
project
.
wikis
.
where
(
slug:
'Home'
).
any?
end
...
...
This diff is collapsed.
Click to expand it.
spec/lib/wiki_to_gollum_migrator_spec.rb
View file @
0702bd67
# encoding: UTF-8
require
"spec_helper"
describe
WikiToGollumMigrator
do
...
...
@@ -137,6 +139,99 @@ describe WikiToGollumMigrator do
end
end
context
"when migrating wiki's with extra whitespace in the title"
do
before
do
subject
.
rollback!
ENV
[
'safe_migrate'
]
=
'true'
@project
=
@projects
.
last
@page
=
@project
.
wikis
.
new
(
title:
"2012-06-16 "
,
content:
"Page with funky title"
)
@page
.
slug
=
@page
.
title
.
parameterize
@page
.
user
=
@project
.
owner
@page
.
save!
3
.
times
{
create_revision
(
@page
)
}
subject
.
migrate!
end
it
"creates the wiki page correctly"
do
wiki
=
GollumWiki
.
new
(
@project
,
nil
)
page
=
wiki
.
find_page
(
"2012 06 16"
)
page
.
should
be_present
page
.
content
.
should
==
"Updated Content"
page
.
versions
.
count
.
should
==
2
end
end
context
"when migrating wiki's with slashes in the title"
do
before
do
subject
.
rollback!
ENV
[
'safe_migrate'
]
=
'true'
@project
=
@projects
.
last
@page
=
@project
.
wikis
.
new
(
title:
"Awesome 1337 /bin/badass "
,
content:
"Page with funky title"
)
@page
.
slug
=
@page
.
title
.
parameterize
@page
.
user
=
@project
.
owner
@page
.
save!
create_revision
(
@page
)
subject
.
migrate!
end
it
"creates the wiki page correctly"
do
wiki
=
GollumWiki
.
new
(
@project
,
nil
)
page
=
wiki
.
find_page
(
"Awesome 1337 Bin Badass"
)
page
.
should
be_present
page
.
versions
.
count
.
should
==
2
end
end
context
"when migrating wiki's with non alphanumeric characters in the title"
do
before
do
subject
.
rollback!
ENV
[
'safe_migrate'
]
=
'true'
@project
=
@projects
.
last
@page
=
@project
.
wikis
.
new
(
title:
"Awes@me-1337 #!/bin/badass? "
,
content:
"Page with funky title"
)
@page
.
slug
=
@page
.
title
.
parameterize
@page
.
user
=
@project
.
owner
@page
.
save!
create_revision
(
@page
)
subject
.
migrate!
end
it
"creates the wiki page correctly"
do
wiki
=
GollumWiki
.
new
(
@project
,
nil
)
page
=
wiki
.
find_page
(
"Awes Me 1337 Bin Badass"
)
page
.
should
be_present
page
.
versions
.
count
.
should
==
2
end
end
context
"when migrating wiki's with non-english characters in the title"
do
before
do
subject
.
rollback!
ENV
[
'safe_migrate'
]
=
'true'
@project
=
@projects
.
last
@page
=
@project
.
wikis
.
new
(
title:
"Mögliche Aufteilung"
,
content:
"Page with funky title"
)
@page
.
slug
=
@page
.
title
.
parameterize
@page
.
user
=
@project
.
owner
@page
.
save!
create_revision
(
@page
)
subject
.
migrate!
end
it
"creates the wiki page correctly"
do
wiki
=
GollumWiki
.
new
(
@project
,
nil
)
page
=
wiki
.
find_page
(
"Mogliche Aufteilung"
)
page
.
should
be_present
page
.
versions
.
count
.
should
==
2
end
end
context
"changing wiki title from index to home"
do
before
do
@project
=
@projects
.
last
...
...
This diff is collapsed.
Click to expand it.
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