From 874d5f8072adf51027b9ee2751fa5d3356dbad63 Mon Sep 17 00:00:00 2001 From: Kyle Edwards Date: Fri, 8 Oct 2021 13:26:59 -0400 Subject: [PATCH] CI Runners: Add token expiration field This field stores the runner's token expiration time. Changelog: added Issue: https://gitlab.com/gitlab-org/gitlab/-/issues/30942 --- ...11154950_add_token_expires_at_to_ci_runners.rb | 7 +++++++ ...51_add_index_to_ci_runners_token_expires_at.rb | 15 +++++++++++++++ db/schema_migrations/20220111154950 | 1 + db/schema_migrations/20220111154951 | 1 + db/structure.sql | 5 +++++ 5 files changed, 29 insertions(+) create mode 100644 db/migrate/20220111154950_add_token_expires_at_to_ci_runners.rb create mode 100644 db/migrate/20220111154951_add_index_to_ci_runners_token_expires_at.rb create mode 100644 db/schema_migrations/20220111154950 create mode 100644 db/schema_migrations/20220111154951 diff --git a/db/migrate/20220111154950_add_token_expires_at_to_ci_runners.rb b/db/migrate/20220111154950_add_token_expires_at_to_ci_runners.rb new file mode 100644 index 00000000000000..b4d7c63d24b04f --- /dev/null +++ b/db/migrate/20220111154950_add_token_expires_at_to_ci_runners.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddTokenExpiresAtToCiRunners < Gitlab::Database::Migration[1.0] + def change + add_column :ci_runners, :token_expires_at, :datetime_with_timezone + end +end diff --git a/db/migrate/20220111154951_add_index_to_ci_runners_token_expires_at.rb b/db/migrate/20220111154951_add_index_to_ci_runners_token_expires_at.rb new file mode 100644 index 00000000000000..53623198f5116d --- /dev/null +++ b/db/migrate/20220111154951_add_index_to_ci_runners_token_expires_at.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class AddIndexToCiRunnersTokenExpiresAt < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + def up + add_concurrent_index :ci_runners, [:token_expires_at, :id], order: { token_expires_at: :asc, id: :desc }, name: 'index_ci_runners_on_token_expires_at_and_id_desc' + add_concurrent_index :ci_runners, [:token_expires_at, :id], order: { token_expires_at: :desc, id: :desc }, name: 'index_ci_runners_on_token_expires_at_desc_and_id_desc' + end + + def down + remove_concurrent_index_by_name :ci_runners, 'index_ci_runners_on_token_expires_at_desc_and_id_desc' + remove_concurrent_index_by_name :ci_runners, 'index_ci_runners_on_token_expires_at_and_id_desc' + end +end diff --git a/db/schema_migrations/20220111154950 b/db/schema_migrations/20220111154950 new file mode 100644 index 00000000000000..6070beb76e9af0 --- /dev/null +++ b/db/schema_migrations/20220111154950 @@ -0,0 +1 @@ +4719c533acaac3234ac0e131c70be49d0f98642e29e7d2e31519cc6c372056bc \ No newline at end of file diff --git a/db/schema_migrations/20220111154951 b/db/schema_migrations/20220111154951 new file mode 100644 index 00000000000000..9d18e4c4d44cd5 --- /dev/null +++ b/db/schema_migrations/20220111154951 @@ -0,0 +1 @@ +48d6eaa68912f702be2bd38609bea4fa807eab7131f7c5e2261416820df9836a \ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index 04a978db1a9989..1facf765e50cba 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -12184,6 +12184,7 @@ CREATE TABLE ci_runners ( config jsonb DEFAULT '{}'::jsonb NOT NULL, executor_type smallint, maintainer_note text, + token_expires_at timestamp with time zone, CONSTRAINT check_56f5ea8804 CHECK ((char_length(maintainer_note) <= 255)) ); @@ -25711,6 +25712,10 @@ CREATE INDEX index_ci_runners_on_token ON ci_runners USING btree (token); CREATE INDEX index_ci_runners_on_token_encrypted ON ci_runners USING btree (token_encrypted); +CREATE INDEX index_ci_runners_on_token_expires_at_and_id_desc ON ci_runners USING btree (token_expires_at, id DESC); + +CREATE INDEX index_ci_runners_on_token_expires_at_desc_and_id_desc ON ci_runners USING btree (token_expires_at DESC, id DESC); + CREATE UNIQUE INDEX index_ci_running_builds_on_build_id ON ci_running_builds USING btree (build_id); CREATE INDEX index_ci_running_builds_on_project_id ON ci_running_builds USING btree (project_id); -- GitLab