Can't upgrade Discourse because of missing index


(Sander Datema) #1

The error is Index name 'index_topic_custom_fields_on_value' on table 'topic_custom_fields' does not exist. Btw, this is a multisite setup.

Full log:

== 20160326001747 AddUserFirstVisit: migrating ================================
-- add_column(:users, :first_seen_at, :datetime)
   -> 0.0084s
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

Index name 'index_topic_custom_fields_on_value' on table 'topic_custom_fields' does not exist
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/schema_statements.rb:1003:in `index_name_for_remove'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/schema_statements.rb:593:in `remove_index'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.6/lib/active_record/migration.rb:665:in `block in method_missing'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.6/lib/active_record/migration.rb:634:in `block in say_with_time'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.6/lib/active_record/migration.rb:634:in `say_with_time'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.6/lib/active_record/migration.rb:654:in `method_missing'
/var/www/discourse/db/migrate/20160520022627_shorten_topic_custom_fields_index.rb:3:in `up'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.6/lib/active_record/migration.rb:611:in `exec_migration'
/var/www/discourse/lib/freedom_patches/schema_migration_details.rb:7:in `block in exec_migration'
/var/www/discourse/lib/freedom_patches/schema_migration_details.rb:6:in `exec_migration'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.6/lib/active_record/migration.rb:592:in `block (2 levels) in migrate'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.6/lib/active_record/migration.rb:591:in `block in migrate'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:292:in `with_connection'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.6/lib/active_record/migration.rb:590:in `migrate'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.6/lib/active_record/migration.rb:768:in `migrate'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.6/lib/active_record/migration.rb:998:in `block in execute_migration_in_transaction'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.6/lib/active_record/migration.rb:1044:in `block in ddl_transaction'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/transaction.rb:184:in `within_new_transaction'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.6/lib/active_record/transactions.rb:220:in `transaction'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.6/lib/active_record/migration.rb:1044:in `ddl_transaction'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.6/lib/active_record/migration.rb:997:in `execute_migration_in_transaction'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.6/lib/active_record/migration.rb:959:in `block in migrate'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.6/lib/active_record/migration.rb:955:in `each'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.6/lib/active_record/migration.rb:955:in `migrate'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.6/lib/active_record/migration.rb:823:in `up'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.6/lib/active_record/migration.rb:801:in `migrate'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.6/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.6/lib/active_record/railties/databases.rake:44:in `block (2 levels) in '
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/rails_multisite-1.0.4/lib/tasks/db.rake:8:in `block (2 levels) in '
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/rails_multisite-1.0.4/lib/rails_multisite/connection_management.rb:124:in `call'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/rails_multisite-1.0.4/lib/rails_multisite/connection_management.rb:124:in `block in each_connection'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/rails_multisite-1.0.4/lib/rails_multisite/connection_management.rb:122:in `each'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/rails_multisite-1.0.4/lib/rails_multisite/connection_management.rb:122:in `each_connection'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/rails_multisite-1.0.4/lib/tasks/db.rake:3:in `block in '
/usr/local/bin/bundle:22:in `load'
/usr/local/bin/bundle:22:in `
'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
== 20160326001747 AddUserFirstVisit: migrated (0.0216s) =======================

== 20160520022627 ShortenTopicCustomFieldsIndex: migrating ====================
-- remove_index(:topic_custom_fields, :value)

(Sam Saffron) #2

Are you using our docker based install?

Can you find the incorrect name of the index, I can add a fallback.

./launcher enter app
sudo -u postgres psql discourse

psql> \d topic_custom_fields

(Sander Datema) #3

I’ve been using the Docker based install for decades! :wink:

Not sure if I can get the data you need. After this error I did a rebuild, that failed as well. But now the database is behind, while the code is updated to the latest commit. :frowning:

Anyway, your command gets this result:

discourse=# \d topic_custom_fields
                                     Table "public.topic_custom_fields"
   Column   |            Type             |                            Modifiers
------------+-----------------------------+------------------------------------------------------------------
 id         | integer                     | not null default nextval('topic_custom_fields_id_seq'::regclass)
 topic_id   | integer                     | not null
 name       | character varying(256)      | not null
 value      | text                        |
 created_at | timestamp without time zone | not null
 updated_at | timestamp without time zone | not null
Indexes:
    "topic_custom_fields_pkey" PRIMARY KEY, btree (id)
    "index_topic_custom_fields_on_topic_id_and_name" btree (topic_id, name)
    "topic_custom_fields_value_key_idx" btree (value, name) WHERE value IS NOT NULL AND char_length(value) < 400

BTW, this is only the first database in the multisite list.


(Sam Saffron) #4

hmmm it looks like this particular migration has run but somehow it was not logged, no idea how this happened.

if you drop the topic_custom_fields_value_key_idx and add an index called index_topic_custom_fields_on_value and rerun migrations it should all start working.


(Sander Datema) #5

Would love to, but have no idea how… Could you please give the two command I’d need to run?


(Sam Saffron) #6

let me know if this works

drop index topic_custom_fields_value_key_idx;
create index index_topic_custom_fields_on_value on topic_custom_fields(value);

(Sander Datema) #7

Thanks! That fixed it. Odd thing: it wasn’t necessary for all the databases. Some needed only the first, other only the second command. But the main discourse database needed both.

Migrating now worked fine.