Commit 40514746 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Introduce build pending states table and model

This commits adds a new database table with model and corresponding
migration. We are going to store a final build state upon a final build
update sent from a Runner.
parent 06a3f976
# frozen_string_literal: true
class Ci::BuildPendingState < ApplicationRecord
extend Gitlab::Ci::Model
belongs_to :build, class_name: 'Ci::Build', foreign_key: :build_id
validates :build, presence: true
end
---
title: Introduce build states table / model / migration
merge_request: 41585
author:
type: added
# frozen_string_literal: true
class CreateCiBuildPendingStates < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def up
with_lock_retries do
create_table :ci_build_pending_states do |t|
t.timestamps_with_timezone
t.references :build, index: { unique: true }, null: false, foreign_key: { to_table: :ci_builds, on_delete: :cascade }, type: :bigint
t.integer :state
t.integer :failure_reason
t.binary :trace_checksum
end
end
end
def down
with_lock_retries do
drop_table :ci_build_pending_states
end
end
end
08c9c6e5cd19aac17de7fc639eaca5ddba3e8280452821b8a72f05dcde790feb
\ No newline at end of file
......@@ -9779,6 +9779,25 @@ CREATE SEQUENCE public.ci_build_needs_id_seq
ALTER SEQUENCE public.ci_build_needs_id_seq OWNED BY public.ci_build_needs.id;
CREATE TABLE public.ci_build_pending_states (
id bigint NOT NULL,
created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL,
build_id bigint NOT NULL,
state integer,
failure_reason integer,
trace_checksum bytea
);
CREATE SEQUENCE public.ci_build_pending_states_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE public.ci_build_pending_states_id_seq OWNED BY public.ci_build_pending_states.id;
CREATE TABLE public.ci_build_report_results (
build_id bigint NOT NULL,
project_id bigint NOT NULL,
......@@ -16872,6 +16891,8 @@ ALTER TABLE ONLY public.chat_teams ALTER COLUMN id SET DEFAULT nextval('public.c
ALTER TABLE ONLY public.ci_build_needs ALTER COLUMN id SET DEFAULT nextval('public.ci_build_needs_id_seq'::regclass);
ALTER TABLE ONLY public.ci_build_pending_states ALTER COLUMN id SET DEFAULT nextval('public.ci_build_pending_states_id_seq'::regclass);
ALTER TABLE ONLY public.ci_build_report_results ALTER COLUMN build_id SET DEFAULT nextval('public.ci_build_report_results_build_id_seq'::regclass);
ALTER TABLE ONLY public.ci_build_trace_chunks ALTER COLUMN id SET DEFAULT nextval('public.ci_build_trace_chunks_id_seq'::regclass);
......@@ -17823,6 +17844,9 @@ ALTER TABLE public.merge_request_diffs
ALTER TABLE ONLY public.ci_build_needs
ADD CONSTRAINT ci_build_needs_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.ci_build_pending_states
ADD CONSTRAINT ci_build_pending_states_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.ci_build_report_results
ADD CONSTRAINT ci_build_report_results_pkey PRIMARY KEY (build_id);
......@@ -19265,6 +19289,8 @@ CREATE UNIQUE INDEX index_chat_teams_on_namespace_id ON public.chat_teams USING
CREATE UNIQUE INDEX index_ci_build_needs_on_build_id_and_name ON public.ci_build_needs USING btree (build_id, name);
CREATE UNIQUE INDEX index_ci_build_pending_states_on_build_id ON public.ci_build_pending_states USING btree (build_id);
CREATE INDEX index_ci_build_report_results_on_project_id ON public.ci_build_report_results USING btree (project_id);
CREATE UNIQUE INDEX index_ci_build_trace_chunks_on_build_id_and_chunk_index ON public.ci_build_trace_chunks USING btree (build_id, chunk_index);
......@@ -22149,6 +22175,9 @@ ALTER TABLE ONLY public.project_deploy_tokens
ALTER TABLE ONLY public.packages_conan_file_metadata
ADD CONSTRAINT fk_rails_0afabd9328 FOREIGN KEY (package_file_id) REFERENCES public.packages_package_files(id) ON DELETE CASCADE;
ALTER TABLE ONLY public.ci_build_pending_states
ADD CONSTRAINT fk_rails_0bbbfeaf9d FOREIGN KEY (build_id) REFERENCES public.ci_builds(id) ON DELETE CASCADE;
ALTER TABLE ONLY public.operations_user_lists
ADD CONSTRAINT fk_rails_0c716e079b FOREIGN KEY (project_id) REFERENCES public.projects(id) ON DELETE CASCADE;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment