summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-26 15:08:16 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-26 15:08:16 +0000
commite80e0dd64fbb04f60394cb1bb08e17dbcb22b8ce (patch)
tree9e538341b9b77e96737964813e10235dbecf47ff /db
parentef31adeb0fb9a02b2c6a4529ec4e38d7082a4b2b (diff)
downloadgitlab-ce-e80e0dd64fbb04f60394cb1bb08e17dbcb22b8ce.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20200323071918_add_bio_to_user_details.rb17
-rw-r--r--db/migrate/20200323074147_add_temp_index_on_users_bio.rb18
-rw-r--r--db/post_migrate/20200323080714_trigger_background_migration_for_users_bio.rb31
-rw-r--r--db/structure.sql8
4 files changed, 73 insertions, 1 deletions
diff --git a/db/migrate/20200323071918_add_bio_to_user_details.rb b/db/migrate/20200323071918_add_bio_to_user_details.rb
new file mode 100644
index 00000000000..90e4b964695
--- /dev/null
+++ b/db/migrate/20200323071918_add_bio_to_user_details.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class AddBioToUserDetails < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ add_column_with_default(:user_details, :bio, :string, default: '', allow_null: false, limit: 255, update_column_in_batches_args: { batch_column_name: :user_id })
+ end
+
+ def down
+ remove_column(:user_details, :bio)
+ end
+end
diff --git a/db/migrate/20200323074147_add_temp_index_on_users_bio.rb b/db/migrate/20200323074147_add_temp_index_on_users_bio.rb
new file mode 100644
index 00000000000..4b26bb971f5
--- /dev/null
+++ b/db/migrate/20200323074147_add_temp_index_on_users_bio.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class AddTempIndexOnUsersBio < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+ INDEX_NAME = 'tmp_idx_on_user_id_where_bio_is_filled'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :users, :id, where: "(COALESCE(bio, '') IS DISTINCT FROM '')", name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :users, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20200323080714_trigger_background_migration_for_users_bio.rb b/db/post_migrate/20200323080714_trigger_background_migration_for_users_bio.rb
new file mode 100644
index 00000000000..31ab41a6b88
--- /dev/null
+++ b/db/post_migrate/20200323080714_trigger_background_migration_for_users_bio.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+
+class TriggerBackgroundMigrationForUsersBio < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+ INTERVAL = 2.minutes.to_i
+ BATCH_SIZE = 500
+ MIGRATION = 'MigrateUsersBioToUserDetails'
+
+ disable_ddl_transaction!
+
+ class User < ActiveRecord::Base
+ self.table_name = 'users'
+
+ include ::EachBatch
+ end
+
+ def up
+ relation = User.where("(COALESCE(bio, '') IS DISTINCT FROM '')")
+
+ queue_background_migration_jobs_by_range_at_intervals(relation,
+ MIGRATION,
+ INTERVAL,
+ batch_size: BATCH_SIZE)
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/structure.sql b/db/structure.sql
index adaa0a594e6..8bd83517bb8 100644
--- a/db/structure.sql
+++ b/db/structure.sql
@@ -6152,7 +6152,8 @@ ALTER SEQUENCE public.user_custom_attributes_id_seq OWNED BY public.user_custom_
CREATE TABLE public.user_details (
user_id bigint NOT NULL,
- job_title character varying(200) DEFAULT ''::character varying NOT NULL
+ job_title character varying(200) DEFAULT ''::character varying NOT NULL,
+ bio character varying(255) DEFAULT ''::character varying NOT NULL
);
CREATE SEQUENCE public.user_details_user_id_seq
@@ -10243,6 +10244,8 @@ CREATE UNIQUE INDEX term_agreements_unique_index ON public.term_agreements USING
CREATE INDEX tmp_build_stage_position_index ON public.ci_builds USING btree (stage_id, stage_idx) WHERE (stage_idx IS NOT NULL);
+CREATE INDEX tmp_idx_on_user_id_where_bio_is_filled ON public.users USING btree (id) WHERE ((COALESCE(bio, ''::character varying))::text IS DISTINCT FROM ''::text);
+
CREATE INDEX undefined_vulnerabilities ON public.vulnerability_occurrences USING btree (id) WHERE (severity = 0);
CREATE INDEX undefined_vulnerability ON public.vulnerabilities USING btree (id) WHERE (severity = 0);
@@ -12797,7 +12800,10 @@ COPY "schema_migrations" (version) FROM STDIN;
20200319203901
20200320112455
20200320123839
+20200323071918
+20200323074147
20200323075043
+20200323080714
20200323122201
20200323134519
20200324115359