Skip to content
Snippets Groups Projects
Commit db577200 authored by Dan Knox's avatar Dan Knox
Browse files

Add a safe migration mode to the wiki migrator.

The safe migrate mode can be invoked by setting the
safe_migrate environment variable to 'true' on the command
line when running the task.

RAILS_ENV=production rake gitlab:wiki:migrate
parent 951273ff
No related branches found
No related tags found
3 merge requests!104685 0 stable,!3933Merge 5.0.1 into 5.1,!3719Add a safe migration mode to the wiki migrator.
Loading
@@ -11,7 +11,13 @@ namespace :gitlab do
Loading
@@ -11,7 +11,13 @@ namespace :gitlab do
# Notes: # Notes:
# * The existing Wiki content will remain in your # * The existing Wiki content will remain in your
# database in-tact. # 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 task :migrate => :environment do
wiki_migrator = WikiToGollumMigrator.new wiki_migrator = WikiToGollumMigrator.new
wiki_migrator.migrate! wiki_migrator.migrate!
Loading
Loading
# encoding: UTF-8
class WikiToGollumMigrator class WikiToGollumMigrator
   
attr_reader :projects attr_reader :projects
Loading
@@ -84,7 +86,7 @@ class WikiToGollumMigrator
Loading
@@ -84,7 +86,7 @@ class WikiToGollumMigrator
# and revision created so the correct User is shown in # and revision created so the correct User is shown in
# the commit message. # the commit message.
wiki = GollumWiki.new(project, revision.user) 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) attributes = extract_attributes_from_page(revision, project)
   
Loading
@@ -103,6 +105,10 @@ class WikiToGollumMigrator
Loading
@@ -103,6 +105,10 @@ class WikiToGollumMigrator
.with_indifferent_access .with_indifferent_access
.slice(:title, :content) .slice(:title, :content)
   
if ENV["safe_migrate"] == "true"
attributes[:title] = gollum_safe_title(attributes[:title])
end
slug = page.slug slug = page.slug
   
# Change 'index' pages to 'home' pages to match Gollum standards # Change 'index' pages to 'home' pages to match Gollum standards
Loading
@@ -113,6 +119,10 @@ class WikiToGollumMigrator
Loading
@@ -113,6 +119,10 @@ class WikiToGollumMigrator
attributes attributes
end end
   
def gollum_safe_title(title)
title.parameterize.titleize
end
def home_already_exists?(project) def home_already_exists?(project)
project.wikis.where(slug: 'home').any? || project.wikis.where(slug: 'Home').any? project.wikis.where(slug: 'home').any? || project.wikis.where(slug: 'Home').any?
end end
Loading
Loading
# encoding: UTF-8
require "spec_helper" require "spec_helper"
   
describe WikiToGollumMigrator do describe WikiToGollumMigrator do
Loading
@@ -137,6 +139,98 @@ describe WikiToGollumMigrator do
Loading
@@ -137,6 +139,98 @@ describe WikiToGollumMigrator do
end end
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!
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.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 context "changing wiki title from index to home" do
before do before do
@project = @projects.last @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