blob: fdecf9a663b30e28c4bd8bfdf275300e449149ea (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# frozen_string_literal: true
require 'spec_helper'
require_migration!
RSpec.describe RemoveOldAsyncIndexTableNameLengthConstraint, schema: 20230523074248, feature_category: :database do
let(:migration) { described_class.new }
let(:postgres_async_indexes) { table(:postgres_async_indexes) }
let(:old_length) { Gitlab::Database::MigrationHelpers::MAX_IDENTIFIER_NAME_LENGTH }
let(:long_table_name) { "#{'a' * old_length}.#{'b' * old_length}" }
describe '.up' do
it 'allows inserting longer table names' do
migration.up
expect do
postgres_async_indexes.create!(
name: 'some_index',
definition: '(id)',
table_name: long_table_name
)
end.not_to raise_error
end
end
describe '.down' do
it 'disallows inserting longer table names' do
migration.down
expect do
postgres_async_indexes.create!(
name: 'some_index',
definition: '(id)',
table_name: long_table_name
)
end.to raise_error(ActiveRecord::StatementInvalid)
end
it 'cleans up records with too long table_name' do
migration.up
# Delete
postgres_async_indexes.create!(
name: 'some_index',
definition: '(id)',
table_name: long_table_name
)
# Keep
postgres_async_indexes.create!(
name: 'other_index',
definition: '(id)',
table_name: 'short_name'
)
migration.down
async_indexes = postgres_async_indexes.all
expect(async_indexes.size).to eq(1)
expect(async_indexes.first.name).to eq('other_index')
end
end
end
|