diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2017-02-21 15:07:02 +0100 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2017-02-21 15:07:02 +0100 |
commit | 79696f5b7aaf260176355026e91af05d40d92d0c (patch) | |
tree | efee41993f5d006e9c5b717af4789576a09f50d4 /spec/lib | |
parent | 459a97d46812fecc59c973bad356935422c7f60e (diff) | |
download | gitlab-ce-79696f5b7aaf260176355026e91af05d40d92d0c.tar.gz |
Hash concurrent foreign key names similar to Railshash-concurrent-foreign-key-names
This was initially not implemented simply because I forgot about the
size limit of constraint names in PostgreSQL (63 bytes). Using the old
technique we can't add foreign keys for certain tables. For example,
adding a foreign key on
protected_branch_merge_access_levels.protected_branch_id would lead to
the following key name:
fk_protected_branch_merge_access_levels_protected_branches_protected_branch_id
This key is 78 bytes long, thus violating the PostgreSQL size
requirements.
The hashing strategy is copied from Rails' foreign_key_name() method,
which unfortunately is private and subject to change without notice.
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/gitlab/database/migration_helpers_spec.rb | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/spec/lib/gitlab/database/migration_helpers_spec.rb b/spec/lib/gitlab/database/migration_helpers_spec.rb index e94ca4fcfd2..e007044868c 100644 --- a/spec/lib/gitlab/database/migration_helpers_spec.rb +++ b/spec/lib/gitlab/database/migration_helpers_spec.rb @@ -101,6 +101,16 @@ describe Gitlab::Database::MigrationHelpers, lib: true do end end + describe '#concurrent_foreign_key_name' do + it 'returns the name for a foreign key' do + name = model.concurrent_foreign_key_name(:this_is_a_very_long_table_name, + :with_a_very_long_column_name) + + expect(name).to be_an_instance_of(String) + expect(name.length).to eq(13) + end + end + describe '#disable_statement_timeout' do context 'using PostgreSQL' do it 'disables statement timeouts' do |