# Bug OP-9431 - Multiple indexes found on journal columns when migrating from 11.4.1 to 12.0.1

Project: OpenProject
Status: closed
URL: https://community.openproject.org/work_packages/OP-9431

## Open points

_No work packages_

## Details

| Attribute | Value |
| --- | --- |
| Date |  |
| Priority | High |
| Module |  |
| Target versions | 12.1.0 |
| Observed in versions | 12.0.0 |
| Sprint | 12.1.0 |
| Backlog bucket |  |
| Bug found in version (deprecated) | 12.0.x |
| Found in mobile app version |  |
| Follow-up feedback e-mail |  |
| Requires doc change | No |
| Accessibility | No |
| Pull preview |  |
| List |  |
| Labels |  |

## People

| Attribute | Value |
| --- | --- |
| Assignee |  |
| Accountable |  |
| Product manager |  |
| Developers |  |
| Designer |  |
| Ordered by |  |
| Signed off by |  |
| Interest by |  |

## Planning

| Attribute | Value |
| --- | --- |
| Relevance |  |

## Costs

| Attribute | Value |
| --- | --- |
| Votes |  |
| Work |  |
| Labor costs |  |

## Description

### **Environment**:

Your OpenProject Version: 12.0.1 / Self Hosted

Operating System / Browser / OpenProject language: Debian 10

### **Logs**

``` text
== 20210615150558 AggregateJournals: migrated (0.0490s) =======================

I, [2021-11-17T23:08:57.189568 #13262]  INFO -- : Migrating to PolymorphicJournalData (20210616145324)
== 20210616145324 PolymorphicJournalData: migrating ===========================
-- change_table(:journals)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

Multiple indexes found on journals columns [:journable_id]. Specify an index name from index_journals_on_journable_id, index_journals_on_journable_id
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:1408:in `index_name_for_remove'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/postgresql/schema_statements.rb:470:in `remove_index'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/abstract/schema_definitions.rb:707:in `remove_index'
/opt/openproject/db/migrate/20210616145324_polymorphic_journal_data.rb:54:in `block in add_data_and_remove_index'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:490:in `change_table'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/migration.rb:929:in `block in method_missing'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/migration.rb:897:in `block in say_with_time'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/migration.rb:897:in `say_with_time'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/migration.rb:918:in `method_missing'
/opt/openproject/db/migrate/20210616145324_polymorphic_journal_data.rb:51:in `add_data_and_remove_index'
/opt/openproject/db/migrate/20210616145324_polymorphic_journal_data.rb:5:in `up'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/migration.rb:870:in `public_send'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/migration.rb:870:in `exec_migration'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/migration.rb:851:in `block (2 levels) in migrate'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/migration.rb:850:in `block in migrate'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:462:in `with_connection'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/migration.rb:849:in `migrate'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/migration.rb:1037:in `migrate'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/migration.rb:1329:in `block in execute_migration_in_transaction'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/migration.rb:1380:in `block in ddl_transaction'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/abstract/database_statements.rb:320:in `block in transaction'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/abstract/transaction.rb:319:in `block in within_new_transaction'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activesupport-6.1.4.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in `block (2 levels) in synchronize'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activesupport-6.1.4.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activesupport-6.1.4.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activesupport-6.1.4.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activesupport-6.1.4.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/abstract/transaction.rb:317:in `within_new_transaction'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/abstract/database_statements.rb:320:in `transaction'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/transactions.rb:209:in `transaction'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/migration.rb:1380:in `ddl_transaction'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/migration.rb:1328:in `execute_migration_in_transaction'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/migration.rb:1302:in `each'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/migration.rb:1302:in `migrate_without_lock'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/migration.rb:1251:in `block in migrate'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/migration.rb:1401:in `block in with_advisory_lock'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/migration.rb:1416:in `block in with_advisory_lock_connection'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:462:in `with_connection'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/migration.rb:1416:in `with_advisory_lock_connection'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/migration.rb:1397:in `with_advisory_lock'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/migration.rb:1251:in `migrate'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/migration.rb:1086:in `up'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/migration.rb:1061:in `migrate'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/tasks/database_tasks.rb:237:in `migrate'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/railties/databases.rake:92:in `block (3 levels) in <top (required)>'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/railties/databases.rake:90:in `each'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/railties/databases.rake:90:in `block (2 levels) in <top (required)>'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/rake-13.0.6/exe/rake:27:in `<top (required)>'
bin/bundle:110:in `load'
bin/bundle:110:in `<main>'

Caused by:
ArgumentError: Multiple indexes found on journals columns [:journable_id]. Specify an index name from index_journals_on_journable_id, index_journals_on_journable_id
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:1408:in `index_name_for_remove'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/postgresql/schema_statements.rb:470:in `remove_index'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/abstract/schema_definitions.rb:707:in `remove_index'
/opt/openproject/db/migrate/20210616145324_polymorphic_journal_data.rb:54:in `block in add_data_and_remove_index'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:490:in `change_table'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/migration.rb:929:in `block in method_missing'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/migration.rb:897:in `block in say_with_time'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/migration.rb:897:in `say_with_time'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/migration.rb:918:in `method_missing'
/opt/openproject/db/migrate/20210616145324_polymorphic_journal_data.rb:51:in `add_data_and_remove_index'
/opt/openproject/db/migrate/20210616145324_polymorphic_journal_data.rb:5:in `up'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/migration.rb:870:in `public_send'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/migration.rb:870:in `exec_migration'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/migration.rb:851:in `block (2 levels) in migrate'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/migration.rb:850:in `block in migrate'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:462:in `with_connection'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/migration.rb:849:in `migrate'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/migration.rb:1037:in `migrate'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/migration.rb:1329:in `block in execute_migration_in_transaction'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/migration.rb:1380:in `block in ddl_transaction'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/abstract/database_statements.rb:320:in `block in transaction'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/abstract/transaction.rb:319:in `block in within_new_transaction'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activesupport-6.1.4.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in `block (2 levels) in synchronize'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activesupport-6.1.4.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activesupport-6.1.4.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activesupport-6.1.4.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activesupport-6.1.4.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/abstract/transaction.rb:317:in `within_new_transaction'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/abstract/database_statements.rb:320:in `transaction'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/transactions.rb:209:in `transaction'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/migration.rb:1380:in `ddl_transaction'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/migration.rb:1328:in `execute_migration_in_transaction'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/migration.rb:1302:in `each'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/migration.rb:1302:in `migrate_without_lock'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/migration.rb:1251:in `block in migrate'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/migration.rb:1401:in `block in with_advisory_lock'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/migration.rb:1416:in `block in with_advisory_lock_connection'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:462:in `with_connection'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/migration.rb:1416:in `with_advisory_lock_connection'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/migration.rb:1397:in `with_advisory_lock'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/migration.rb:1251:in `migrate'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/migration.rb:1086:in `up'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/migration.rb:1061:in `migrate'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/tasks/database_tasks.rb:237:in `migrate'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/railties/databases.rake:92:in `block (3 levels) in <top (required)>'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/railties/databases.rake:90:in `each'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/railties/databases.rake:90:in `block (2 levels) in <top (required)>'
/opt/openproject/vendor/bundle/ruby/2.7.0/gems/rake-13.0.6/exe/rake:27:in `<top (required)>'
bin/bundle:110:in `load'
bin/bundle:110:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
```

Table structure was

``` text

                                          Table "public.journals"
     Column     |            Type             | Collation | Nullable |               Default                
----------------+-----------------------------+-----------+----------+--------------------------------------
 id             | integer                     |           | not null | nextval('journals_id_seq'::regclass)
 journable_type | character varying           |           |          | 
 journable_id   | integer                     |           |          | 
 user_id        | integer                     |           | not null | 0
 notes          | text                        |           |          | 
 created_at     | timestamp without time zone |           | not null | 
 version        | integer                     |           | not null | 0
 activity_type  | character varying           |           |          | 
Indexes:
    "journals_pkey" PRIMARY KEY, btree (id)
    "index_journals_on_journable_type_and_journable_id_and_version" UNIQUE, btree (journable_type, journable_id, version)
    "index_journals_on_activity_type" btree (activity_type)
    "index_journals_on_created_at" btree (created_at)
    "index_journals_on_journable_id" btree (journable_id)
    "index_journals_on_journable_type" btree (journable_type)
    "index_journals_on_user_id" btree (user_id)
```

### **Steps to reproduce:**

1.  Upgrade Openproject 11.4.1 to 12.0.1 from debian package
2.  Run `openproject configure`
3.  Above logs are seen.

### **Actual Behavior**

DB migration code finds multiple indexes on database.

### **Expected Behavior**

Database migration should be succeed.

**Notes**

1.  My installation is active from openproject 6.x.  So this issue may be invalid for newer users.
2.  I dropped indexes with following command on postgres. Then migration is succeed.

<!-- end list -->

``` sql
DROP INDEX "index_journals_on_journable_id";
DROP INDEX "index_journals_on_journable_type";
DROP INDEX "index_journals_on_created_at";
DROP INDEX "index_journals_on_user_id";
DROP INDEX "index_journals_on_activity_type";
DROP INDEX "index_journals_on_journable_type_and_journable_id_and_version";
```
