Skip to content
代码片段 群组 项目
提交 79309fcc 编辑于 作者: Mayra Cabrera's avatar Mayra Cabrera
浏览文件

Merge branch 'pedropombeiro/386491/add-registration-columns-to-ci_runners-table' into 'master'

No related branches found
No related tags found
无相关合并请求
...@@ -27,6 +27,11 @@ class Runner < Ci::ApplicationRecord ...@@ -27,6 +27,11 @@ class Runner < Ci::ApplicationRecord
project_type: 3 project_type: 3
} }
enum registration_type: {
registration_token: 0,
authenticated_user: 1
}
enum executor_type: { enum executor_type: {
unknown: 0, unknown: 0,
custom: 1, custom: 1,
...@@ -77,6 +82,8 @@ class Runner < Ci::ApplicationRecord ...@@ -77,6 +82,8 @@ class Runner < Ci::ApplicationRecord
has_one :last_build, -> { order('id DESC') }, class_name: 'Ci::Build' has_one :last_build, -> { order('id DESC') }, class_name: 'Ci::Build'
has_one :runner_version, primary_key: :version, foreign_key: :version, class_name: 'Ci::RunnerVersion' has_one :runner_version, primary_key: :version, foreign_key: :version, class_name: 'Ci::RunnerVersion'
belongs_to :creator, class_name: 'User', optional: true
before_save :ensure_token before_save :ensure_token
scope :active, -> (value = true) { where(active: value) } scope :active, -> (value = true) { where(active: value) }
......
...@@ -114,6 +114,10 @@ ci_runner_projects: ...@@ -114,6 +114,10 @@ ci_runner_projects:
- table: projects - table: projects
column: project_id column: project_id
on_delete: async_delete on_delete: async_delete
ci_runners:
- table: users
column: creator_id
on_delete: async_nullify
ci_running_builds: ci_running_builds:
- table: projects - table: projects
column: project_id column: project_id
......
# frozen_string_literal: true
class AddRegistrationColumnsToCiRunners < Gitlab::Database::Migration[2.1]
enable_lock_retries!
def change
add_column :ci_runners, :registration_type, :integer, limit: 1, default: 0, null: false
add_column :ci_runners, :creator_id, :bigint, null: true
end
end
# frozen_string_literal: true
class IndexCiRunnersOnCreatorId < Gitlab::Database::Migration[2.1]
disable_ddl_transaction!
INDEX_NAME = 'index_ci_runners_on_creator_id_where_creator_id_not_null'
def up
add_concurrent_index :ci_runners, :creator_id, where: 'creator_id IS NOT NULL', name: INDEX_NAME
end
def down
remove_concurrent_index_by_name :ci_runners, INDEX_NAME
end
end
29ebddfcf7508f259eb4de595e194995b255a1a80d79aaa6d261323d8d273021
\ No newline at end of file
395dd3ad54b7854a12d9bf2faf575ee4d7842a75f0f16db40d26523e4e2ea21f
\ No newline at end of file
...@@ -13455,6 +13455,8 @@ CREATE TABLE ci_runners ( ...@@ -13455,6 +13455,8 @@ CREATE TABLE ci_runners (
maintainer_note text, maintainer_note text,
token_expires_at timestamp with time zone, token_expires_at timestamp with time zone,
allowed_plans text[] DEFAULT '{}'::text[] NOT NULL, allowed_plans text[] DEFAULT '{}'::text[] NOT NULL,
registration_type smallint DEFAULT 0 NOT NULL,
creator_id bigint,
CONSTRAINT check_ce275cee06 CHECK ((char_length(maintainer_note) <= 1024)) CONSTRAINT check_ce275cee06 CHECK ((char_length(maintainer_note) <= 1024))
); );
   
...@@ -28917,6 +28919,8 @@ CREATE INDEX index_ci_runners_on_created_at_and_id_where_inactive ON ci_runners ...@@ -28917,6 +28919,8 @@ CREATE INDEX index_ci_runners_on_created_at_and_id_where_inactive ON ci_runners
   
CREATE INDEX index_ci_runners_on_created_at_desc_and_id_desc ON ci_runners USING btree (created_at DESC, id DESC); CREATE INDEX index_ci_runners_on_created_at_desc_and_id_desc ON ci_runners USING btree (created_at DESC, id DESC);
   
CREATE INDEX index_ci_runners_on_creator_id_where_creator_id_not_null ON ci_runners USING btree (creator_id) WHERE (creator_id IS NOT NULL);
CREATE INDEX index_ci_runners_on_description_trigram ON ci_runners USING gin (description gin_trgm_ops); CREATE INDEX index_ci_runners_on_description_trigram ON ci_runners USING gin (description gin_trgm_ops);
   
CREATE INDEX index_ci_runners_on_locked ON ci_runners USING btree (locked); CREATE INDEX index_ci_runners_on_locked ON ci_runners USING btree (locked);
...@@ -140,7 +140,7 @@ instance (for example if the runner is offline). ...@@ -140,7 +140,7 @@ instance (for example if the runner is offline).
In addition, we should add the following columns to `ci_runners`: In addition, we should add the following columns to `ci_runners`:
- a `user_id` column to keep track of who created a runner; - a `creator_id` column to keep track of who created a runner;
- a `registration_type` enum column to `ci_runners` to signal whether a runner has been created - a `registration_type` enum column to `ci_runners` to signal whether a runner has been created
using the legacy `register` method, or the new UI-based method. using the legacy `register` method, or the new UI-based method.
Possible values are `:registration_token` and `:authenticated_user`. Possible values are `:registration_token` and `:authenticated_user`.
...@@ -150,7 +150,7 @@ In addition, we should add the following columns to `ci_runners`: ...@@ -150,7 +150,7 @@ In addition, we should add the following columns to `ci_runners`:
```sql ```sql
CREATE TABLE ci_runner ( CREATE TABLE ci_runner (
... ...
user_id bigint creator_id bigint
registration_type int8 registration_type int8
) )
``` ```
......
...@@ -11,6 +11,13 @@ ...@@ -11,6 +11,13 @@
let(:factory_name) { :ci_runner } let(:factory_name) { :ci_runner }
end end
context 'loose foreign key on ci_runners.creator_id' do
it_behaves_like 'cleanup by a loose foreign key' do
let!(:parent) { create(:user) }
let!(:model) { create(:ci_runner, creator: parent) }
end
end
describe 'groups association' do describe 'groups association' do
# Due to other associations such as projects this whole spec is allowed to # Due to other associations such as projects this whole spec is allowed to
# generate cross-database queries. So we have this temporary spec to # generate cross-database queries. So we have this temporary spec to
......
...@@ -95,7 +95,7 @@ def attributes ...@@ -95,7 +95,7 @@ def attributes
expect(model.attributes).to include(attribute) # double-check the attribute does exist expect(model.attributes).to include(attribute) # double-check the attribute does exist
expect(model.serializable_hash).not_to include(attribute) expect(model.serializable_hash).not_to include(attribute)
expect(model.to_json).not_to include(attribute) expect(model.to_json).not_to match(/\b#{attribute}\b/)
expect(model.as_json).not_to include(attribute) expect(model.as_json).not_to include(attribute)
end end
end end
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册