summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20230127093353_initialize_conversion_of_merge_request_metrics_to_bigint.rb16
-rw-r--r--db/post_migrate/20230127101834_backfill_merge_request_metrics_for_bigint_conversion.rb16
-rw-r--r--db/post_migrate/20230130102855_add_fk_index_to_ci_build_report_results_on_partition_id_and_build_id.rb17
-rw-r--r--db/post_migrate/20230130102856_add_fk_to_ci_build_report_results_on_partition_id_and_build_id.rb37
-rw-r--r--db/post_migrate/20230201152525_schedule_fk_index_to_ci_build_needs_on_partition_id_and_build_id.rb17
-rw-r--r--db/schema_migrations/202301270933531
-rw-r--r--db/schema_migrations/202301271018341
-rw-r--r--db/schema_migrations/202301301028551
-rw-r--r--db/schema_migrations/202301301028561
-rw-r--r--db/schema_migrations/202302011525251
-rw-r--r--db/structure.sql17
11 files changed, 125 insertions, 0 deletions
diff --git a/db/migrate/20230127093353_initialize_conversion_of_merge_request_metrics_to_bigint.rb b/db/migrate/20230127093353_initialize_conversion_of_merge_request_metrics_to_bigint.rb
new file mode 100644
index 00000000000..dfca67a2e2f
--- /dev/null
+++ b/db/migrate/20230127093353_initialize_conversion_of_merge_request_metrics_to_bigint.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+class InitializeConversionOfMergeRequestMetricsToBigint < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ TABLE = :merge_request_metrics
+ COLUMNS = %i[id]
+
+ def up
+ initialize_conversion_of_integer_to_bigint(TABLE, COLUMNS)
+ end
+
+ def down
+ revert_initialize_conversion_of_integer_to_bigint(TABLE, COLUMNS)
+ end
+end
diff --git a/db/post_migrate/20230127101834_backfill_merge_request_metrics_for_bigint_conversion.rb b/db/post_migrate/20230127101834_backfill_merge_request_metrics_for_bigint_conversion.rb
new file mode 100644
index 00000000000..02ef1c230da
--- /dev/null
+++ b/db/post_migrate/20230127101834_backfill_merge_request_metrics_for_bigint_conversion.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+class BackfillMergeRequestMetricsForBigintConversion < Gitlab::Database::Migration[2.1]
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ TABLE = :merge_request_metrics
+ COLUMNS = %i[id]
+
+ def up
+ backfill_conversion_of_integer_to_bigint(TABLE, COLUMNS, sub_batch_size: 200)
+ end
+
+ def down
+ revert_backfill_conversion_of_integer_to_bigint(TABLE, COLUMNS)
+ end
+end
diff --git a/db/post_migrate/20230130102855_add_fk_index_to_ci_build_report_results_on_partition_id_and_build_id.rb b/db/post_migrate/20230130102855_add_fk_index_to_ci_build_report_results_on_partition_id_and_build_id.rb
new file mode 100644
index 00000000000..4fe71ba46d9
--- /dev/null
+++ b/db/post_migrate/20230130102855_add_fk_index_to_ci_build_report_results_on_partition_id_and_build_id.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class AddFkIndexToCiBuildReportResultsOnPartitionIdAndBuildId < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ INDEX_NAME = :index_ci_build_report_results_on_partition_id_build_id
+ TABLE_NAME = :ci_build_report_results
+ COLUMNS = [:partition_id, :build_id]
+
+ def up
+ add_concurrent_index(TABLE_NAME, COLUMNS, unique: true, name: INDEX_NAME)
+ end
+
+ def down
+ remove_concurrent_index_by_name(TABLE_NAME, INDEX_NAME)
+ end
+end
diff --git a/db/post_migrate/20230130102856_add_fk_to_ci_build_report_results_on_partition_id_and_build_id.rb b/db/post_migrate/20230130102856_add_fk_to_ci_build_report_results_on_partition_id_and_build_id.rb
new file mode 100644
index 00000000000..ef301af2c9f
--- /dev/null
+++ b/db/post_migrate/20230130102856_add_fk_to_ci_build_report_results_on_partition_id_and_build_id.rb
@@ -0,0 +1,37 @@
+# frozen_string_literal: true
+
+class AddFkToCiBuildReportResultsOnPartitionIdAndBuildId < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ SOURCE_TABLE_NAME = :ci_build_report_results
+ TARGET_TABLE_NAME = :ci_builds
+ COLUMN = :build_id
+ TARGET_COLUMN = :id
+ FK_NAME = :fk_rails_16cb1ff064_p
+ PARTITION_COLUMN = :partition_id
+
+ def up
+ add_concurrent_foreign_key(
+ SOURCE_TABLE_NAME,
+ TARGET_TABLE_NAME,
+ column: [PARTITION_COLUMN, COLUMN],
+ target_column: [PARTITION_COLUMN, TARGET_COLUMN],
+ validate: false,
+ reverse_lock_order: true,
+ on_update: :cascade,
+ on_delete: :cascade,
+ name: FK_NAME
+ )
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key_if_exists(
+ SOURCE_TABLE_NAME,
+ TARGET_TABLE_NAME,
+ name: FK_NAME,
+ reverse_lock_order: true
+ )
+ end
+ end
+end
diff --git a/db/post_migrate/20230201152525_schedule_fk_index_to_ci_build_needs_on_partition_id_and_build_id.rb b/db/post_migrate/20230201152525_schedule_fk_index_to_ci_build_needs_on_partition_id_and_build_id.rb
new file mode 100644
index 00000000000..674d92295c3
--- /dev/null
+++ b/db/post_migrate/20230201152525_schedule_fk_index_to_ci_build_needs_on_partition_id_and_build_id.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class ScheduleFkIndexToCiBuildNeedsOnPartitionIdAndBuildId < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ INDEX_NAME = :index_ci_build_needs_on_partition_id_build_id
+ TABLE_NAME = :ci_build_needs
+ COLUMNS = [:partition_id, :build_id]
+
+ def up
+ prepare_async_index(TABLE_NAME, COLUMNS, name: INDEX_NAME)
+ end
+
+ def down
+ unprepare_async_index_by_name(TABLE_NAME, INDEX_NAME)
+ end
+end
diff --git a/db/schema_migrations/20230127093353 b/db/schema_migrations/20230127093353
new file mode 100644
index 00000000000..903688f1608
--- /dev/null
+++ b/db/schema_migrations/20230127093353
@@ -0,0 +1 @@
+7b6b30a2de12f145df5eb0814f584a117a421b1ae23c4dd45fea58fe0d883653 \ No newline at end of file
diff --git a/db/schema_migrations/20230127101834 b/db/schema_migrations/20230127101834
new file mode 100644
index 00000000000..4d89984347a
--- /dev/null
+++ b/db/schema_migrations/20230127101834
@@ -0,0 +1 @@
+13aba72dc08069cf5585657a6c684495886f27c634cdb63c363ddd1ab6f7c58d \ No newline at end of file
diff --git a/db/schema_migrations/20230130102855 b/db/schema_migrations/20230130102855
new file mode 100644
index 00000000000..91f9164a254
--- /dev/null
+++ b/db/schema_migrations/20230130102855
@@ -0,0 +1 @@
+1e6d539713dd9d6b6b8afd5fcb6db87e75eb96fccf91a94c00700760fb5e963f \ No newline at end of file
diff --git a/db/schema_migrations/20230130102856 b/db/schema_migrations/20230130102856
new file mode 100644
index 00000000000..f258d0e1eae
--- /dev/null
+++ b/db/schema_migrations/20230130102856
@@ -0,0 +1 @@
+4dc770e4a78c0f3e3aa5af43e017744a85b4974c1315508ac2244c7b12f4e0b3 \ No newline at end of file
diff --git a/db/schema_migrations/20230201152525 b/db/schema_migrations/20230201152525
new file mode 100644
index 00000000000..51fd8eabe91
--- /dev/null
+++ b/db/schema_migrations/20230201152525
@@ -0,0 +1 @@
+cfe3f77bf0615889a0fd1d55ef4f07f2bb9a1dbe1a6bb0fb5a36c017f9a5ca46 \ No newline at end of file
diff --git a/db/structure.sql b/db/structure.sql
index 6321bfa3ab0..ddc4945a58f 100644
--- a/db/structure.sql
+++ b/db/structure.sql
@@ -234,6 +234,15 @@ BEGIN
END;
$$;
+CREATE FUNCTION trigger_c7107f30d69d() RETURNS trigger
+ LANGUAGE plpgsql
+ AS $$
+BEGIN
+ NEW."id_convert_to_bigint" := NEW."id";
+ RETURN NEW;
+END;
+$$;
+
CREATE FUNCTION unset_has_issues_on_vulnerability_reads() RETURNS trigger
LANGUAGE plpgsql
AS $$
@@ -17791,6 +17800,7 @@ CREATE TABLE merge_request_metrics (
added_lines integer,
removed_lines integer,
target_project_id integer,
+ id_convert_to_bigint bigint DEFAULT 0 NOT NULL,
CONSTRAINT check_e03d0900bf CHECK ((target_project_id IS NOT NULL))
);
@@ -28982,6 +28992,8 @@ CREATE UNIQUE INDEX index_ci_build_pending_states_on_build_id ON ci_build_pendin
CREATE INDEX index_ci_build_pending_states_on_partition_id_build_id ON ci_build_pending_states USING btree (partition_id, build_id);
+CREATE UNIQUE INDEX index_ci_build_report_results_on_partition_id_build_id ON ci_build_report_results USING btree (partition_id, build_id);
+
CREATE INDEX index_ci_build_report_results_on_project_id ON ci_build_report_results USING btree (project_id);
CREATE UNIQUE INDEX index_ci_build_trace_chunks_on_build_id_and_chunk_index ON ci_build_trace_chunks USING btree (build_id, chunk_index);
@@ -33426,6 +33438,8 @@ CREATE TRIGGER projects_loose_fk_trigger AFTER DELETE ON projects REFERENCING OL
CREATE TRIGGER trigger_1a857e8db6cd BEFORE INSERT OR UPDATE ON vulnerability_occurrences FOR EACH ROW EXECUTE FUNCTION trigger_1a857e8db6cd();
+CREATE TRIGGER trigger_c7107f30d69d BEFORE INSERT OR UPDATE ON merge_request_metrics FOR EACH ROW EXECUTE FUNCTION trigger_c7107f30d69d();
+
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();
@@ -34559,6 +34573,9 @@ ALTER TABLE ONLY users_security_dashboard_projects
ALTER TABLE ONLY ci_build_report_results
ADD CONSTRAINT fk_rails_16cb1ff064 FOREIGN KEY (build_id) REFERENCES ci_builds(id) ON DELETE CASCADE;
+ALTER TABLE ONLY ci_build_report_results
+ ADD CONSTRAINT fk_rails_16cb1ff064_p FOREIGN KEY (partition_id, build_id) REFERENCES ci_builds(partition_id, id) ON UPDATE CASCADE ON DELETE CASCADE NOT VALID;
+
ALTER TABLE ONLY project_deploy_tokens
ADD CONSTRAINT fk_rails_170e03cbaf FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;