Migration fails in 7.10.2 when trying to add unique index on tags
Created by: dreis2211
Hey,
i just updated to 7-10-stable and experienced a bug when trying to migrate our database.
gitlab:/home/git/gitlab# sudo -u git -H bundle exec rake db:migrate RAILS_ENV=production
== 20150425164648 AddMissingUniqueIndices: migrating ==========================
-- add_index(:tags, :name, {:unique=>true})
rake aborted!
StandardError: An error has occurred, all later migrations canceled:
Mysql2::Error: Duplicate entry 'ios' for key 'index_tags_on_name': CREATE UNIQUE INDEX `index_tags_on_name` ON `tags` (`name`) /home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/activerecord-4.1.9/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:303:in `query'
/home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/activerecord-4.1.9/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:303:in `block in execute'
/home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/activerecord-4.1.9/lib/active_record/connection_adapters/abstract_adapter.rb:373:in `block in log'
/home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.9/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/activerecord-4.1.9/lib/active_record/connection_adapters/abstract_adapter.rb:367:in `log'
/home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/activerecord-4.1.9/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:303:in `execute'
/home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/activerecord-4.1.9/lib/active_record/connection_adapters/mysql2_adapter.rb:228:in `execute'
/home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/activerecord-4.1.9/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:525:in `add_index'
/home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/activerecord-4.1.9/lib/active_record/migration.rb:656:in `block in method_missing'
/home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/activerecord-4.1.9/lib/active_record/migration.rb:628:in `block in say_with_time'
/home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/activerecord-4.1.9/lib/active_record/migration.rb:628:in `say_with_time'
/home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/activerecord-4.1.9/lib/active_record/migration.rb:648:in `method_missing'
/home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/activerecord-4.1.9/lib/active_record/migration.rb:413:in `method_missing'
/home/git/gitlab/db/migrate/20150425164648_add_missing_unique_indices.acts_as_taggable_on_engine.rb:4:in `up'
The problem is that unique indexes in MySQL are depending on the underlying collation of the field. In GitLab this is case-insensitive as default, so adding unique indexes will break if there is a row with "IOS" and one with "ios" in the tags table.
The commit that introduced the bug, is https://github.com/gitlabhq/gitlabhq/commit/81634bc1f7d8abb1686ca0cf2318bc02f3c7d97c
It already contains a change of the collation, but is applied too late.
I don't know what procedure you're following in that case. Deleting the migration, adjusting it, adjusting the table or whatever. Otherwise I'd do the PR myself.
See the following commit for additional information, that tags should be strictly case matching. https://github.com/gitlabhq/gitlabhq/commit/45de7d263d8494d0aaaf99d7a6c44f7f9d2adf09
Cheers.