November 06, 2004

MovableTypeをアップグレードしようとした件のつづき

Posted at November 6, 2004 09:40 AM in Fedora Core 2を自宅サーバに入れてみた .

前のエントリの続き。

MovableTypeのデータの格納にはPostgreSQLを使っている。pgAdmin(GUIなPostgreSQL管理ツール)でデータベースの中身を覗いてみると、確かにmt_fileinfoなんていうテーブルは作成されていない。とりあえずmt_fileinfoを作ってみるという方針にする。拡張子がpmだのcgiだのになってるファイルに片端からgrepを掛けると、アップグレード版のアーカイブに入っているmt-upgrade31.cgiの中に、mt_fileinfoを作成するコードが見つかった。

mt-upgrade31.cgiでは、設定されているデータベースの種類($mt->{cfg}->ObjectDriver)によって処理を切り分けて、データベースに対してテーブルの追加やインデックスの作成をし、スキーマを新しいバージョンのものに対応させる処理をしている。PostgreSQLに対する処理は110行目から153行目までにある。

elsif ($mt->{cfg}->ObjectDriver =~ /postgres/) {
        print "hoge";
        @stmts = add_once(\@stmts, $dbh, 'mt_blog', 'blog_ping_technorati', 'smallint')
            unless has_column($dbh, 'mt_blog', 'blog_ping_technorati');
        @stmts = add_once(\@stmts, $dbh, 'mt_blog', 'blog_children_modified_on', 'timestamp')
            unless has_column($dbh, 'mt_blog', 'blog_children_modified_on');
        push @stmts, ('alter table mt_blog add blog_custom_dynamic_templates varchar(25)',
                      "update mt_blog set blog_custom_dynamic_templates = 'none'")
            unless has_column($dbh, 'mt_blog', 'blog_custom_dynamic_template');
        @stmts = add_once(\@stmts, $dbh, 'mt_template', 'template_created_on', 'timestamp');
        @stmts = add_once(\@stmts, $dbh, 'mt_template', 'template_modified_on', 'timestamp');
        @stmts = add_once(\@stmts, $dbh, 'mt_template', 'template_created_by', 'integer');
        @stmts = add_once(\@stmts, $dbh, 'mt_template', 'template_modified_by', 'integer');
        push @stmts, ('alter table mt_template add template_build_dynamic smallint')
            unless has_column($dbh, 'mt_template', 'template_build_dynamic');
        push @stmts, ('update mt_template set template_build_dynamic = 0 where template_build_dynamic <> 1 or template_build_dynamic is null',
                      'alter table mt_template alter column template_build_dynamic set not null');
        push @stmts, ('alter table mt_category add category_parent integer',
                      'update mt_category set category_parent = 0',
                      'alter table mt_category alter column category_parent set not null')
            unless has_column($dbh, 'mt_category', 'category_parent');
        push @stmts, ("update mt_entry set entry_basename = '' where entry_basename is null",
                      'alter table mt_entry alter column entry_basename set not null');
        unless (has_column($dbh, 'mt_fileinfo', 'fileinfo_id')) {
            push @stmts, <<FILEINFO;
create table mt_fileinfo (
    fileinfo_id integer primary key,
    fileinfo_blog_id integer not null,
    fileinfo_entry_id integer,
    fileinfo_url varchar(255),
    fileinfo_file_path text,
    fileinfo_template_id integer,
    fileinfo_templatemap_id integer,
    fileinfo_archive_type varchar(255),
    fileinfo_category_id integer,
    fileinfo_startdate varchar(80),
    fileinfo_virtual smallint
)
FILEINFO
            push @stmts, ("create sequence mt_fileinfo_id",
                          "create index mt_fileinfo_blog_id on mt_fileinfo (fileinfo_blog_id)",
                          "create index mt_fileinfo_entry_id on mt_fileinfo (fileinfo_entry_id)",
                          "create index mt_fileinfo_url on mt_fileinfo (fileinfo_url)");
        }
    }

ここで、@stmtsにpushされている文字列が、PostgreSQLに対して実行されるSQL文となっている。これを手作業で打ち込んで、mt_fileinfoテーブルを作ったり何だりしてやると、とりあえず動くようになった。いい加減な処置なので、まだどこかにエラーの種が残っているかもしれないけど。

PostgreSQLにはコマンドベースの管理ツール"psql"が付属している。これを下のように起動してやる。-Uでユーザ名、-dでデータベース名を指定する。

#psql -U postgres -d mt

で、あとはひたすらSQL文をこぴぺこぴぺ。



Trackback

You can ping this entry by using http://windy.ac/MT/mt-tb.cgi/614 .

時代に足並み揃えてみました。動機は...特に無し、なんとなく。なのに、アップグレ...

Comments

Post a comment










Remember personal info?