diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-09 12:12:15 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-09 12:12:15 +0000 |
commit | b808458daa86105dd2101893961338912961ee92 (patch) | |
tree | 5a3b432668a2340cced92eeaa2654604ba0efef9 /db | |
parent | 1aa9cd3080e7ef34b7b021f23222d3990e4a1128 (diff) | |
download | gitlab-ce-b808458daa86105dd2101893961338912961ee92.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'db')
-rw-r--r-- | db/post_migrate/20211105135157_drop_ci_build_trace_sections.rb | 99 | ||||
-rw-r--r-- | db/schema_migrations/20211105135157 | 1 | ||||
-rw-r--r-- | db/structure.sql | 61 |
3 files changed, 100 insertions, 61 deletions
diff --git a/db/post_migrate/20211105135157_drop_ci_build_trace_sections.rb b/db/post_migrate/20211105135157_drop_ci_build_trace_sections.rb new file mode 100644 index 00000000000..1595068952d --- /dev/null +++ b/db/post_migrate/20211105135157_drop_ci_build_trace_sections.rb @@ -0,0 +1,99 @@ +# frozen_string_literal: true + +class DropCiBuildTraceSections < Gitlab::Database::Migration[1.0] + include Gitlab::Database::SchemaHelpers + + disable_ddl_transaction! + + def up + with_lock_retries do + remove_foreign_key_if_exists(:dep_ci_build_trace_sections, column: :project_id) + end + + with_lock_retries do + remove_foreign_key_if_exists(:dep_ci_build_trace_section_names, column: :project_id) + end + + if table_exists?(:dep_ci_build_trace_sections) + with_lock_retries do + drop_table :dep_ci_build_trace_sections + end + end + + if table_exists?(:dep_ci_build_trace_section_names) + with_lock_retries do + drop_table :dep_ci_build_trace_section_names + end + end + + drop_function('trigger_91dc388a5fe6') + end + + def down + execute(<<~SQL) + CREATE OR REPLACE FUNCTION trigger_91dc388a5fe6() RETURNS trigger + LANGUAGE plpgsql + AS $$ + BEGIN + NEW."build_id_convert_to_bigint" := NEW."build_id"; + RETURN NEW; + END; + $$; + SQL + + execute_in_transaction(<<~SQL, !table_exists?(:dep_ci_build_trace_section_names)) + CREATE TABLE dep_ci_build_trace_section_names ( + id integer NOT NULL, + project_id integer NOT NULL, + name character varying NOT NULL + ); + + CREATE SEQUENCE dep_ci_build_trace_section_names_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + ALTER SEQUENCE dep_ci_build_trace_section_names_id_seq OWNED BY dep_ci_build_trace_section_names.id; + + ALTER TABLE ONLY dep_ci_build_trace_section_names ALTER COLUMN id SET DEFAULT nextval('dep_ci_build_trace_section_names_id_seq'::regclass); + ALTER TABLE ONLY dep_ci_build_trace_section_names ADD CONSTRAINT dep_ci_build_trace_section_names_pkey PRIMARY KEY (id); + SQL + + execute_in_transaction(<<~SQL, !table_exists?(:dep_ci_build_trace_sections)) + CREATE TABLE dep_ci_build_trace_sections ( + project_id integer NOT NULL, + date_start timestamp without time zone NOT NULL, + date_end timestamp without time zone NOT NULL, + byte_start bigint NOT NULL, + byte_end bigint NOT NULL, + build_id integer NOT NULL, + section_name_id integer NOT NULL, + build_id_convert_to_bigint bigint DEFAULT 0 NOT NULL + ); + + ALTER TABLE ONLY dep_ci_build_trace_sections ADD CONSTRAINT ci_build_trace_sections_pkey PRIMARY KEY (build_id, section_name_id); + CREATE TRIGGER trigger_91dc388a5fe6 BEFORE INSERT OR UPDATE ON dep_ci_build_trace_sections FOR EACH ROW EXECUTE FUNCTION trigger_91dc388a5fe6(); + SQL + + add_concurrent_index :dep_ci_build_trace_section_names, [:project_id, :name], unique: true, name: 'index_dep_ci_build_trace_section_names_on_project_id_and_name' + add_concurrent_index :dep_ci_build_trace_sections, :project_id, name: 'index_dep_ci_build_trace_sections_on_project_id' + add_concurrent_index :dep_ci_build_trace_sections, :section_name_id, name: 'index_dep_ci_build_trace_sections_on_section_name_id' + + add_concurrent_foreign_key :dep_ci_build_trace_sections, :dep_ci_build_trace_section_names, column: :section_name_id, on_delete: :cascade, name: 'fk_264e112c66' + add_concurrent_foreign_key :dep_ci_build_trace_sections, :projects, column: :project_id, on_delete: :cascade, name: 'fk_ab7c104e26' + add_concurrent_foreign_key :dep_ci_build_trace_section_names, :projects, column: :project_id, on_delete: :cascade, name: 'fk_f8cd72cd26' + end + + private + + def execute_in_transaction(sql, condition) + return unless condition + + transaction do + execute(sql) + end + end +end diff --git a/db/schema_migrations/20211105135157 b/db/schema_migrations/20211105135157 new file mode 100644 index 00000000000..694509bfafd --- /dev/null +++ b/db/schema_migrations/20211105135157 @@ -0,0 +1 @@ +20f10ae28d439de1d07357ab7e977dae88feaaedb16770820350a9bf8242817f
\ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index 790b9066eac..4279fbfd448 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -86,15 +86,6 @@ RETURN NULL; END $$; -CREATE FUNCTION trigger_91dc388a5fe6() RETURNS trigger - LANGUAGE plpgsql - AS $$ -BEGIN - NEW."build_id_convert_to_bigint" := NEW."build_id"; - RETURN NEW; -END; -$$; - CREATE TABLE audit_events ( id bigint NOT NULL, author_id integer NOT NULL, @@ -13235,33 +13226,6 @@ CREATE SEQUENCE dast_sites_id_seq ALTER SEQUENCE dast_sites_id_seq OWNED BY dast_sites.id; -CREATE TABLE dep_ci_build_trace_section_names ( - id integer NOT NULL, - project_id integer NOT NULL, - name character varying NOT NULL -); - -CREATE SEQUENCE dep_ci_build_trace_section_names_id_seq - AS integer - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - -ALTER SEQUENCE dep_ci_build_trace_section_names_id_seq OWNED BY dep_ci_build_trace_section_names.id; - -CREATE TABLE dep_ci_build_trace_sections ( - project_id integer NOT NULL, - date_start timestamp without time zone NOT NULL, - date_end timestamp without time zone NOT NULL, - byte_start bigint NOT NULL, - byte_end bigint NOT NULL, - build_id integer NOT NULL, - section_name_id integer NOT NULL, - build_id_convert_to_bigint bigint DEFAULT 0 NOT NULL -); - CREATE TABLE dependency_proxy_blobs ( id integer NOT NULL, group_id integer NOT NULL, @@ -21410,8 +21374,6 @@ ALTER TABLE ONLY dast_site_validations ALTER COLUMN id SET DEFAULT nextval('dast ALTER TABLE ONLY dast_sites ALTER COLUMN id SET DEFAULT nextval('dast_sites_id_seq'::regclass); -ALTER TABLE ONLY dep_ci_build_trace_section_names ALTER COLUMN id SET DEFAULT nextval('dep_ci_build_trace_section_names_id_seq'::regclass); - ALTER TABLE ONLY dependency_proxy_blobs ALTER COLUMN id SET DEFAULT nextval('dependency_proxy_blobs_id_seq'::regclass); ALTER TABLE ONLY dependency_proxy_group_settings ALTER COLUMN id SET DEFAULT nextval('dependency_proxy_group_settings_id_seq'::regclass); @@ -22705,9 +22667,6 @@ ALTER TABLE ONLY ci_build_trace_chunks ALTER TABLE ONLY ci_build_trace_metadata ADD CONSTRAINT ci_build_trace_metadata_pkey PRIMARY KEY (build_id); -ALTER TABLE ONLY dep_ci_build_trace_sections - ADD CONSTRAINT ci_build_trace_sections_pkey PRIMARY KEY (build_id, section_name_id); - ALTER TABLE ONLY ci_builds_metadata ADD CONSTRAINT ci_builds_metadata_pkey PRIMARY KEY (id); @@ -22960,9 +22919,6 @@ ALTER TABLE ONLY dast_site_validations ALTER TABLE ONLY dast_sites ADD CONSTRAINT dast_sites_pkey PRIMARY KEY (id); -ALTER TABLE ONLY dep_ci_build_trace_section_names - ADD CONSTRAINT dep_ci_build_trace_section_names_pkey PRIMARY KEY (id); - ALTER TABLE ONLY dependency_proxy_blobs ADD CONSTRAINT dependency_proxy_blobs_pkey PRIMARY KEY (id); @@ -25675,12 +25631,6 @@ CREATE INDEX index_dast_sites_on_dast_site_validation_id ON dast_sites USING btr CREATE UNIQUE INDEX index_dast_sites_on_project_id_and_url ON dast_sites USING btree (project_id, url); -CREATE UNIQUE INDEX index_dep_ci_build_trace_section_names_on_project_id_and_name ON dep_ci_build_trace_section_names USING btree (project_id, name); - -CREATE INDEX index_dep_ci_build_trace_sections_on_project_id ON dep_ci_build_trace_sections USING btree (project_id); - -CREATE INDEX index_dep_ci_build_trace_sections_on_section_name_id ON dep_ci_build_trace_sections USING btree (section_name_id); - CREATE UNIQUE INDEX index_dep_prox_manifests_on_group_id_file_name_and_status ON dependency_proxy_manifests USING btree (group_id, file_name, status); CREATE INDEX index_dependency_proxy_blobs_on_group_id_and_file_name ON dependency_proxy_blobs USING btree (group_id, file_name); @@ -28733,8 +28683,6 @@ CREATE TRIGGER chat_names_loose_fk_trigger AFTER DELETE ON chat_names REFERENCIN CREATE TRIGGER ci_runners_loose_fk_trigger AFTER DELETE ON ci_runners REFERENCING OLD TABLE AS old_table FOR EACH STATEMENT EXECUTE FUNCTION insert_into_loose_foreign_keys_deleted_records(); -CREATE TRIGGER trigger_91dc388a5fe6 BEFORE INSERT OR UPDATE ON dep_ci_build_trace_sections FOR EACH ROW EXECUTE FUNCTION trigger_91dc388a5fe6(); - CREATE TRIGGER trigger_delete_project_namespace_on_project_delete AFTER DELETE ON projects FOR EACH ROW WHEN ((old.project_namespace_id IS NOT NULL)) EXECUTE FUNCTION delete_associated_project_namespace(); CREATE TRIGGER trigger_has_external_issue_tracker_on_delete AFTER DELETE ON integrations FOR EACH ROW WHEN ((((old.category)::text = 'issue_tracker'::text) AND (old.active = true) AND (old.project_id IS NOT NULL))) EXECUTE FUNCTION set_has_external_issue_tracker(); @@ -28888,9 +28836,6 @@ ALTER TABLE ONLY projects ALTER TABLE ONLY ci_pipelines ADD CONSTRAINT fk_262d4c2d19 FOREIGN KEY (auto_canceled_by_id) REFERENCES ci_pipelines(id) ON DELETE SET NULL; -ALTER TABLE ONLY dep_ci_build_trace_sections - ADD CONSTRAINT fk_264e112c66 FOREIGN KEY (section_name_id) REFERENCES dep_ci_build_trace_section_names(id) ON DELETE CASCADE; - ALTER TABLE ONLY geo_event_log ADD CONSTRAINT fk_27548c6db3 FOREIGN KEY (hashed_storage_migrated_event_id) REFERENCES geo_hashed_storage_migrated_events(id) ON DELETE CASCADE; @@ -29293,9 +29238,6 @@ ALTER TABLE ONLY boards ALTER TABLE ONLY member_tasks ADD CONSTRAINT fk_ab636303dd FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE; -ALTER TABLE ONLY dep_ci_build_trace_sections - ADD CONSTRAINT fk_ab7c104e26 FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE; - ALTER TABLE ONLY ci_sources_pipelines ADD CONSTRAINT fk_acd9737679 FOREIGN KEY (source_project_id) REFERENCES projects(id) ON DELETE CASCADE; @@ -29587,9 +29529,6 @@ ALTER TABLE ONLY cluster_agents ALTER TABLE ONLY protected_tag_create_access_levels ADD CONSTRAINT fk_f7dfda8c51 FOREIGN KEY (protected_tag_id) REFERENCES protected_tags(id) ON DELETE CASCADE; -ALTER TABLE ONLY dep_ci_build_trace_section_names - ADD CONSTRAINT fk_f8cd72cd26 FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE; - ALTER TABLE ONLY ci_stages ADD CONSTRAINT fk_fb57e6cc56 FOREIGN KEY (pipeline_id) REFERENCES ci_pipelines(id) ON DELETE CASCADE; |