2017年9月12日火曜日

RedmineプラグインでMroongaを使うときのテスト

Full text search pluginRedmine XLSX format issue exporterが競合した話。
パッチのロード順でチケットが表示(issues#show)できなった。
パッチを提示してもらい、パッチを適用する位置を変更して対処した。
https://github.com/two-pack/redmine_xlsx_format_issue_exporter/issues/50

ここからが本題。
いつも開発環境はsqlite3でやっているが、Full text search pluginがMroongaを使用するので、Unofficial Redmine CookingのRedmine AnsiblePlaybook Unofficial Cooking Edition(闇鍋版)を使用した。
すると、rake redmine:plugins:testでRedmine XLSX format issue exporterのテストを実行すると以下のようなエラーが出た。
Mysql2::Error: The used table type doesn't support FULLTEXT indexes: CREATE fulltext INDEX `index_issue_contents_on_contents` 

調べて見るとdb/schema.rbにテーブル作成時のオプション指定が入らないことが原因。
プラグインでは以下のようなmigrateが書かれている。
create_table :issue_contents, options: "ENGINE=Mroonga" do |t|
            t.integer :project_id
            t.integer :issue_id, unique: true, null: false
            t.string :subject
            t.text :contents, limit: 16.megabytes
            t.integer :status_id
            t.boolean :is_private
          end
対してschema.rbは以下のような感じ。
create_table "issue_contents", force: :cascade do |t|
    t.integer "project_id", limit: 4
    t.integer "issue_id",   limit: 4,          null: false
    t.string  "subject",    limit: 255
    t.text    "contents",   limit: 4294967295
    t.integer "status_id",  limit: 4
    t.boolean "is_private"
  end

  add_index "issue_contents", ["contents"], name: "index_issue_contents_on_contee
nts", type: :fulltext

rakeでテストを実行するの際に、db:test:prepareで一度テーブルが削除されてから、schema.rbを元に作成し直す。
その際に、schema.rbにはENGINEがMroongaではなくInnoDBになってしまうので、FULLTEXTのインデックスが作れない。

結局、db/tasks/redmine.rakeを書き換えた上で、db:drop -> db:create -> db:migrate -> redmine:plugins:test の順で実行した。
config/application.rbでconfig.active_record.schema_format = :sqlとするとSQLに書きだされるため大丈夫というのも検索しているとあったが、db/structure.sqlにplugin分が書き込まれてないため、rake taskではテーブルがないとエラーになってだめだった。

RedmineプラグインをGitHub Actionsでテストする

Redmine Advent Calendar 2019 の Qiita で書きました。追っかけで もう一つ 。 Travis-CIで行っていたRedmineプラグインのCIを、GitHub Actionsに変更したものです。 GitHub Actionsをやってみようという...