Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-26 18:08:16 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-26 18:08:16 +0300
commite80e0dd64fbb04f60394cb1bb08e17dbcb22b8ce (patch)
tree9e538341b9b77e96737964813e10235dbecf47ff /lib/gitlab/background_migration
parentef31adeb0fb9a02b2c6a4529ec4e38d7082a4b2b (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/background_migration')
-rw-r--r--lib/gitlab/background_migration/migrate_users_bio_to_user_details.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/gitlab/background_migration/migrate_users_bio_to_user_details.rb b/lib/gitlab/background_migration/migrate_users_bio_to_user_details.rb
new file mode 100644
index 00000000000..ca64d13b118
--- /dev/null
+++ b/lib/gitlab/background_migration/migrate_users_bio_to_user_details.rb
@@ -0,0 +1,34 @@
+# frozen_string_literal: true
+# rubocop:disable Style/Documentation
+
+module Gitlab
+ module BackgroundMigration
+ class MigrateUsersBioToUserDetails
+ class User < ActiveRecord::Base
+ self.table_name = 'users'
+ end
+
+ class UserDetails < ActiveRecord::Base
+ self.table_name = 'user_details'
+ end
+
+ def perform(start_id, stop_id)
+ return if Feature.disabled?(:migrate_bio_to_user_details, default_enabled: true)
+
+ relation = User
+ .select("id AS user_id", "substring(COALESCE(bio, '') from 1 for 255) AS bio")
+ .where("(COALESCE(bio, '') IS DISTINCT FROM '')")
+ .where(id: (start_id..stop_id))
+
+ ActiveRecord::Base.connection.execute <<-EOF.strip_heredoc
+ INSERT INTO user_details
+ (user_id, bio)
+ #{relation.to_sql}
+ ON CONFLICT (user_id)
+ DO UPDATE SET
+ "bio" = EXCLUDED."bio";
+ EOF
+ end
+ end
+ end
+end