Skip to content
代码片段 群组 项目
未验证 提交 a723afb2 编辑于 作者: Jason Goodman's avatar Jason Goodman 提交者: GitLab
浏览文件

Merge branch 'migrate-seat-control-based-on-user-cap' into 'master'

Migrate Seat Control Based on User Cap

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/159466



Merged-by: default avatarJason Goodman <jgoodman@gitlab.com>
Approved-by: default avatarAdam Hegyi <ahegyi@gitlab.com>
No related branches found
No related tags found
无相关合并请求
# frozen_string_literal: true
class AddTmpIndexToNamespaceSettingsOnNewUserSignupsCap < Gitlab::Database::Migration[2.2]
disable_ddl_transaction!
milestone '17.3'
TABLE = :namespace_settings
COLUMN = :new_user_signups_cap
INDEX_NAME = 'tmp_index_namespace_settings_on_new_user_signups_cap'
def up
add_concurrent_index TABLE, COLUMN, name: INDEX_NAME, where: 'new_user_signups_cap IS NOT NULL'
end
def down
remove_concurrent_index_by_name TABLE, INDEX_NAME
end
end
# frozen_string_literal: true
class SyncNamespaceSettingsSeatControlWithUserCap < Gitlab::Database::Migration[2.2]
restrict_gitlab_migration gitlab_schema: :gitlab_main
disable_ddl_transaction!
milestone '17.3'
def up
define_batchable_model('namespace_settings').where.not(new_user_signups_cap: nil).each_batch do |relation|
relation.update_all(seat_control: 1)
end
end
def down
# no-op
end
end
# frozen_string_literal: true
class RemoveTmpIndexFromNamespaceSettingsOnNewUserSignupsCap < Gitlab::Database::Migration[2.2]
disable_ddl_transaction!
milestone '17.3'
TABLE = :namespace_settings
COLUMN = :new_user_signups_cap
INDEX_NAME = 'tmp_index_namespace_settings_on_new_user_signups_cap'
def up
remove_concurrent_index_by_name TABLE, INDEX_NAME
end
def down
add_concurrent_index TABLE, COLUMN, name: INDEX_NAME, where: 'new_user_signups_cap IS NOT NULL'
end
end
0bbf02a4cf3b620d0e4cdd180a6543d7fd160174f3bf3a9ae43f9b1000d4ce60
\ No newline at end of file
7d3bd4c25d5e3adcf41f9b2821fff4e769841066b11d3f26ba96065377ec9b34
\ No newline at end of file
be480d22843ca39035f8d6bf721d9b5922582e7aa0ba4e939b8a8a0994d059fc
\ No newline at end of file
# frozen_string_literal: true
require 'spec_helper'
require_migration!
RSpec.describe SyncNamespaceSettingsSeatControlWithUserCap, feature_category: :consumables_cost_management do
let(:namespaces) { table(:namespaces) }
let(:namespace_settings) { table(:namespace_settings) }
it 'sets the value of seat_control to 1 where new_user_signups_cap has a value' do
namespace = namespaces.create!(name: 'MyNamespace', path: 'my-namespace')
settings = namespace_settings.create!(namespace_id: namespace.id, new_user_signups_cap: 10, seat_control: 0)
migrate!
expect(settings.reload.seat_control).to eq(1)
end
it 'does not change the value of seat_control where new_user_signups_cap is null' do
namespace = namespaces.create!(name: 'MyNamespace', path: 'my-namespace')
settings = namespace_settings.create!(namespace_id: namespace.id, new_user_signups_cap: nil, seat_control: 0)
migrate!
expect(settings.reload.seat_control).to eq(0)
end
it 'sets the value of seat_control for multiple rows' do
namespace_a = namespaces.create!(name: 'MyNamespaceA', path: 'my-namespace-a')
settings_a = namespace_settings.create!(namespace_id: namespace_a.id, new_user_signups_cap: 5, seat_control: 0)
namespace_b = namespaces.create!(name: 'MyNamespaceB', path: 'my-namespace-b')
settings_b = namespace_settings.create!(namespace_id: namespace_b.id, new_user_signups_cap: nil, seat_control: 0)
namespace_c = namespaces.create!(name: 'MyNamespaceC', path: 'my-namespace-c')
settings_c = namespace_settings.create!(namespace_id: namespace_c.id, new_user_signups_cap: 20, seat_control: 0)
migrate!
expect(settings_a.reload.seat_control).to eq(1)
expect(settings_b.reload.seat_control).to eq(0)
expect(settings_c.reload.seat_control).to eq(1)
end
end
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册