length constrain on the index, not on the column

we actually don't need a limit on the column itself for MySQL to work.
we need to set a length on the index.
This commit is contained in:
Alexis Reigel 2017-07-20 22:07:04 +02:00
parent 57ccff8ea4
commit c4c44c6a1b
3 changed files with 20 additions and 11 deletions

View file

@ -7,12 +7,12 @@ class CreateGpgKeys < ActiveRecord::Migration
t.references :user, index: true, foreign_key: { on_delete: :cascade }
t.binary :primary_keyid, limit: Gitlab::Database.mysql? ? 20 : nil
t.binary :fingerprint, limit: Gitlab::Database.mysql? ? 20 : nil
t.binary :primary_keyid
t.binary :fingerprint
t.text :key
t.index :primary_keyid
t.index :primary_keyid, length: Gitlab::Database.mysql? ? 20 : nil
end
end
end

View file

@ -10,14 +10,14 @@ class CreateGpgSignatures < ActiveRecord::Migration
t.boolean :valid_signature
t.binary :commit_sha, limit: Gitlab::Database.mysql? ? 20 : nil
t.binary :gpg_key_primary_keyid, limit: Gitlab::Database.mysql? ? 20 : nil
t.binary :commit_sha
t.binary :gpg_key_primary_keyid
t.text :gpg_key_user_name
t.text :gpg_key_user_email
t.index :commit_sha
t.index :gpg_key_primary_keyid
t.index :commit_sha, length: Gitlab::Database.mysql? ? 20 : nil
t.index :gpg_key_primary_keyid, length: Gitlab::Database.mysql? ? 20 : nil
end
end
end

View file

@ -1,5 +1,9 @@
# rubocop:disable all
require Rails.root.join('lib/gitlab/database/migration_helpers.rb')
class LimitsToMysql < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
def up
return unless ActiveRecord::Base.configurations[Rails.env]['adapter'] =~ /^mysql/
@ -8,9 +12,14 @@ class LimitsToMysql < ActiveRecord::Migration
change_column :snippets, :content, :text, limit: 2147483647
change_column :notes, :st_diff, :text, limit: 2147483647
change_column :events, :data, :text, limit: 2147483647
change_column :gpg_keys, :primary_keyid, :binary, limit: 20
change_column :gpg_keys, :fingerprint, :binary, limit: 20
change_column :gpg_signatures, :commit_sha, :binary, limit: 20
change_column :gpg_signatures, :gpg_key_primary_keyid, :binary, limit: 20
[
[:gpg_keys, :primary_keyid],
[:gpg_signatures, :commit_sha],
[:gpg_signatures, :gpg_key_primary_keyid]
].each do |table_name, column_name|
remove_index table_name, column_name if index_exists?(table_name, column_name)
add_concurrent_index table_name, column_name, length: 20
end
end
end