mastodon.zunda.ninja is one of the many independent Mastodon servers you can use to participate in the fediverse.
Zundon is a single user instance as home of @zundan as well as a test bed for changes of the code.

Administered by:

Server stats:

1
active users

Masterに追随できませんすたー。ひゃー。

Migrating to AddCaseInsensitiveIndexToTags (20190726175042)
== 20190726175042 AddCaseInsensitiveIndexToTags: migrating ====================
-- execute("CREATE UNIQUE INDEX CONCURRENTLY index_tags_on_name_lower ON tags (lower(name))")
rake aborted!
StandardError: An error has occurred, all later migrations canceled:

PG::UniqueViolation: ERROR: could not create unique index "index_tags_on_name_lower"
DETAIL: Key (lower(name::text))=(ドット絵) is duplicated.
: CREATE UNIQUE INDEX CONCURRENTLY index_tags_on_name_lower ON tags (lower(name))

どうすればいいのだー

$ heroku pg:psql -a zundan-mastodon
SELECT * FROM tags WHERE name='ドット絵';
id | name | created_at | updated_at
-------+----------+----------------------------+----------------------------
6861 | ドット絵 | 2017-12-08 00:19:35.793832 | 2017-12-08 00:19:35.793832
33453 | ドット絵 | 2018-12-21 23:16:44.551211 | 2018-12-21 23:16:44.551211
(2 rows)

2つのテーブルから別々のIDで参照されてるんだねぇ

> \d tags
:
Referenced by:
TABLE "account_tag_stats" CONSTRAINT "fk_rails_1fa34bab2d" FOREIGN KEY (tag_id) REFERENCES tags(id) ON DELETE CASCADE
TABLE "featured_tags" CONSTRAINT "fk_rails_23a9055c7c" FOREIGN KEY (tag_id) REFERENCES tags(id) ON DELETE CASCADE
TABLE "statuses_tags" CONSTRAINT "fk_rails_623fc2c83d" FOREIGN KEY (tag_id) REFERENCES tags(id) ON DELETE CASCADE
> SELECT id, tag_id FROM account_tag_stats where tag_id=6861 OR tag_id=33453;
id | tag_id
-----+--------
910 | 33453
(1 row)

> SELECT id, tag_id FROM featured_tags where tag_id=6861 OR tag_id=33453;
id | tag_id
----+--------
(0 rows)

> SELECT * FROM statuses_tags where tag_id=6861 OR tag_id=33453;
status_id | tag_id
--------------------+--------
99133468401332852 | 6861
:
102412648813550940 | 6861
(27 rows)

うりゃ。

> UPDATE account_tag_stats SET tag_id=6861 WHERE id=910;
UPDATE 1

あ、できた。

> DELETE FROM tags WHERE id=33453;

お、できた。

もう一度プロモーションしてみるよ!

$ heroku pipelines:promote
$ heroku releases:output
D, [2019-07-28T19:06:20.321073 #53] DEBUG -- : [httplog] Connecting: checkin.scoutapp.com:443
Migrating to AddCaseInsensitiveIndexToTags (20190726175042)
== 20190726175042 AddCaseInsensitiveIndexToTags: migrating ====================
-- execute("CREATE UNIQUE INDEX CONCURRENTLY index_tags_on_name_lower ON tags (lower(name))")
rake aborted!
StandardError: An error has occurred, all later migrations canceled:

PG::DuplicateTable: ERROR: relation "index_tags_on_name_lower" already exists
: CREATE UNIQUE INDEX CONCURRENTLY index_tags_on_name_lower ON tags (lower(name))
:

もうひといきだね

> DROP INDEX CONCURRENTLY index_tags_on_name_lower;
DROP INDEX

PG::UniqueViolation: ERROR: could not create unique index "index_tags_on_name_lower"
DETAIL: Key (lower(name::text))=(銀河丼だじゃれ部) is duplicated.

ぐぬぬーw

@zundan この件について Issue 書こうと考えているのですが、zunda さんのこのトゥートの内容を転載したいのですがよろしいでしょうか?

zunda

@mayaeh ありがとうございます。ぜひぜひお願いします!こちらで理解してからIssueを書こうとも思ったのですが、時間がかかりそうな気配です。

@zundan ありがとうございます!
私が遭遇している内容については大文字・小文字で存在するためと思われます。
ただ zunda さんのは日本語オンリーのものでも起きているようなので、そこは私にはまだ分からない状態です。

@zundan すみません勘違いしていました。
私のケースも zunda さんと同じ理由だろうと思います ( 大文字小文字で duplicate かと思っていましたがそもそも全て小文字で格納されているので重複するはずがなく…

@mayaeh これまでの歴史で同じnameのタグのレコードが複数作られちゃう場面があった感じですかねー

@zundan Mastodon の db:migrate でこける件、オイゲンさんのこの PR で直ると思います。
github.com/tootsuite/mastodon/
ただし 11416 後に db:migrate した環境だとまだ苦労するかもしれません… ( 私はこの時まで db:rollback を知りませんでした…実行済みの場合は問題ないのかもしれません

github.comFix tag normalization and migration not removing duplicate tags by Gargron · Pull Request #11441 · tootsuite/mastodonFix #11428

@mayaeh おお! ちょうどデプロイを始めたころにmergeされたようです。今のビルドをデプロイしたら次に適用してみますね。ただ、こちらのデータベースだとGROUP BY nameで同一視されるようなtagが問題になってたようなので規格化の改良でなおったかどうかはわかりません (そして無理やり重複tagを消しちゃったのでテストにもならない…)。もちっと冷静に進めときゃよかったですね←

https://gist.github.com/zunda/45330d4cf860deae275a8474aedf1ccc

gist.github.comDuplicate tags for mastodon.zunda.ninja as of 2019-07-28 22:00 UTCDuplicate tags for mastodon.zunda.ninja as of 2019-07-28 22:00 UTC - gist:45330d4cf860deae275a8474aedf1ccc

@zundan こちらもテスト鯖の方では強引に進めた部分があり自信がない状態です…(汗
明日ここに適用した時に分かるかも?

@zundan ってわお…すごい数あったんですね、、、

@mayaeh 歴史の重み的な…ww

@mayaeh 今デプロイしましたがdb:migrateは何もしませんでしたー。すでに改善前ので走ちゃってるからですね、きっと。