summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-15 18:09:36 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-15 18:09:36 +0000
commit09093c1278f2b3347465bf5939fda215592f0d1f (patch)
tree07976e435f6c73de8faf7a4cc891ebcfacee62d1 /db
parent0d83264a7a24b33de933437355c77a4fe47e5419 (diff)
downloadgitlab-ce-09093c1278f2b3347465bf5939fda215592f0d1f.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20200325104755_add_push_rules_id_to_project_settings.rb19
-rw-r--r--db/migrate/20200325104756_add_push_rules_foreign_key_to_project_settings.rb18
-rw-r--r--db/migrate/20200325104833_add_push_rules_id_to_application_settings.rb19
-rw-r--r--db/migrate/20200325104834_add_push_rules_foreign_key_to_application_settings.rb18
-rw-r--r--db/migrate/20200406165950_add_not_null_constraint_on_file_store_to_lfs_objects.rb24
-rw-r--r--db/migrate/20200406171857_add_not_null_constraint_on_file_store_to_ci_job_artifacts.rb24
-rw-r--r--db/migrate/20200406172135_add_not_null_constraint_on_file_store_to_uploads.rb24
-rw-r--r--db/migrate/20200408133211_add_index_on_route_path_trigram.rb18
-rw-r--r--db/migrate/20200415160722_remove_not_null_lfs_objects_constraint.rb19
-rw-r--r--db/migrate/20200415161021_remove_not_null_ci_job_artifacts_constraint.rb19
-rw-r--r--db/migrate/20200415161206_remove_not_null_uploads_constraint.rb19
-rw-r--r--db/post_migrate/20200325162730_schedule_backfill_push_rules_id_in_projects.rb36
-rw-r--r--db/post_migrate/20200406193427_add_index_to_issues_health_status.rb23
-rw-r--r--db/structure.sql44
14 files changed, 238 insertions, 86 deletions
diff --git a/db/migrate/20200325104755_add_push_rules_id_to_project_settings.rb b/db/migrate/20200325104755_add_push_rules_id_to_project_settings.rb
new file mode 100644
index 00000000000..93de736436b
--- /dev/null
+++ b/db/migrate/20200325104755_add_push_rules_id_to_project_settings.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class AddPushRulesIdToProjectSettings < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ def up
+ with_lock_retries do
+ add_column :project_settings, :push_rule_id, :bigint
+ end
+ end
+
+ def down
+ with_lock_retries do
+ remove_column :project_settings, :push_rule_id
+ end
+ end
+end
diff --git a/db/migrate/20200325104756_add_push_rules_foreign_key_to_project_settings.rb b/db/migrate/20200325104756_add_push_rules_foreign_key_to_project_settings.rb
new file mode 100644
index 00000000000..41ad8d73b4c
--- /dev/null
+++ b/db/migrate/20200325104756_add_push_rules_foreign_key_to_project_settings.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class AddPushRulesForeignKeyToProjectSettings < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :project_settings, :push_rule_id, unique: true
+ add_concurrent_foreign_key :project_settings, :push_rules, column: :push_rule_id, on_delete: :cascade
+ end
+
+ def down
+ remove_foreign_key_if_exists :project_settings, column: :push_rule_id
+ remove_concurrent_index :project_settings, :push_rule_id
+ end
+end
diff --git a/db/migrate/20200325104833_add_push_rules_id_to_application_settings.rb b/db/migrate/20200325104833_add_push_rules_id_to_application_settings.rb
new file mode 100644
index 00000000000..4650f1734c0
--- /dev/null
+++ b/db/migrate/20200325104833_add_push_rules_id_to_application_settings.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class AddPushRulesIdToApplicationSettings < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ def up
+ with_lock_retries do
+ add_column :application_settings, :push_rule_id, :bigint
+ end
+ end
+
+ def down
+ with_lock_retries do
+ remove_column :application_settings, :push_rule_id
+ end
+ end
+end
diff --git a/db/migrate/20200325104834_add_push_rules_foreign_key_to_application_settings.rb b/db/migrate/20200325104834_add_push_rules_foreign_key_to_application_settings.rb
new file mode 100644
index 00000000000..5263250833d
--- /dev/null
+++ b/db/migrate/20200325104834_add_push_rules_foreign_key_to_application_settings.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class AddPushRulesForeignKeyToApplicationSettings < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :application_settings, :push_rule_id, unique: true
+ add_concurrent_foreign_key :application_settings, :push_rules, column: :push_rule_id, on_delete: :nullify
+ end
+
+ def down
+ remove_concurrent_index :application_settings, :push_rule_id
+ remove_foreign_key_if_exists :application_settings, column: :push_rule_id
+ end
+end
diff --git a/db/migrate/20200406165950_add_not_null_constraint_on_file_store_to_lfs_objects.rb b/db/migrate/20200406165950_add_not_null_constraint_on_file_store_to_lfs_objects.rb
deleted file mode 100644
index 78b5832fea4..00000000000
--- a/db/migrate/20200406165950_add_not_null_constraint_on_file_store_to_lfs_objects.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-# frozen_string_literal: true
-
-class AddNotNullConstraintOnFileStoreToLfsObjects < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- CONSTRAINT_NAME = 'lfs_objects_file_store_not_null'
- DOWNTIME = false
-
- def up
- with_lock_retries do
- execute <<~SQL
- ALTER TABLE lfs_objects ADD CONSTRAINT #{CONSTRAINT_NAME} CHECK (file_store IS NOT NULL) NOT VALID;
- SQL
- end
- end
-
- def down
- with_lock_retries do
- execute <<~SQL
- ALTER TABLE lfs_objects DROP CONSTRAINT IF EXISTS #{CONSTRAINT_NAME};
- SQL
- end
- end
-end
diff --git a/db/migrate/20200406171857_add_not_null_constraint_on_file_store_to_ci_job_artifacts.rb b/db/migrate/20200406171857_add_not_null_constraint_on_file_store_to_ci_job_artifacts.rb
deleted file mode 100644
index 1d44e5c17b3..00000000000
--- a/db/migrate/20200406171857_add_not_null_constraint_on_file_store_to_ci_job_artifacts.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-# frozen_string_literal: true
-
-class AddNotNullConstraintOnFileStoreToCiJobArtifacts < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- CONSTRAINT_NAME = 'ci_job_artifacts_file_store_not_null'
- DOWNTIME = false
-
- def up
- with_lock_retries do
- execute <<~SQL
- ALTER TABLE ci_job_artifacts ADD CONSTRAINT #{CONSTRAINT_NAME} CHECK (file_store IS NOT NULL) NOT VALID;
- SQL
- end
- end
-
- def down
- with_lock_retries do
- execute <<~SQL
- ALTER TABLE ci_job_artifacts DROP CONSTRAINT IF EXISTS #{CONSTRAINT_NAME};
- SQL
- end
- end
-end
diff --git a/db/migrate/20200406172135_add_not_null_constraint_on_file_store_to_uploads.rb b/db/migrate/20200406172135_add_not_null_constraint_on_file_store_to_uploads.rb
deleted file mode 100644
index aa498ba9c89..00000000000
--- a/db/migrate/20200406172135_add_not_null_constraint_on_file_store_to_uploads.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-# frozen_string_literal: true
-
-class AddNotNullConstraintOnFileStoreToUploads < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- CONSTRAINT_NAME = 'uploads_store_not_null'
- DOWNTIME = false
-
- def up
- with_lock_retries do
- execute <<~SQL
- ALTER TABLE uploads ADD CONSTRAINT #{CONSTRAINT_NAME} CHECK (store IS NOT NULL) NOT VALID;
- SQL
- end
- end
-
- def down
- with_lock_retries do
- execute <<~SQL
- ALTER TABLE uploads DROP CONSTRAINT IF EXISTS #{CONSTRAINT_NAME};
- SQL
- end
- end
-end
diff --git a/db/migrate/20200408133211_add_index_on_route_path_trigram.rb b/db/migrate/20200408133211_add_index_on_route_path_trigram.rb
new file mode 100644
index 00000000000..3329252bbd3
--- /dev/null
+++ b/db/migrate/20200408133211_add_index_on_route_path_trigram.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class AddIndexOnRoutePathTrigram < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+ INDEX_NAME = 'index_routes_on_path_trigram'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :routes, :path, name: INDEX_NAME, using: :gin, opclass: { path: :gin_trgm_ops }
+ end
+
+ def down
+ remove_concurrent_index_by_name(:routes, INDEX_NAME)
+ end
+end
diff --git a/db/migrate/20200415160722_remove_not_null_lfs_objects_constraint.rb b/db/migrate/20200415160722_remove_not_null_lfs_objects_constraint.rb
new file mode 100644
index 00000000000..58cfa8e8969
--- /dev/null
+++ b/db/migrate/20200415160722_remove_not_null_lfs_objects_constraint.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class RemoveNotNullLfsObjectsConstraint < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ def up
+ with_lock_retries do
+ execute <<~SQL
+ ALTER TABLE lfs_objects DROP CONSTRAINT IF EXISTS lfs_objects_file_store_not_null;
+ SQL
+ end
+ end
+
+ def down
+ # No-op
+ end
+end
diff --git a/db/migrate/20200415161021_remove_not_null_ci_job_artifacts_constraint.rb b/db/migrate/20200415161021_remove_not_null_ci_job_artifacts_constraint.rb
new file mode 100644
index 00000000000..65430c180ce
--- /dev/null
+++ b/db/migrate/20200415161021_remove_not_null_ci_job_artifacts_constraint.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class RemoveNotNullCiJobArtifactsConstraint < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ def up
+ with_lock_retries do
+ execute <<~SQL
+ ALTER TABLE ci_job_artifacts DROP CONSTRAINT IF EXISTS ci_job_artifacts_file_store_not_null;
+ SQL
+ end
+ end
+
+ def down
+ # No-op
+ end
+end
diff --git a/db/migrate/20200415161206_remove_not_null_uploads_constraint.rb b/db/migrate/20200415161206_remove_not_null_uploads_constraint.rb
new file mode 100644
index 00000000000..23f202bac7e
--- /dev/null
+++ b/db/migrate/20200415161206_remove_not_null_uploads_constraint.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class RemoveNotNullUploadsConstraint < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ def up
+ with_lock_retries do
+ execute <<~SQL
+ ALTER TABLE uploads DROP CONSTRAINT IF EXISTS uploads_store_not_null;
+ SQL
+ end
+ end
+
+ def down
+ # No-op
+ end
+end
diff --git a/db/post_migrate/20200325162730_schedule_backfill_push_rules_id_in_projects.rb b/db/post_migrate/20200325162730_schedule_backfill_push_rules_id_in_projects.rb
new file mode 100644
index 00000000000..b25b3365e12
--- /dev/null
+++ b/db/post_migrate/20200325162730_schedule_backfill_push_rules_id_in_projects.rb
@@ -0,0 +1,36 @@
+# frozen_string_literal: true
+
+class ScheduleBackfillPushRulesIdInProjects < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ MIGRATION = 'BackfillPushRulesIdInProjects'.freeze
+ BATCH_SIZE = 1_000
+
+ class PushRules < ActiveRecord::Base
+ include EachBatch
+
+ self.table_name = 'push_rules'
+ end
+
+ def up
+ # Update one record that is connected to the instance
+ value_to_be_updated_to = ScheduleBackfillPushRulesIdInProjects::PushRules.find_by(is_sample: true)&.id
+
+ execute "UPDATE application_settings SET push_rule_id = #{value_to_be_updated_to}" if value_to_be_updated_to
+
+ ApplicationSetting.expire
+
+ queue_background_migration_jobs_by_range_at_intervals(ScheduleBackfillPushRulesIdInProjects::PushRules,
+ MIGRATION,
+ 5.minutes,
+ batch_size: BATCH_SIZE)
+ end
+
+ def down
+ execute "UPDATE application_settings SET push_rule_id = NULL"
+
+ ApplicationSetting.expire
+ end
+end
diff --git a/db/post_migrate/20200406193427_add_index_to_issues_health_status.rb b/db/post_migrate/20200406193427_add_index_to_issues_health_status.rb
new file mode 100644
index 00000000000..83baf5b6d75
--- /dev/null
+++ b/db/post_migrate/20200406193427_add_index_to_issues_health_status.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+class AddIndexToIssuesHealthStatus < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+ INDEX_NAME = 'idx_issues_on_health_status_not_null'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index(
+ :issues,
+ :health_status,
+ where: 'health_status IS NOT NULL',
+ name: INDEX_NAME
+ )
+ end
+
+ def down
+ remove_concurrent_index_by_name(:issues, INDEX_NAME)
+ end
+end
diff --git a/db/structure.sql b/db/structure.sql
index 28b0010eb30..56efa356123 100644
--- a/db/structure.sql
+++ b/db/structure.sql
@@ -399,7 +399,8 @@ CREATE TABLE public.application_settings (
namespace_storage_size_limit bigint DEFAULT 0 NOT NULL,
seat_link_enabled boolean DEFAULT true NOT NULL,
container_expiration_policies_enable_historic_entries boolean DEFAULT false NOT NULL,
- issues_create_limit integer DEFAULT 300 NOT NULL
+ issues_create_limit integer DEFAULT 300 NOT NULL,
+ push_rule_id bigint
);
CREATE SEQUENCE public.application_settings_id_seq
@@ -5025,7 +5026,8 @@ ALTER SEQUENCE public.project_repository_states_id_seq OWNED BY public.project_r
CREATE TABLE public.project_settings (
project_id integer NOT NULL,
created_at timestamp with time zone NOT NULL,
- updated_at timestamp with time zone NOT NULL
+ updated_at timestamp with time zone NOT NULL,
+ push_rule_id bigint
);
CREATE TABLE public.project_statistics (
@@ -7697,9 +7699,6 @@ ALTER TABLE ONLY public.ci_daily_report_results
ALTER TABLE ONLY public.ci_group_variables
ADD CONSTRAINT ci_group_variables_pkey PRIMARY KEY (id);
-ALTER TABLE public.ci_job_artifacts
- ADD CONSTRAINT ci_job_artifacts_file_store_not_null CHECK ((file_store IS NOT NULL)) NOT VALID;
-
ALTER TABLE ONLY public.ci_job_artifacts
ADD CONSTRAINT ci_job_artifacts_pkey PRIMARY KEY (id);
@@ -8057,9 +8056,6 @@ ALTER TABLE ONLY public.ldap_group_links
ALTER TABLE ONLY public.lfs_file_locks
ADD CONSTRAINT lfs_file_locks_pkey PRIMARY KEY (id);
-ALTER TABLE public.lfs_objects
- ADD CONSTRAINT lfs_objects_file_store_not_null CHECK ((file_store IS NOT NULL)) NOT VALID;
-
ALTER TABLE ONLY public.lfs_objects
ADD CONSTRAINT lfs_objects_pkey PRIMARY KEY (id);
@@ -8453,9 +8449,6 @@ ALTER TABLE ONLY public.u2f_registrations
ALTER TABLE ONLY public.uploads
ADD CONSTRAINT uploads_pkey PRIMARY KEY (id);
-ALTER TABLE public.uploads
- ADD CONSTRAINT uploads_store_not_null CHECK ((store IS NOT NULL)) NOT VALID;
-
ALTER TABLE ONLY public.user_agent_details
ADD CONSTRAINT user_agent_details_pkey PRIMARY KEY (id);
@@ -8573,6 +8566,8 @@ CREATE UNIQUE INDEX design_management_designs_versions_uniqueness ON public.desi
CREATE INDEX design_user_mentions_on_design_id_and_note_id_index ON public.design_user_mentions USING btree (design_id, note_id);
+CREATE INDEX dev_index_route_on_path_trigram ON public.routes USING gin (path public.gin_trgm_ops);
+
CREATE UNIQUE INDEX epic_user_mentions_on_epic_id_and_note_id_index ON public.epic_user_mentions USING btree (epic_id, note_id);
CREATE UNIQUE INDEX epic_user_mentions_on_epic_id_index ON public.epic_user_mentions USING btree (epic_id) WHERE (note_id IS NULL);
@@ -8585,6 +8580,8 @@ CREATE UNIQUE INDEX idx_environment_merge_requests_unique_index ON public.deploy
CREATE INDEX idx_geo_con_rep_updated_events_on_container_repository_id ON public.geo_container_repository_updated_events USING btree (container_repository_id);
+CREATE INDEX idx_issues_on_health_status_not_null ON public.issues USING btree (health_status) WHERE (health_status IS NOT NULL);
+
CREATE INDEX idx_issues_on_project_id_and_created_at_and_id_and_state_id ON public.issues USING btree (project_id, created_at, id, state_id);
CREATE INDEX idx_issues_on_project_id_and_due_date_and_id_and_state_id ON public.issues USING btree (project_id, due_date, id, state_id) WHERE (due_date IS NOT NULL);
@@ -8677,6 +8674,8 @@ CREATE INDEX index_application_settings_on_file_template_project_id ON public.ap
CREATE INDEX index_application_settings_on_instance_administrators_group_id ON public.application_settings USING btree (instance_administrators_group_id);
+CREATE UNIQUE INDEX index_application_settings_on_push_rule_id ON public.application_settings USING btree (push_rule_id);
+
CREATE INDEX index_application_settings_on_usage_stats_set_by_user_id ON public.application_settings USING btree (usage_stats_set_by_user_id);
CREATE INDEX index_applicationsettings_on_instance_administration_project_id ON public.application_settings USING btree (instance_administration_project_id);
@@ -9891,6 +9890,8 @@ CREATE INDEX index_project_repositories_on_shard_id ON public.project_repositori
CREATE UNIQUE INDEX index_project_repository_states_on_project_id ON public.project_repository_states USING btree (project_id);
+CREATE UNIQUE INDEX index_project_settings_on_push_rule_id ON public.project_settings USING btree (push_rule_id);
+
CREATE INDEX index_project_statistics_on_namespace_id ON public.project_statistics USING btree (namespace_id);
CREATE UNIQUE INDEX index_project_statistics_on_project_id ON public.project_statistics USING btree (project_id);
@@ -10117,6 +10118,8 @@ CREATE UNIQUE INDEX index_routes_on_path ON public.routes USING btree (path);
CREATE INDEX index_routes_on_path_text_pattern_ops ON public.routes USING btree (path varchar_pattern_ops);
+CREATE INDEX index_routes_on_path_trigram ON public.routes USING gin (path public.gin_trgm_ops);
+
CREATE UNIQUE INDEX index_routes_on_source_type_and_source_id ON public.routes USING btree (source_type, source_id);
CREATE INDEX index_saml_providers_on_group_id ON public.saml_providers USING btree (group_id);
@@ -10636,6 +10639,9 @@ ALTER TABLE ONLY public.epics
ALTER TABLE ONLY public.ci_pipelines
ADD CONSTRAINT fk_3d34ab2e06 FOREIGN KEY (pipeline_schedule_id) REFERENCES public.ci_pipeline_schedules(id) ON DELETE SET NULL;
+ALTER TABLE ONLY public.project_settings
+ ADD CONSTRAINT fk_413a953e20 FOREIGN KEY (push_rule_id) REFERENCES public.push_rules(id) ON DELETE CASCADE;
+
ALTER TABLE ONLY public.ci_pipeline_schedule_variables
ADD CONSTRAINT fk_41c35fda51 FOREIGN KEY (pipeline_schedule_id) REFERENCES public.ci_pipeline_schedules(id) ON DELETE CASCADE;
@@ -10687,6 +10693,9 @@ ALTER TABLE ONLY public.merge_requests
ALTER TABLE ONLY public.ci_builds
ADD CONSTRAINT fk_6661f4f0e8 FOREIGN KEY (resource_group_id) REFERENCES public.ci_resource_groups(id) ON DELETE SET NULL;
+ALTER TABLE ONLY public.application_settings
+ ADD CONSTRAINT fk_693b8795e4 FOREIGN KEY (push_rule_id) REFERENCES public.push_rules(id) ON DELETE SET NULL;
+
ALTER TABLE ONLY public.merge_requests
ADD CONSTRAINT fk_6a5165a692 FOREIGN KEY (milestone_id) REFERENCES public.milestones(id) ON DELETE SET NULL;
@@ -13113,9 +13122,14 @@ COPY "schema_migrations" (version) FROM STDIN;
20200323134519
20200324093258
20200324115359
+20200325104755
+20200325104756
+20200325104833
+20200325104834
20200325111432
20200325152327
20200325160952
+20200325162730
20200325183636
20200326114443
20200326122700
@@ -13143,15 +13157,17 @@ COPY "schema_migrations" (version) FROM STDIN;
20200406102111
20200406102120
20200406135648
-20200406165950
-20200406171857
-20200406172135
20200406192059
+20200406193427
20200407094005
20200407094923
20200408110856
+20200408133211
20200408153842
20200408175424
20200409211607
+20200415160722
+20200415161021
+20200415161206
\.