Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Database migration fails while upgrading from v2.9.3 --> v3.0.0 (or v3.0.1) #12516

Closed
Vertux opened this issue Dec 1, 2019 · 7 comments
Closed

Database migration fails while upgrading from v2.9.3 --> v3.0.0 (or v3.0.1) #12516

Vertux opened this issue Dec 1, 2019 · 7 comments

Comments

@Vertux
Copy link

@Vertux Vertux commented Dec 1, 2019

Expected behaviour

A clean database migration without errors

Actual behaviour

if I start the database migration with SKIP_POST_DEPLOYMENT_MIGRATIONS=true RAILS_ENV=production bundle exec rails db:migrate it throws an error:

Migrating to AddInstanceActor (20190715164535)
== 20190715164535 AddInstanceActor: migrating =================================
== 20190715164535 AddInstanceActor: migrated (0.1109s) ========================

Migrating to AddCaseInsensitiveIndexToTags (20190726175042)
== 20190726175042 AddCaseInsensitiveIndexToTags: migrating ====================
-- execute("UPDATE accounts_tags AS t0 SET tag_id = 19467 WHERE tag_id IN (19627, 6804) AND NOT EXISTS (SELECT t1.tag_id FROM accounts_tags AS t1 WHERE t1.tag_id = 19467 AND t1.account_id = t0.account_id)")
   -> 0.0005s
-- execute("UPDATE statuses_tags AS t0 SET tag_id = 19467 WHERE tag_id IN (19627, 6804) AND NOT EXISTS (SELECT t1.tag_id FROM statuses_tags AS t1 WHERE t1.tag_id = 19467 AND t1.status_id = t0.status_id)")
   -> 0.0496s

[…..truncated….]

-- execute("CREATE UNIQUE INDEX CONCURRENTLY index_tags_on_name_lower ON tags (lower(name))")
   -> 0.1186s
-- remove_index(:tags, {:name=>"index_tags_on_name"})
rails aborted!
StandardError: An error has occurred, all later migrations canceled:

PG::UndefinedObject: ERROR:  index "index_tags_on_name" does not exist
: DROP INDEX  "index_tags_on_name"
/home/mastodon/live/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql/database_statements.rb:75:in `async_exec'
/home/mastodon/live/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql/database_statements.rb:75:in `block (2 levels) in execute'

[…..truncated….]

Steps to reproduce the problem

  • systemctl stop mastodon-*.service
  • upgrade codebase (release notes)
  • drop database, restore database from backup (v2.9.3)
  • SKIP_POST_DEPLOYMENT_MIGRATIONS=true RAILS_ENV=production bundle exec rails db:migrate

Specifications

Mastodon v3.0.0 (non Docker)

@ThibG

This comment has been minimized.

Copy link
Collaborator

@ThibG ThibG commented Dec 2, 2019

I don't understand why the index_tags_on_name index wouldn't exist, it should have been in here since 2016… did you do anything weird with your database in the past?

@Vertux

This comment has been minimized.

Copy link
Author

@Vertux Vertux commented Dec 3, 2019

I did not manually modify my database in any way. Is there a way to manually fix the index issue ?

@ThibG

This comment has been minimized.

Copy link
Collaborator

@ThibG ThibG commented Dec 3, 2019

@Vertux

This comment has been minimized.

Copy link
Author

@Vertux Vertux commented Dec 4, 2019

I wish I could you give you a hint, but all the former updates worked very well, I cannot remember any error. I have checked an older database backup and it had the same error. I can't completely rule out that i missed an error when I applied a previous update - i am running the instance quite a long time.

@Vertux

This comment has been minimized.

Copy link
Author

@Vertux Vertux commented Dec 14, 2019

@ThibG can you give me the location and filename where I have to comment out “remove_index” please ? I have looked for it already, but I have found a couple of locations and was unsure, which is the right one.

@ThibG

This comment has been minimized.

Copy link
Collaborator

@ThibG ThibG commented Dec 14, 2019

That would be db/migrate/20190726175042_add_case_insensitive_index_to_tags.rb, line 19: remove_index :tags, name: 'index_tags_on_name'

@Vertux

This comment has been minimized.

Copy link
Author

@Vertux Vertux commented Dec 14, 2019

Thank you @ThibG for the quick answer, it worked very well, now the instance is running on v3.0.1 again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.