Skip to content
Snippets Groups Projects
Commit 0702bd67 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets
Browse files

Merge pull request #3719 from DanKnox/add_safe_wiki_migration

Add a safe migration mode to the wiki migrator.
parents 951273ff 58ca7553
No related branches found
No related tags found
2 merge requests!104685 0 stable,!3933Merge 5.0.1 into 5.1
Loading
Loading
@@ -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!
Loading
Loading
# encoding: UTF-8
class WikiToGollumMigrator
 
attr_reader :projects
Loading
Loading
@@ -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).ordered.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
Loading
Loading
@@ -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)
 
Loading
Loading
@@ -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
Loading
Loading
@@ -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
Loading
Loading
# encoding: UTF-8
require "spec_helper"
 
describe WikiToGollumMigrator do
Loading
Loading
@@ -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
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment