作業メモ: Mastodon upgrade v2.4.3 → v2.4.4

v2.4.4 にアップグレードしようとしたら db:migrate でコケた。

$ docker-compose run --rm web rails db:migrate                                                                                                               
Migrating to CreateCustomFilters (20180628181026)
== 20180628181026 CreateCustomFilters: migrating ==============================
-- create_table(:custom_filters)
rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:

PG::DuplicateTable: ERROR:  relation "custom_filters" already exists
: CREATE TABLE "custom_filters" ("id" bigserial primary key, "account_id" bigint, "expires_at" timestamp, "phrase" text DEFAULT '' NOT NULL, "context" character varying[] DEFAULT '{}' NOT NULL, "
irreversible" boolean DEFAULT FALSE NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, CONSTRAINT "fk_rails_8b8d786993"
FOREIGN KEY ("account_id")
  REFERENCES "accounts" ("id")
 ON DELETE CASCADE)
(snip)

$ docker-compose run --rm web rails console
Default type scope order, limit and offset are ignored and will be nullified
Creating scope :cache_ids. Overwriting existing method Notification.cache_ids.
Chewy console strategy is `urgent`
Loading production environment (Rails 5.2.0)
irb(main):002:0> CustomFilter.count
=> 0

custom_filters テーブルが既に存在しているのに作ろうとしているらしい。中身空っぽだし、dropしてええやろ、ということで以下の修正を入れた。

$ vim db/migrate/20180628181026_create_custom_filters.rb
$ git diff
diff --git a/db/migrate/20180628181026_create_custom_filters.rb b/db/migrate/20180628181026_create_custom_filters.rb
index d19cf2e9d..701b25c3e 100644
--- a/db/migrate/20180628181026_create_custom_filters.rb
+++ b/db/migrate/20180628181026_create_custom_filters.rb
@@ -1,5 +1,6 @@
 class CreateCustomFilters < ActiveRecord::Migration[5.2]
   def change
+    drop_table :custom_filters
     create_table :custom_filters do |t|
       t.belongs_to :account, foreign_key: { on_delete: :cascade }
       t.datetime :expires_at

改めて実行したら成功したので、migrationファイルを元に戻しておく。

$ git checkout db/migrate/20180628181026_create_custom_filters.rb

assets:precompileは問題なし。

$ docker-compose run --rm web rails assets:precompile
yarn install v1.3.2
[1/6] Validating package.json...
[2/6] Resolving packages...
success Already up-to-date.
Done in 1.73s.
Webpacker is installed ? ?
Using /mastodon/config/webpacker.yml file for setting up webpack paths
Compiling…
Compiled all packs in /mastodon/public/packs

再起動して作業完了。

$ sudo systemctl restart mastodon

あとがき

v2.4.5がリリースされてた

Database migrations from earlier (pre-2.4.2) releases have been fixed to facilitate the upgrade

とのことなので、多分直ってると思われる。(追ってない)

タイトルとURLをコピーしました