Upgrading Typo 4.0.3

0

升級前注意事項

升級前務必備份,而且是 MySQL 備份。typo installer 升級採先備份 yml,洗光,改結構,注入舊備份 yml。

問題是這個流程中,備份採用 YAML 格式,這個格式非常不適合處理多行資料,特別是中間有一大堆雙引號與奇怪程式碼的內容,往往會出現資料回復 YAML.load_file 時卡住現象,如果不想幾千筆資料用手慢慢清的人,請務必先用 mysqldump 做些預防。

開始

第一次升級,之前參照 這裡 是用專屬的 gem 做法,所以一開始就打算用懶人 installer 升級法。

$ gem install typo
Bulk updating Gem source index for: http://gems.rubyforge.org
Install required dependency rails-app-installer? [Yn]  y
Successfully installed typo-4.0.3
Successfully installed rails-app-installer-0.2.0
Installing ri documentation for rails-app-installer-0.2.0...
Installing RDoc documentation for rails-app-installer-0.2.0...

$ gem list | grep typo
typo (4.0.3, 4.0.2)

$ gem uninstall typo

Select RubyGem to uninstall:
 1. typo-4.0.2
 2. typo-4.0.3
 3. All versions
> 1
Successfully uninstalled typo version 4.0.2

付諸流水

接下來就是一連串問題的開始。因為覺得用 Rail Application Installer 應該很方便,可以幫忙更新檔案與資料庫結構,結果是東西不用不明白。

$ typo install blog.extremepattern.com
 Installing typo 4.0.3
.......
 Checking database
 Database exists, preparing for upgrade
 Migrating Typo's database to newest release
........

 Running tests.  This may take a minute or two
 ***** Tests failed *****
 ** Please run 'rake test' by hand in your install directory.

以為只是測試失敗,沒管他,直接上網頁去看,居然跳出 signup 畫面,這通常是第一次登入才會出現,心中有不好的預感,很擔心資料庫全部被洗光,而我因為只有十幾筆資料,還沒有做 MySQL 備份。

結果是只剩下兩筆進去,而且系統也怪怪的,應該是吃了不乾淨的東西。

柳暗花明

心想還好這個 installer 有個新的 備分機制 ,安裝前會存放資料到 YAML 格式,於是試試看。

$ rails-restore db/backup/backup-20060820-2116.yml
Restoring data
 Restoring table articles_categories (17)
 Restoring table page_caches (0)
 Restoring table pings (0)
 Restoring table tags (0)
 Restoring table blacklist_patterns (0)
 Restoring table redirects (0)
 Restoring table resources (6)
 Restoring table sidebars (4)
 Restoring table categories (6)
 Restoring table contents (2)
 Restoring table notifications (0)
 Restoring table users (1)

欲哭無淚

可以復原,但是資料卻無法完全餵進去,只有兩筆內容可以。想說進管理頁面看看,會要求資料庫結構要升級,一按下去,卻停掉。

結果只剩下兩筆資料,這才發現轉成 YAML 有許多問題,特別是多行內容加上 text filter 語法的時候。

大海撈針

於是想辦法試看看要刪除哪裡才可以救回資料。

require "yaml" 
db = YAML:load_file "backup-20060820-2116.yml" 

發現在 windows 平台會秀出第幾行吃不去,完全吃不進去一點資料,但是 linux 平台卻吃進去兩筆停住。反覆修改後才救出這些資料,而且兩種平台改的地方還不一樣,不過主要是多行的雙引號問題導致,偏偏 textile 用雙引號當超連結使用,所以有些地方衝到。

大功告成

根據上面說明需要回到之前版本的資料庫結構。

$ rake migrate VERSION=49
$ rails-restore db/backup/backup-modify-20060820.yml

Restoring data
 Restoring table articles_categories (17)
 Restoring table page_caches (0)
 Restoring table pings (0)
 Restoring table tags (0)
 Restoring table blacklist_patterns (0)
 Restoring table redirects (0)
 Restoring table resources (6)
 Restoring table sidebars (4)
 Restoring table categories (6)
 Restoring table contents (13)
 Restoring table notifications (0)
 Restoring table users (1)
 Restoring table articles_tags (0)
 Restoring table text_filters (5)
 Restoring table triggers (0)
 Restoring table blogs (1)

$ rake migrate

美中不足

還是有問題,文章列表都是空的,進去看發現 contents 表的 type 欄位都是 NULL,但是 YAML 中卻是有 type: Article 這欄位,很奇怪。於是只好自己來

MySQL > update contents set type='Article'

來亂的

最後雖然列表出來,有些中文卻消失變成 \xFF 等格式,應該是為求讀入 YAML 將某些雙引號改單引號的結果,也只好一個個手動改回來。

Comments

(leave url/email »)

   Preview comment