diff options
author | Nick Thomas <nick@gitlab.com> | 2019-07-01 14:23:25 +0300 |
---|---|---|
committer | Nick Thomas <nick@gitlab.com> | 2019-07-02 11:35:03 +0300 |
commit | cfe31f992a12c95570891b8cca8747589c6c6228 (patch) | |
tree | d89296a511b093b7216a4aca3a933234c9047865 /db/post_migrate | |
parent | 6d867cad918d80216908b68dba7e785997871ac7 (diff) |
Squash old migrations
Use the `squasher` gem to squash migrations older than the start of 2018
Diffstat (limited to 'db/post_migrate')
105 files changed, 0 insertions, 3628 deletions
diff --git a/db/post_migrate/20160824121037_change_personal_access_tokens_default_back_to_empty_array.rb b/db/post_migrate/20160824121037_change_personal_access_tokens_default_back_to_empty_array.rb deleted file mode 100644 index 099814d7556..00000000000 --- a/db/post_migrate/20160824121037_change_personal_access_tokens_default_back_to_empty_array.rb +++ /dev/null @@ -1,19 +0,0 @@ -# The default needs to be `[]`, but all existing access tokens need to have `scopes` set to `['api']`. -# It's easier to achieve this by adding the column with the `['api']` default (regular migration), and -# then changing the default to `[]` (in this post-migration). -# -# Details: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/5951#note_19721973 - -class ChangePersonalAccessTokensDefaultBackToEmptyArray < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def up - change_column_default :personal_access_tokens, :scopes, [].to_yaml - end - - def down - change_column_default :personal_access_tokens, :scopes, ['api'].to_yaml - end -end diff --git a/db/post_migrate/20161011222551_remove_inactive_jira_service_properties.rb b/db/post_migrate/20161011222551_remove_inactive_jira_service_properties.rb deleted file mode 100644 index bf3aee99418..00000000000 --- a/db/post_migrate/20161011222551_remove_inactive_jira_service_properties.rb +++ /dev/null @@ -1,10 +0,0 @@ -class RemoveInactiveJiraServiceProperties < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = true - DOWNTIME_REASON = "Removes all inactive jira_service properties" - - def up - execute("UPDATE services SET properties = '{}' WHERE services.type = 'JiraService' and services.active = false") - end -end diff --git a/db/post_migrate/20161109150329_fix_project_records_with_invalid_visibility.rb b/db/post_migrate/20161109150329_fix_project_records_with_invalid_visibility.rb deleted file mode 100644 index 6d9c7e4ed72..00000000000 --- a/db/post_migrate/20161109150329_fix_project_records_with_invalid_visibility.rb +++ /dev/null @@ -1,49 +0,0 @@ -class FixProjectRecordsWithInvalidVisibility < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - BATCH_SIZE = 500 - DOWNTIME = false - - # This migration is idempotent and there's no sense in throwing away the - # partial result if it's interrupted - disable_ddl_transaction! - - def up - projects = Arel::Table.new(:projects) - namespaces = Arel::Table.new(:namespaces) - - finder_sql = - projects - .join(namespaces, Arel::Nodes::InnerJoin) - .on(projects[:namespace_id].eq(namespaces[:id])) - .where(projects[:visibility_level].gt(namespaces[:visibility_level])) - .project(projects[:id], namespaces[:visibility_level]) - .take(BATCH_SIZE) - .to_sql - - # Update matching rows in batches. Each batch can cause up to 3 UPDATE - # statements, in addition to the SELECT: one per visibility_level - loop do - to_update = connection.exec_query(finder_sql) - break if to_update.rows.count == 0 - - # row[0] is projects.id, row[1] is namespaces.visibility_level - updates = to_update.rows.each_with_object(Hash.new {|h, k| h[k] = [] }) do |row, obj| - obj[row[1]] << row[0] - end - - updates.each do |visibility_level, project_ids| - updater = Arel::UpdateManager.new - .table(projects) - .set(projects[:visibility_level] => visibility_level) - .where(projects[:id].in(project_ids)) - - ActiveRecord::Base.connection.exec_update(updater.to_sql, self.class.name, []) - end - end - end - - def down - # no-op - end -end diff --git a/db/post_migrate/20161128170531_drop_user_activities_table.rb b/db/post_migrate/20161128170531_drop_user_activities_table.rb deleted file mode 100644 index d8b1e0731f3..00000000000 --- a/db/post_migrate/20161128170531_drop_user_activities_table.rb +++ /dev/null @@ -1,33 +0,0 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. -class DropUserActivitiesTable < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - # When using the methods "add_concurrent_index" or "add_column_with_default" - # you must disable the use of transactions as these methods can not run in an - # existing transaction. When using "add_concurrent_index" make sure that this - # method is the _only_ method called in the migration, any other changes - # should go in a separate migration. This ensures that upon failure _only_ the - # index creation fails and can be retried or reverted easily. - # - # To disable transactions uncomment the following line and remove these - # comments: - # disable_ddl_transaction! - - def up - drop_table :user_activities if table_exists?(:user_activities) - end - - def down - unless table_exists?(:user_activities) - create_table "user_activities", force: :cascade do |t| - t.integer "user_id" - t.datetime "last_activity_at", null: false - end - - add_index "user_activities", ["user_id"], name: "index_user_activities_on_user_id", unique: true, using: :btree - end - end -end diff --git a/db/post_migrate/20161221140236_remove_unneeded_services.rb b/db/post_migrate/20161221140236_remove_unneeded_services.rb deleted file mode 100644 index 31f24263877..00000000000 --- a/db/post_migrate/20161221140236_remove_unneeded_services.rb +++ /dev/null @@ -1,15 +0,0 @@ -class RemoveUnneededServices < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def up - disable_statement_timeout - - execute("DELETE FROM services WHERE active = false AND properties = '{}';") - end - - def down - # noop - end -end diff --git a/db/post_migrate/20161221153951_rename_reserved_project_names.rb b/db/post_migrate/20161221153951_rename_reserved_project_names.rb deleted file mode 100644 index 32579256299..00000000000 --- a/db/post_migrate/20161221153951_rename_reserved_project_names.rb +++ /dev/null @@ -1,137 +0,0 @@ -class RenameReservedProjectNames < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - THREAD_COUNT = 8 - - KNOWN_PATHS = %w(.well-known - all - blame - blob - commits - create - create_dir - edit - files - find_file - groups - hooks - issues - logs_tree - merge_requests - new - preview - projects - raw - repository - robots.txt - s - snippets - teams - tree - u - unsubscribes - update - users - wikis).freeze - - def up - queues = Array.new(THREAD_COUNT) { Queue.new } - start = false - - threads = Array.new(THREAD_COUNT) do |index| - Thread.new do - queue = queues[index] - - # Wait until we have input to process. - until start; end - - rename_projects(queue.pop) until queue.empty? - end - end - - enum = queues.each - - reserved_projects.each_slice(100) do |slice| - begin - queue = enum.next - rescue StopIteration - enum.rewind - retry - end - - queue << slice - end - - start = true - - threads.each(&:join) - end - - def down - # nothing to do here - end - - private - - def reserved_projects - Project.unscoped - .includes(:namespace) - .where('EXISTS (SELECT 1 FROM namespaces WHERE projects.namespace_id = namespaces.id)') - .where('projects.path' => KNOWN_PATHS) - end - - def route_exists?(full_path) - quoted_path = ActiveRecord::Base.connection.quote_string(full_path) - - ActiveRecord::Base.connection - .select_all("SELECT id, path FROM routes WHERE path = '#{quoted_path}'").present? - end - - # Adds number to the end of the path that is not taken by other route - def rename_path(namespace_path, path_was) - counter = 0 - path = "#{path_was}#{counter}" - - while route_exists?("#{namespace_path}/#{path}") - counter += 1 - path = "#{path_was}#{counter}" - end - - path - end - - def rename_projects(projects) - projects.each do |project| - id = project.id - path_was = project.path - namespace_path = project.namespace.path - path = rename_path(namespace_path, path_was) - - begin - # Because project path update is quite complex operation we can't safely - # copy-paste all code from GitLab. As exception we use Rails code here - if rename_project_row(project, path) - after_rename_service(project, path_was, namespace_path).execute - end - rescue Exception => e # rubocop: disable Lint/RescueException - Rails.logger.error "Exception when renaming project #{id}: #{e.message}" - end - end - end - - def rename_project_row(project, path) - project.respond_to?(:update_attributes) && - project.update(path: path) && - defined?(Projects::AfterRenameService) - end - - def after_rename_service(project, path_was, namespace_path) - AfterRenameService.new( - project, - path_before: path_was, - full_path_before: "#{namespace_path}/#{path_was}" - ).execute - end -end diff --git a/db/post_migrate/20170104150317_requeue_pending_delete_projects.rb b/db/post_migrate/20170104150317_requeue_pending_delete_projects.rb deleted file mode 100644 index f567accb051..00000000000 --- a/db/post_migrate/20170104150317_requeue_pending_delete_projects.rb +++ /dev/null @@ -1,49 +0,0 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class RequeuePendingDeleteProjects < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def up - admin = User.find_by(admin: true) - return unless admin - - @offset = 0 - - loop do - ids = pending_delete_batch - - break if ids.rows.count.zero? - - args = ids.map { |id| [id['id'], admin.id, {}] } - - Sidekiq::Client.push_bulk('class' => "ProjectDestroyWorker", 'args' => args) - - @offset += 1 - end - end - - def down - # noop - end - - private - - def pending_delete_batch - connection.exec_query(find_batch) - end - - BATCH_SIZE = 5000 - - def find_batch - projects = Arel::Table.new(:projects) - projects.project(projects[:id]) - .where(projects[:pending_delete].eq(true)) - .where(projects[:namespace_id].not_eq(nil)) - .skip(@offset * BATCH_SIZE) - .take(BATCH_SIZE) - .to_sql - end -end diff --git a/db/post_migrate/20170106142508_fill_authorized_projects.rb b/db/post_migrate/20170106142508_fill_authorized_projects.rb deleted file mode 100644 index 1f1dd0f47f0..00000000000 --- a/db/post_migrate/20170106142508_fill_authorized_projects.rb +++ /dev/null @@ -1,30 +0,0 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class FillAuthorizedProjects < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - class User < ActiveRecord::Base - self.table_name = 'users' - end - - # Set this constant to true if this migration requires downtime. - DOWNTIME = false - - # We're not inserting any data so we don't need to start a transaction. - disable_ddl_transaction! - - def up - relation = User.select(:id) - .where('authorized_projects_populated IS NOT TRUE') - - relation.find_in_batches(batch_size: 1_000) do |rows| - args = rows.map { |row| [row.id] } - - Sidekiq::Client.push_bulk('class' => 'AuthorizedProjectsWorker', 'args' => args) - end - end - - def down - end -end diff --git a/db/post_migrate/20170106172224_remove_project_authorizations_id_column.rb b/db/post_migrate/20170106172224_remove_project_authorizations_id_column.rb deleted file mode 100644 index 893af23465a..00000000000 --- a/db/post_migrate/20170106172224_remove_project_authorizations_id_column.rb +++ /dev/null @@ -1,12 +0,0 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class RemoveProjectAuthorizationsIdColumn < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def change - remove_column :project_authorizations, :id, :primary_key - end -end diff --git a/db/post_migrate/20170131214021_reset_users_authorized_projects_populated.rb b/db/post_migrate/20170131214021_reset_users_authorized_projects_populated.rb deleted file mode 100644 index 055a14ad729..00000000000 --- a/db/post_migrate/20170131214021_reset_users_authorized_projects_populated.rb +++ /dev/null @@ -1,18 +0,0 @@ -# rubocop:disable Migration/UpdateLargeTable -# rubocop:disable Migration/UpdateColumnInBatches -class ResetUsersAuthorizedProjectsPopulated < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - # This ensures we don't lock all users for the duration of the migration. - update_column_in_batches(:users, :authorized_projects_populated, nil) - end - - def down - # noop - end -end diff --git a/db/post_migrate/20170206040400_remove_inactive_default_email_services.rb b/db/post_migrate/20170206040400_remove_inactive_default_email_services.rb deleted file mode 100644 index f221dac8e20..00000000000 --- a/db/post_migrate/20170206040400_remove_inactive_default_email_services.rb +++ /dev/null @@ -1,41 +0,0 @@ -class RemoveInactiveDefaultEmailServices < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - Gitlab::Database.with_connection_pool(2) do |pool| - threads = [] - - threads << Thread.new do - pool.with_connection do |connection| - connection.execute <<-SQL.strip_heredoc - DELETE FROM services - WHERE type = 'BuildsEmailService' - AND active IS FALSE - AND properties = '{"notify_only_broken_builds":true}'; - SQL - end - end - - threads << Thread.new do - pool.with_connection do |connection| - connection.execute <<-SQL.strip_heredoc - DELETE FROM services - WHERE type = 'PipelinesEmailService' - AND active IS FALSE - AND properties = '{"notify_only_broken_pipelines":true}'; - SQL - end - end - - threads.each(&:join) - end - end - - def down - # Nothing can be done to restore the records - end -end diff --git a/db/post_migrate/20170206101007_remove_trackable_columns_from_timelogs.rb b/db/post_migrate/20170206101007_remove_trackable_columns_from_timelogs.rb deleted file mode 100644 index 14f5d0d4add..00000000000 --- a/db/post_migrate/20170206101007_remove_trackable_columns_from_timelogs.rb +++ /dev/null @@ -1,24 +0,0 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class RemoveTrackableColumnsFromTimelogs < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - # When using the methods "add_concurrent_index" or "add_column_with_default" - # you must disable the use of transactions as these methods can not run in an - # existing transaction. When using "add_concurrent_index" make sure that this - # method is the _only_ method called in the migration, any other changes - # should go in a separate migration. This ensures that upon failure _only_ the - # index creation fails and can be retried or reverted easily. - # - # To disable transactions uncomment the following line and remove these - # comments: - # disable_ddl_transaction! - - def change - remove_column :timelogs, :trackable_id, :integer - remove_column :timelogs, :trackable_type, :string - end -end diff --git a/db/post_migrate/20170206101030_validate_foreign_keys_on_timelogs.rb b/db/post_migrate/20170206101030_validate_foreign_keys_on_timelogs.rb deleted file mode 100644 index b5a5c0f06c7..00000000000 --- a/db/post_migrate/20170206101030_validate_foreign_keys_on_timelogs.rb +++ /dev/null @@ -1,32 +0,0 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class ValidateForeignKeysOnTimelogs < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - # When using the methods "add_concurrent_index" or "add_column_with_default" - # you must disable the use of transactions as these methods can not run in an - # existing transaction. When using "add_concurrent_index" make sure that this - # method is the _only_ method called in the migration, any other changes - # should go in a separate migration. This ensures that upon failure _only_ the - # index creation fails and can be retried or reverted easily. - # - # To disable transactions uncomment the following line and remove these - # comments: - disable_ddl_transaction! - - def up - if Gitlab::Database.postgresql? - execute <<-EOF - ALTER TABLE timelogs VALIDATE CONSTRAINT "fk_timelogs_issues_issue_id"; - ALTER TABLE timelogs VALIDATE CONSTRAINT "fk_timelogs_merge_requests_merge_request_id"; - EOF - end - end - - def down - # noop - end -end diff --git a/db/post_migrate/20170209140523_validate_foreign_keys_on_oauth_openid_requests.rb b/db/post_migrate/20170209140523_validate_foreign_keys_on_oauth_openid_requests.rb deleted file mode 100644 index 81ac4cf1373..00000000000 --- a/db/post_migrate/20170209140523_validate_foreign_keys_on_oauth_openid_requests.rb +++ /dev/null @@ -1,20 +0,0 @@ -class ValidateForeignKeysOnOauthOpenidRequests < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - if Gitlab::Database.postgresql? - execute %q{ - ALTER TABLE "oauth_openid_requests" - VALIDATE CONSTRAINT "fk_oauth_openid_requests_oauth_access_grants_access_grant_id"; - } - end - end - - def down - # noop - end -end diff --git a/db/post_migrate/20170211073944_disable_invalid_service_templates.rb b/db/post_migrate/20170211073944_disable_invalid_service_templates.rb deleted file mode 100644 index 31234e5b086..00000000000 --- a/db/post_migrate/20170211073944_disable_invalid_service_templates.rb +++ /dev/null @@ -1,13 +0,0 @@ -class DisableInvalidServiceTemplates < ActiveRecord::Migration[4.2] - DOWNTIME = false - - class Service < ActiveRecord::Base - self.inheritance_column = nil - end - - def up - Service.where(template: true, active: true).each do |template| - template.update(active: false) unless template.valid? - end - end -end diff --git a/db/post_migrate/20170214111112_delete_deprecated_gitlab_ci_service.rb b/db/post_migrate/20170214111112_delete_deprecated_gitlab_ci_service.rb deleted file mode 100644 index c273060f8b0..00000000000 --- a/db/post_migrate/20170214111112_delete_deprecated_gitlab_ci_service.rb +++ /dev/null @@ -1,15 +0,0 @@ -class DeleteDeprecatedGitlabCiService < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def up - disable_statement_timeout - - execute("DELETE FROM services WHERE type = 'GitlabCiService';") - end - - def down - # noop - end -end diff --git a/db/post_migrate/20170215200045_remove_theme_id_from_users.rb b/db/post_migrate/20170215200045_remove_theme_id_from_users.rb deleted file mode 100644 index 937fe3f57af..00000000000 --- a/db/post_migrate/20170215200045_remove_theme_id_from_users.rb +++ /dev/null @@ -1,9 +0,0 @@ -class RemoveThemeIdFromUsers < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def change - remove_column :users, :theme_id, :integer - end -end diff --git a/db/post_migrate/20170301205640_migrate_build_events_to_pipeline_events.rb b/db/post_migrate/20170301205640_migrate_build_events_to_pipeline_events.rb deleted file mode 100644 index c2d28d79491..00000000000 --- a/db/post_migrate/20170301205640_migrate_build_events_to_pipeline_events.rb +++ /dev/null @@ -1,86 +0,0 @@ -class MigrateBuildEventsToPipelineEvents < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def up - Gitlab::Database.with_connection_pool(2) do |pool| - threads = [] - - threads << Thread.new do - pool.with_connection do |connection| - Thread.current[:foreign_key_connection] = connection - - execute(<<-SQL.strip_heredoc) - UPDATE services - SET properties = replace(properties, - 'notify_only_broken_builds', - 'notify_only_broken_pipelines') - , pipeline_events = #{true_value} - , build_events = #{false_value} - WHERE type IN - ('SlackService', 'MattermostService', 'HipchatService') - AND build_events = #{true_value}; - SQL - end - end - - threads << Thread.new do - pool.with_connection do |connection| - Thread.current[:foreign_key_connection] = connection - - execute(update_pipeline_services_sql) - end - end - - threads.each(&:join) - end - end - - def down - # Don't bother to migrate the data back - end - - def connection - # Rails memoizes connection objects, but this causes them to be shared - # amongst threads; we don't want that. - Thread.current[:foreign_key_connection] || ActiveRecord::Base.connection - end - - private - - def update_pipeline_services_sql - if Gitlab::Database.postgresql? - <<-SQL - UPDATE services - SET type = 'PipelinesEmailService' - , properties = replace(properties, - 'notify_only_broken_builds', - 'notify_only_broken_pipelines') - , pipeline_events = #{true_value} - , build_events = #{false_value} - WHERE type = 'BuildsEmailService' - AND - (SELECT 1 FROM services pipeline_services - WHERE pipeline_services.project_id = services.project_id - AND pipeline_services.type = 'PipelinesEmailService' LIMIT 1) - IS NULL; - SQL - else - <<-SQL - UPDATE services build_services - LEFT OUTER JOIN services pipeline_services - ON build_services.project_id = pipeline_services.project_id - AND pipeline_services.type = 'PipelinesEmailService' - SET build_services.type = 'PipelinesEmailService' - , build_services.properties = replace(build_services.properties, - 'notify_only_broken_builds', - 'notify_only_broken_pipelines') - , build_services.pipeline_events = #{true_value} - , build_services.build_events = #{false_value} - WHERE build_services.type = 'BuildsEmailService' - AND pipeline_services.id IS NULL; - SQL - end.strip_heredoc - end -end diff --git a/db/post_migrate/20170306170512_migrate_legacy_manual_actions.rb b/db/post_migrate/20170306170512_migrate_legacy_manual_actions.rb deleted file mode 100644 index aa12e8ac3da..00000000000 --- a/db/post_migrate/20170306170512_migrate_legacy_manual_actions.rb +++ /dev/null @@ -1,23 +0,0 @@ -class MigrateLegacyManualActions < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def up - disable_statement_timeout - - execute <<-EOS - UPDATE ci_builds SET status = 'manual', allow_failure = true - WHERE ci_builds.when = 'manual' AND ci_builds.status = 'skipped'; - EOS - end - - def down - disable_statement_timeout - - execute <<-EOS - UPDATE ci_builds SET status = 'skipped', allow_failure = false - WHERE ci_builds.when = 'manual' AND ci_builds.status = 'manual'; - EOS - end -end diff --git a/db/post_migrate/20170309171644_reset_relative_position_for_issue.rb b/db/post_migrate/20170309171644_reset_relative_position_for_issue.rb deleted file mode 100644 index 2cf4cf61d8f..00000000000 --- a/db/post_migrate/20170309171644_reset_relative_position_for_issue.rb +++ /dev/null @@ -1,19 +0,0 @@ -# rubocop:disable Migration/UpdateLargeTable -# rubocop:disable Migration/UpdateColumnInBatches -class ResetRelativePositionForIssue < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - update_column_in_batches(:issues, :relative_position, nil) do |table, query| - query.where(table[:relative_position].not_eq(nil)) - end - end - - def down - # noop - end -end diff --git a/db/post_migrate/20170313133418_rename_more_reserved_project_names.rb b/db/post_migrate/20170313133418_rename_more_reserved_project_names.rb deleted file mode 100644 index 85c97e3687e..00000000000 --- a/db/post_migrate/20170313133418_rename_more_reserved_project_names.rb +++ /dev/null @@ -1,79 +0,0 @@ -class RenameMoreReservedProjectNames < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - KNOWN_PATHS = %w(artifacts graphs refs badges).freeze - - def up - reserved_projects.each_slice(100) do |slice| - rename_projects(slice) - end - end - - def down - # nothing to do here - end - - private - - def reserved_projects - Project.unscoped - .includes(:namespace) - .where('EXISTS (SELECT 1 FROM namespaces WHERE projects.namespace_id = namespaces.id)') - .where('projects.path' => KNOWN_PATHS) - end - - def route_exists?(full_path) - quoted_path = ActiveRecord::Base.connection.quote_string(full_path) - - ActiveRecord::Base.connection - .select_all("SELECT id, path FROM routes WHERE path = '#{quoted_path}'").present? - end - - # Adds number to the end of the path that is not taken by other route - def rename_path(namespace_path, path_was) - counter = 0 - path = "#{path_was}#{counter}" - - while route_exists?("#{namespace_path}/#{path}") - counter += 1 - path = "#{path_was}#{counter}" - end - - path - end - - def rename_projects(projects) - projects.each do |project| - id = project.id - path_was = project.path - namespace_path = project.namespace.path - path = rename_path(namespace_path, path_was) - - begin - # Because project path update is quite complex operation we can't safely - # copy-paste all code from GitLab. As exception we use Rails code here - if rename_project_row(project, path) - after_rename_service(project, path_was, namespace_path).execute - end - rescue Exception => e # rubocop: disable Lint/RescueException - Rails.logger.error "Exception when renaming project #{id}: #{e.message}" - end - end - end - - def rename_project_row(project, path) - project.respond_to?(:update_attributes) && - project.update(path: path) && - defined?(Projects::AfterRenameService) - end - - def after_rename_service(project, path_was, namespace_path) - AfterRenameService.new( - project, - path_before: path_was, - full_path_before: "#{namespace_path}/#{path_was}" - ).execute - end -end diff --git a/db/post_migrate/20170317162059_update_upload_paths_to_system.rb b/db/post_migrate/20170317162059_update_upload_paths_to_system.rb deleted file mode 100644 index 99cdca465e2..00000000000 --- a/db/post_migrate/20170317162059_update_upload_paths_to_system.rb +++ /dev/null @@ -1,57 +0,0 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class UpdateUploadPathsToSystem < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - AFFECTED_MODELS = %w(User Project Note Namespace Appearance) - - disable_ddl_transaction! - - def up - update_column_in_batches(:uploads, :path, replace_sql(arel_table[:path], base_directory, new_upload_dir)) do |_table, query| - query.where(uploads_to_switch_to_new_path) - end - end - - def down - update_column_in_batches(:uploads, :path, replace_sql(arel_table[:path], new_upload_dir, base_directory)) do |_table, query| - query.where(uploads_to_switch_to_old_path) - end - end - - # "SELECT \"uploads\".* FROM \"uploads\" WHERE \"uploads\".\"model_type\" IN ('User', 'Project', 'Note', 'Namespace', 'Appearance') AND (\"uploads\".\"path\" ILIKE 'uploads/%' AND NOT (\"uploads\".\"path\" ILIKE 'uploads/system/%'))" - def uploads_to_switch_to_new_path - affected_uploads.and(starting_with_base_directory).and(starting_with_new_upload_directory.not) - end - - # "SELECT \"uploads\".* FROM \"uploads\" WHERE \"uploads\".\"model_type\" IN ('User', 'Project', 'Note', 'Namespace', 'Appearance') AND (\"uploads\".\"path\" ILIKE 'uploads/%' AND \"uploads\".\"path\" ILIKE 'uploads/system/%')" - def uploads_to_switch_to_old_path - affected_uploads.and(starting_with_new_upload_directory) - end - - def starting_with_base_directory - arel_table[:path].matches("#{base_directory}/%") - end - - def starting_with_new_upload_directory - arel_table[:path].matches("#{new_upload_dir}/%") - end - - def affected_uploads - arel_table[:model_type].in(AFFECTED_MODELS) - end - - def base_directory - "uploads" - end - - def new_upload_dir - File.join(base_directory, "-", "system") - end - - def arel_table - Arel::Table.new(:uploads) - end -end diff --git a/db/post_migrate/20170324160416_migrate_user_activities_to_users_last_activity_on.rb b/db/post_migrate/20170324160416_migrate_user_activities_to_users_last_activity_on.rb deleted file mode 100644 index 61a5c364b2f..00000000000 --- a/db/post_migrate/20170324160416_migrate_user_activities_to_users_last_activity_on.rb +++ /dev/null @@ -1,88 +0,0 @@ -# rubocop:disable Migration/UpdateLargeTable -class MigrateUserActivitiesToUsersLastActivityOn < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - DOWNTIME = false - USER_ACTIVITY_SET_KEY = 'user/activities'.freeze - ACTIVITIES_PER_PAGE = 100 - TIME_WHEN_ACTIVITY_SET_WAS_INTRODUCED = Time.utc(2016, 12, 1) - - def up - return if activities_count(TIME_WHEN_ACTIVITY_SET_WAS_INTRODUCED, Time.now).zero? - - day = Time.at(activities(TIME_WHEN_ACTIVITY_SET_WAS_INTRODUCED, Time.now).first.second) - - transaction do - while day <= Time.now.utc.tomorrow - persist_last_activity_on(day: day) - day = day.tomorrow - end - end - end - - def down - # This ensures we don't lock all users for the duration of the migration. - update_column_in_batches(:users, :last_activity_on, nil) do |table, query| - query.where(table[:last_activity_on].not_eq(nil)) - end - end - - private - - def persist_last_activity_on(day:, page: 1) - activities_count = activities_count(day.at_beginning_of_day, day.at_end_of_day) - - return if activities_count.zero? - - activities = activities(day.at_beginning_of_day, day.at_end_of_day, page: page) - - update_sql = - Arel::UpdateManager.new - .table(users_table) - .set(users_table[:last_activity_on] => day.to_date) - .where(users_table[:username].in(activities.map(&:first))) - .to_sql - - connection.exec_update(update_sql, self.class.name, []) - - unless last_page?(page, activities_count) - persist_last_activity_on(day: day, page: page + 1) - end - end - - def users_table - @users_table ||= Arel::Table.new(:users) - end - - def activities(from, to, page: 1) - Gitlab::Redis::SharedState.with do |redis| - redis.zrangebyscore(USER_ACTIVITY_SET_KEY, from.to_i, to.to_i, - with_scores: true, - limit: limit(page)) - end - end - - def activities_count(from, to) - Gitlab::Redis::SharedState.with do |redis| - redis.zcount(USER_ACTIVITY_SET_KEY, from.to_i, to.to_i) - end - end - - def limit(page) - [offset(page), ACTIVITIES_PER_PAGE] - end - - def total_pages(count) - (count.to_f / ACTIVITIES_PER_PAGE).ceil - end - - def last_page?(page, count) - page >= total_pages(count) - end - - def offset(page) - (page - 1) * ACTIVITIES_PER_PAGE - end -end diff --git a/db/post_migrate/20170404170532_remove_notes_original_discussion_id.rb b/db/post_migrate/20170404170532_remove_notes_original_discussion_id.rb deleted file mode 100644 index 334742f04e4..00000000000 --- a/db/post_migrate/20170404170532_remove_notes_original_discussion_id.rb +++ /dev/null @@ -1,23 +0,0 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class RemoveNotesOriginalDiscussionId < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - # When using the methods "add_concurrent_index" or "add_column_with_default" - # you must disable the use of transactions as these methods can not run in an - # existing transaction. When using "add_concurrent_index" make sure that this - # method is the _only_ method called in the migration, any other changes - # should go in a separate migration. This ensures that upon failure _only_ the - # index creation fails and can be retried or reverted easily. - # - # To disable transactions uncomment the following line and remove these - # comments: - # disable_ddl_transaction! - - def change - remove_column :notes, :original_discussion_id, :string - end -end diff --git a/db/post_migrate/20170406111121_clean_upload_symlinks.rb b/db/post_migrate/20170406111121_clean_upload_symlinks.rb deleted file mode 100644 index 5fec00aa198..00000000000 --- a/db/post_migrate/20170406111121_clean_upload_symlinks.rb +++ /dev/null @@ -1,53 +0,0 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class CleanUploadSymlinks < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - disable_ddl_transaction! - - DOWNTIME = false - DIRECTORIES_TO_MOVE = %w(user project note group appearance) - - def up - return unless file_storage? - - DIRECTORIES_TO_MOVE.each do |dir| - symlink_location = File.join(old_upload_dir, dir) - next unless File.symlink?(symlink_location) - - say "removing symlink: #{symlink_location}" - FileUtils.rm(symlink_location) - end - end - - def down - return unless file_storage? - - DIRECTORIES_TO_MOVE.each do |dir| - symlink = File.join(old_upload_dir, dir) - destination = File.join(new_upload_dir, dir) - - next if File.directory?(symlink) - next unless File.directory?(destination) - - say "Creating symlink #{symlink} -> #{destination}" - FileUtils.ln_s(destination, symlink) - end - end - - def file_storage? - CarrierWave::Uploader::Base.storage == CarrierWave::Storage::File - end - - def base_directory - Rails.root - end - - def old_upload_dir - File.join(base_directory, "public", "uploads") - end - - def new_upload_dir - File.join(base_directory, "public", "uploads", "-", "system") - end -end diff --git a/db/post_migrate/20170406142253_migrate_user_project_view.rb b/db/post_migrate/20170406142253_migrate_user_project_view.rb deleted file mode 100644 index 3601baba787..00000000000 --- a/db/post_migrate/20170406142253_migrate_user_project_view.rb +++ /dev/null @@ -1,22 +0,0 @@ -# rubocop:disable Migration/UpdateLargeTable -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class MigrateUserProjectView < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - # Set this constant to true if this migration requires downtime. - DOWNTIME = false - - disable_ddl_transaction! - - def up - update_column_in_batches(:users, :project_view, 2) do |table, query| - query.where(table[:project_view].eq(0)) - end - end - - def down - # Nothing can be done to restore old values - end -end diff --git a/db/post_migrate/20170408033905_remove_old_cache_directories.rb b/db/post_migrate/20170408033905_remove_old_cache_directories.rb deleted file mode 100644 index 22bc5b9db7b..00000000000 --- a/db/post_migrate/20170408033905_remove_old_cache_directories.rb +++ /dev/null @@ -1,23 +0,0 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -# Remove all files from old custom carrierwave's cache directories. -# See https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/9466 - -class RemoveOldCacheDirectories < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - # FileUploader cache. - FileUtils.rm_rf(Dir[Rails.root.join('public', 'uploads', 'tmp', '*')]) - end - - def down - # Old cache is not supposed to be recoverable. - # So the down method is empty. - end -end diff --git a/db/post_migrate/20170412174900_rename_reserved_dynamic_paths.rb b/db/post_migrate/20170412174900_rename_reserved_dynamic_paths.rb deleted file mode 100644 index c9ff91b0401..00000000000 --- a/db/post_migrate/20170412174900_rename_reserved_dynamic_paths.rb +++ /dev/null @@ -1,62 +0,0 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class RenameReservedDynamicPaths < ActiveRecord::Migration[4.2] - include Gitlab::Database::RenameReservedPathsMigration::V1 - - DOWNTIME = false - - disable_ddl_transaction! - - DISALLOWED_ROOT_PATHS = %w[ - - - abuse_reports - api - autocomplete - explore - health_check - import - invites - jwt - koding - member - notification_settings - oauth - sent_notifications - unicorn_test - uploads - users - ] - - DISALLOWED_WILDCARD_PATHS = %w[ - environments/folders - gitlab-lfs/objects - info/lfs/objects - ] - - DISSALLOWED_GROUP_PATHS = %w[ - activity - analytics - audit_events - avatar - group_members - hooks - labels - ldap - ldap_group_links - milestones - notification_setting - pipeline_quota - subgroups - ] - - def up - rename_root_paths(DISALLOWED_ROOT_PATHS) - rename_wildcard_paths(DISALLOWED_WILDCARD_PATHS) - rename_child_paths(DISSALLOWED_GROUP_PATHS) - end - - def down - # nothing to do - end -end diff --git a/db/post_migrate/20170425121605_migrate_trigger_schedules_to_pipeline_schedules.rb b/db/post_migrate/20170425121605_migrate_trigger_schedules_to_pipeline_schedules.rb deleted file mode 100644 index 99ded277277..00000000000 --- a/db/post_migrate/20170425121605_migrate_trigger_schedules_to_pipeline_schedules.rb +++ /dev/null @@ -1,48 +0,0 @@ -class MigrateTriggerSchedulesToPipelineSchedules < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def up - connection.execute <<~SQL - DELETE FROM ci_trigger_schedules WHERE NOT EXISTS - (SELECT true FROM projects - WHERE ci_trigger_schedules.project_id = projects.id - ) - SQL - - connection.execute <<-SQL - INSERT INTO ci_pipeline_schedules ( - project_id, - created_at, - updated_at, - deleted_at, - cron, - cron_timezone, - next_run_at, - ref, - active, - owner_id, - description - ) - SELECT - ci_trigger_schedules.project_id, - ci_trigger_schedules.created_at, - ci_trigger_schedules.updated_at, - ci_trigger_schedules.deleted_at, - ci_trigger_schedules.cron, - ci_trigger_schedules.cron_timezone, - ci_trigger_schedules.next_run_at, - ci_trigger_schedules.ref, - ci_trigger_schedules.active, - ci_triggers.owner_id, - ci_triggers.description - FROM ci_trigger_schedules - INNER JOIN ci_triggers ON ci_trigger_schedules.trigger_id=ci_triggers.id; - SQL - end - - def down - # no op as the data has been removed - end -end diff --git a/db/post_migrate/20170425130047_drop_ci_trigger_schedules_table.rb b/db/post_migrate/20170425130047_drop_ci_trigger_schedules_table.rb deleted file mode 100644 index 9d515aca8b4..00000000000 --- a/db/post_migrate/20170425130047_drop_ci_trigger_schedules_table.rb +++ /dev/null @@ -1,32 +0,0 @@ -class DropCiTriggerSchedulesTable < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - drop_table :ci_trigger_schedules - end - - def down - create_table "ci_trigger_schedules", force: :cascade do |t| - t.integer "project_id" - t.integer "trigger_id", null: false - t.datetime "deleted_at" - t.datetime "created_at" - t.datetime "updated_at" - t.string "cron" - t.string "cron_timezone" - t.datetime "next_run_at" - t.string "ref" - t.boolean "active" - end - - add_index "ci_trigger_schedules", %w(active next_run_at), name: "index_ci_trigger_schedules_on_active_and_next_run_at", using: :btree - add_index "ci_trigger_schedules", ["project_id"], name: "index_ci_trigger_schedules_on_project_id", using: :btree - add_index "ci_trigger_schedules", ["next_run_at"], name: "index_ci_trigger_schedules_on_next_run_at" - - add_concurrent_foreign_key "ci_trigger_schedules", "ci_triggers", column: :trigger_id, on_delete: :cascade - end -end diff --git a/db/post_migrate/20170502070007_enable_auto_cancel_pending_pipelines_for_all.rb b/db/post_migrate/20170502070007_enable_auto_cancel_pending_pipelines_for_all.rb deleted file mode 100644 index 4d091d7f275..00000000000 --- a/db/post_migrate/20170502070007_enable_auto_cancel_pending_pipelines_for_all.rb +++ /dev/null @@ -1,19 +0,0 @@ -# rubocop:disable Migration/UpdateLargeTable -# rubocop:disable Migration/UpdateColumnInBatches -class EnableAutoCancelPendingPipelinesForAll < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - DOWNTIME = false - - def up - disable_statement_timeout do - update_column_in_batches(:projects, :auto_cancel_pending_pipelines, 1) - end - end - - def down - # Nothing we can do! - end -end diff --git a/db/post_migrate/20170503004427_update_retried_for_ci_build.rb b/db/post_migrate/20170503004427_update_retried_for_ci_build.rb deleted file mode 100644 index 596f8593308..00000000000 --- a/db/post_migrate/20170503004427_update_retried_for_ci_build.rb +++ /dev/null @@ -1,69 +0,0 @@ -# rubocop:disable Migration/UpdateLargeTable -class UpdateRetriedForCiBuild < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - if Gitlab::Database.mysql? - up_mysql - else - disable_statement_timeout do - up_postgres - end - end - end - - def down - end - - private - - def up_mysql - # This is a trick to overcome MySQL limitation: - # Mysql2::Error: Table 'ci_builds' is specified twice, both as a target for 'UPDATE' and as a separate source for data - # However, this leads to create a temporary table from `max(ci_builds.id)` which is slow and do full database update - execute <<-SQL.strip_heredoc - UPDATE ci_builds SET retried= - (id NOT IN ( - SELECT * FROM (SELECT MAX(ci_builds.id) FROM ci_builds GROUP BY commit_id, name) AS latest_jobs - )) - WHERE retried IS NULL - SQL - end - - def up_postgres - with_temporary_partial_index do - latest_id = <<-SQL.strip_heredoc - SELECT MAX(ci_builds2.id) - FROM ci_builds ci_builds2 - WHERE ci_builds.commit_id=ci_builds2.commit_id - AND ci_builds.name=ci_builds2.name - SQL - - # This is slow update as it does single-row query - # This is designed to be run as idle, or a post deployment migration - is_retried = Arel.sql("((#{latest_id}) != ci_builds.id)") - - update_column_in_batches(:ci_builds, :retried, is_retried) do |table, query| - query.where(table[:retried].eq(nil)) - end - end - end - - def with_temporary_partial_index - if Gitlab::Database.postgresql? - unless index_exists?(:ci_builds, :id, name: :index_for_ci_builds_retried_migration) - execute 'CREATE INDEX CONCURRENTLY index_for_ci_builds_retried_migration ON ci_builds (id) WHERE retried IS NULL;' - end - end - - yield - - if Gitlab::Database.postgresql? && index_exists?(:ci_builds, :id, name: :index_for_ci_builds_retried_migration) - execute 'DROP INDEX CONCURRENTLY index_for_ci_builds_retried_migration' - end - end -end diff --git a/db/post_migrate/20170503120310_remove_users_authorized_projects_populated.rb b/db/post_migrate/20170503120310_remove_users_authorized_projects_populated.rb deleted file mode 100644 index 891ce44f60a..00000000000 --- a/db/post_migrate/20170503120310_remove_users_authorized_projects_populated.rb +++ /dev/null @@ -1,15 +0,0 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class RemoveUsersAuthorizedProjectsPopulated < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - # Set this constant to true if this migration requires downtime. - DOWNTIME = false - - disable_ddl_transaction! - - def change - remove_column :users, :authorized_projects_populated, :boolean - end -end diff --git a/db/post_migrate/20170508170547_add_head_pipeline_for_each_merge_request.rb b/db/post_migrate/20170508170547_add_head_pipeline_for_each_merge_request.rb deleted file mode 100644 index 6e7365f4c56..00000000000 --- a/db/post_migrate/20170508170547_add_head_pipeline_for_each_merge_request.rb +++ /dev/null @@ -1,28 +0,0 @@ -# rubocop:disable Migration/UpdateLargeTable -class AddHeadPipelineForEachMergeRequest < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - pipelines = Arel::Table.new(:ci_pipelines) - merge_requests = Arel::Table.new(:merge_requests) - - disable_statement_timeout do - head_id = pipelines - .project(Arel::Nodes::NamedFunction.new('max', [pipelines[:id]])) - .from(pipelines) - .where(pipelines[:ref].eq(merge_requests[:source_branch])) - .where(pipelines[:project_id].eq(merge_requests[:source_project_id])) - - sub_query = Arel::Nodes::SqlLiteral.new(Arel::Nodes::Grouping.new(head_id).to_sql) - - update_column_in_batches(:merge_requests, :head_pipeline_id, sub_query) - end - end - - def down - end -end diff --git a/db/post_migrate/20170510101043_add_foreign_key_on_pipeline_schedule_owner.rb b/db/post_migrate/20170510101043_add_foreign_key_on_pipeline_schedule_owner.rb deleted file mode 100644 index 85586aecd54..00000000000 --- a/db/post_migrate/20170510101043_add_foreign_key_on_pipeline_schedule_owner.rb +++ /dev/null @@ -1,35 +0,0 @@ -class AddForeignKeyOnPipelineScheduleOwner < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - execute <<-SQL - UPDATE ci_pipeline_schedules - SET owner_id = NULL - WHERE NOT EXISTS ( - SELECT true - FROM users - WHERE ci_pipeline_schedules.owner_id = users.id - ) - SQL - - add_concurrent_foreign_key(:ci_pipeline_schedules, :users, column: :owner_id, on_delete: on_delete) - end - - def down - remove_foreign_key(:ci_pipeline_schedules, column: :owner_id) - end - - private - - def on_delete - if Gitlab::Database.mysql? - :nullify - else - 'SET NULL' - end - end -end diff --git a/db/post_migrate/20170511100900_cleanup_rename_web_hooks_build_events_to_job_events.rb b/db/post_migrate/20170511100900_cleanup_rename_web_hooks_build_events_to_job_events.rb deleted file mode 100644 index b4a3db65607..00000000000 --- a/db/post_migrate/20170511100900_cleanup_rename_web_hooks_build_events_to_job_events.rb +++ /dev/null @@ -1,18 +0,0 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class CleanupRenameWebHooksBuildEventsToJobEvents < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - cleanup_concurrent_column_rename :web_hooks, :build_events, :job_events - end - - def down - rename_column_concurrently :web_hooks, :job_events, :build_events - end -end diff --git a/db/post_migrate/20170511101000_cleanup_rename_services_build_events_to_job_events.rb b/db/post_migrate/20170511101000_cleanup_rename_services_build_events_to_job_events.rb deleted file mode 100644 index 65342747321..00000000000 --- a/db/post_migrate/20170511101000_cleanup_rename_services_build_events_to_job_events.rb +++ /dev/null @@ -1,18 +0,0 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class CleanupRenameServicesBuildEventsToJobEvents < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - cleanup_concurrent_column_rename :services, :build_events, :job_events - end - - def down - rename_column_concurrently :services, :job_events, :build_events - end -end diff --git a/db/post_migrate/20170516165238_cleanup_trigger_for_issues.rb b/db/post_migrate/20170516165238_cleanup_trigger_for_issues.rb deleted file mode 100644 index affeba52250..00000000000 --- a/db/post_migrate/20170516165238_cleanup_trigger_for_issues.rb +++ /dev/null @@ -1,39 +0,0 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class CleanupTriggerForIssues < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - # Set this constant to true if this migration requires downtime. - DOWNTIME = false - - # When a migration requires downtime you **must** uncomment the following - # constant and define a short and easy to understand explanation as to why the - # migration requires downtime. - # DOWNTIME_REASON = '' - - # When using the methods "add_concurrent_index", "remove_concurrent_index" or - # "add_column_with_default" you must disable the use of transactions - # as these methods can not run in an existing transaction. - # When using "add_concurrent_index" or "remove_concurrent_index" methods make sure - # that either of them is the _only_ method called in the migration, - # any other changes should go in a separate migration. - # This ensures that upon failure _only_ the index creation or removing fails - # and can be retried or reverted easily. - # - # To disable transactions uncomment the following line and remove these - # comments: - disable_ddl_transaction! - - def up - if Gitlab::Database.postgresql? - execute <<-EOF - DROP TRIGGER IF EXISTS replicate_assignee_id ON issues; - DROP FUNCTION IF EXISTS replicate_assignee_id(); - EOF - end - end - - def down - end -end diff --git a/db/post_migrate/20170516181025_add_constraints_to_issue_assignees_table.rb b/db/post_migrate/20170516181025_add_constraints_to_issue_assignees_table.rb deleted file mode 100644 index 03456a31b0d..00000000000 --- a/db/post_migrate/20170516181025_add_constraints_to_issue_assignees_table.rb +++ /dev/null @@ -1,37 +0,0 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class AddConstraintsToIssueAssigneesTable < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - # Set this constant to true if this migration requires downtime. - DOWNTIME = false - - # When a migration requires downtime you **must** uncomment the following - # constant and define a short and easy to understand explanation as to why the - # migration requires downtime. - # DOWNTIME_REASON = '' - - # When using the methods "add_concurrent_index", "remove_concurrent_index" or - # "add_column_with_default" you must disable the use of transactions - # as these methods can not run in an existing transaction. - # When using "add_concurrent_index" or "remove_concurrent_index" methods make sure - # that either of them is the _only_ method called in the migration, - # any other changes should go in a separate migration. - # This ensures that upon failure _only_ the index creation or removing fails - # and can be retried or reverted easily. - # - # To disable transactions uncomment the following line and remove these - # comments: - # disable_ddl_transaction! - - def up - change_column_null :issue_assignees, :issue_id, false - change_column_null :issue_assignees, :user_id, false - end - - def down - change_column_null :issue_assignees, :issue_id, true - change_column_null :issue_assignees, :user_id, true - end -end diff --git a/db/post_migrate/20170518200835_rename_users_with_renamed_namespace.rb b/db/post_migrate/20170518200835_rename_users_with_renamed_namespace.rb deleted file mode 100644 index 4ba78727cc3..00000000000 --- a/db/post_migrate/20170518200835_rename_users_with_renamed_namespace.rb +++ /dev/null @@ -1,51 +0,0 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class RenameUsersWithRenamedNamespace < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - DISALLOWED_ROOT_PATHS = %w[ - abuse_reports - api - autocomplete - explore - health_check - import - invites - jwt - koding - member - notification_settings - oauth - sent_notifications - unicorn_test - uploads - users - ] - - def up - DISALLOWED_ROOT_PATHS.each do |path| - users = Arel::Table.new(:users) - namespaces = Arel::Table.new(:namespaces) - predicate = namespaces[:owner_id].eq(users[:id]) - .and(namespaces[:type].eq(nil)) - .and(users[:username].matches(path)) - - update_sql = if Gitlab::Database.postgresql? - "UPDATE users SET username = namespaces.path "\ - "FROM namespaces WHERE #{predicate.to_sql}" - else - "UPDATE users INNER JOIN namespaces "\ - "ON namespaces.owner_id = users.id "\ - "SET username = namespaces.path "\ - "WHERE #{predicate.to_sql}" - end - - connection.execute(update_sql) - end - end - - def down - end -end diff --git a/db/post_migrate/20170518231126_fix_wrongly_renamed_routes.rb b/db/post_migrate/20170518231126_fix_wrongly_renamed_routes.rb deleted file mode 100644 index 28a2a2e01bf..00000000000 --- a/db/post_migrate/20170518231126_fix_wrongly_renamed_routes.rb +++ /dev/null @@ -1,105 +0,0 @@ -# rubocop:disable Migration/UpdateLargeTable -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class FixWronglyRenamedRoutes < ActiveRecord::Migration[4.2] - include Gitlab::Database::RenameReservedPathsMigration::V1 - - DOWNTIME = false - - disable_ddl_transaction! - - DISALLOWED_ROOT_PATHS = %w[ - - - abuse_reports - api - autocomplete - explore - health_check - import - invites - jwt - koding - member - notification_settings - oauth - sent_notifications - unicorn_test - uploads - users - ] - - FIXED_PATHS = DISALLOWED_ROOT_PATHS.map { |p| "#{p}0" } - - class Route < Gitlab::Database::RenameReservedPathsMigration::V1::MigrationClasses::Route - self.table_name = 'routes' - end - - def routes - @routes ||= Route.arel_table - end - - def namespaces - @namespaces ||= Arel::Table.new(:namespaces) - end - - def wildcard_collection(collection) - collection.map { |word| "#{word}%" } - end - - # The routes that got incorrectly renamed before, still have a namespace that - # contains the correct path. - # This query fetches all rows from the `routes` table that meet the following - # conditions using `api` as an example: - # - route.path ILIKE `api0%` - # - route.source_type = `Namespace` - # - namespace.parent_id IS NULL - # - namespace.path ILIKE `api%` - # - NOT(namespace.path ILIKE `api0%`) - # This gives us all root-routes, that were renamed, but their namespace was not. - # - def wrongly_renamed - Route.joins("INNER JOIN namespaces ON routes.source_id = namespaces.id") - .where( - routes[:source_type].eq('Namespace') - .and(namespaces[:parent_id].eq(nil)) - ) - .where(namespaces[:path].matches_any(wildcard_collection(DISALLOWED_ROOT_PATHS))) - .where.not(namespaces[:path].matches_any(wildcard_collection(FIXED_PATHS))) - .where(routes[:path].matches_any(wildcard_collection(FIXED_PATHS))) - end - - # Using the query above, we just fetch the `route.path` & the `namespace.path` - # `route.path` is the part of the route that is now incorrect - # `namespace.path` is what it should be - # We can use `route.path` to find all the namespaces that need to be fixed - # And we can use `namespace.path` to apply the correct name. - # - def paths_and_corrections - connection.select_all( - wrongly_renamed.select(routes[:path], namespaces[:path].as('namespace_path')).to_sql - ) - end - - # This can be used to limit the `update_in_batches` call to all routes for a - # single namespace, note the `/` that's what went wrong in the initial migration. - # - def routes_in_namespace_query(namespace) - routes[:path].matches_any([namespace, "#{namespace}/%"]) - end - - def up - paths_and_corrections.each do |root_namespace| - wrong_path = root_namespace['path'] - correct_path = root_namespace['namespace_path'] - replace_statement = replace_sql(Route.arel_table[:path], wrong_path, correct_path) - - update_column_in_batches(:routes, :path, replace_statement) do |table, query| - query.where(routes_in_namespace_query(wrong_path)) - end - end - end - - def down - end -end diff --git a/db/post_migrate/20170523073948_remove_assignee_id_from_issue.rb b/db/post_migrate/20170523073948_remove_assignee_id_from_issue.rb deleted file mode 100644 index d75bbb2f612..00000000000 --- a/db/post_migrate/20170523073948_remove_assignee_id_from_issue.rb +++ /dev/null @@ -1,48 +0,0 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class RemoveAssigneeIdFromIssue < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - # Set this constant to true if this migration requires downtime. - DOWNTIME = false - - # When a migration requires downtime you **must** uncomment the following - # constant and define a short and easy to understand explanation as to why the - # migration requires downtime. - # DOWNTIME_REASON = '' - - # When using the methods "add_concurrent_index", "remove_concurrent_index" or - # "add_column_with_default" you must disable the use of transactions - # as these methods can not run in an existing transaction. - # When using "add_concurrent_index" or "remove_concurrent_index" methods make sure - # that either of them is the _only_ method called in the migration, - # any other changes should go in a separate migration. - # This ensures that upon failure _only_ the index creation or removing fails - # and can be retried or reverted easily. - # - # To disable transactions uncomment the following line and remove these - # comments: - disable_ddl_transaction! - - class Issue < ActiveRecord::Base - self.table_name = 'issues' - - include ::EachBatch - end - - def up - remove_column :issues, :assignee_id - end - - def down - add_column :issues, :assignee_id, :integer - add_concurrent_index :issues, :assignee_id - - update_value = Arel.sql('(SELECT user_id FROM issue_assignees WHERE issue_assignees.issue_id = issues.id LIMIT 1)') - - # This is only used in the down step, so we can ignore the RuboCop warning - # about large tables, as this is very unlikely to be run on GitLab.com - update_column_in_batches(:issues, :assignee_id, update_value) # rubocop:disable Migration/UpdateLargeTable - end -end diff --git a/db/post_migrate/20170523083112_migrate_old_artifacts.rb b/db/post_migrate/20170523083112_migrate_old_artifacts.rb deleted file mode 100644 index 55e155c7619..00000000000 --- a/db/post_migrate/20170523083112_migrate_old_artifacts.rb +++ /dev/null @@ -1,72 +0,0 @@ -class MigrateOldArtifacts < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - # This uses special heuristic to find potential candidates for data migration - # Read more about this here: https://gitlab.com/gitlab-org/gitlab-ce/issues/32036#note_30422345 - - def up - builds_with_artifacts.find_each do |build| - build.migrate_artifacts! - end - end - - def down - end - - private - - def builds_with_artifacts - Build.with_artifacts - .joins('JOIN projects ON projects.id = ci_builds.project_id') - .where('ci_builds.id < ?', min_id) - .where('projects.ci_id IS NOT NULL') - .select('id', 'created_at', 'project_id', 'projects.ci_id AS ci_id') - end - - def min_id - Build.joins('JOIN projects ON projects.id = ci_builds.project_id') - .where('projects.ci_id IS NULL') - .pluck('coalesce(min(ci_builds.id), 0)') - .first - end - - class Build < ActiveRecord::Base - self.table_name = 'ci_builds' - - scope :with_artifacts, -> { where.not(artifacts_file: [nil, '']) } - - def migrate_artifacts! - return unless File.exist?(source_artifacts_path) - return if File.exist?(target_artifacts_path) - - ensure_target_path - - FileUtils.move(source_artifacts_path, target_artifacts_path) - end - - private - - def source_artifacts_path - @source_artifacts_path ||= - File.join(Gitlab.config.artifacts.path, - created_at.utc.strftime('%Y_%m'), - ci_id.to_s, id.to_s) - end - - def target_artifacts_path - @target_artifacts_path ||= - File.join(Gitlab.config.artifacts.path, - created_at.utc.strftime('%Y_%m'), - project_id.to_s, id.to_s) - end - - def ensure_target_path - directory = File.dirname(target_artifacts_path) - FileUtils.mkdir_p(directory) unless Dir.exist?(directory) - end - end -end diff --git a/db/post_migrate/20170525140254_rename_all_reserved_paths_again.rb b/db/post_migrate/20170525140254_rename_all_reserved_paths_again.rb deleted file mode 100644 index 59b8daaffdf..00000000000 --- a/db/post_migrate/20170525140254_rename_all_reserved_paths_again.rb +++ /dev/null @@ -1,102 +0,0 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class RenameAllReservedPathsAgain < ActiveRecord::Migration[4.2] - include Gitlab::Database::RenameReservedPathsMigration::V1 - - DOWNTIME = false - - disable_ddl_transaction! - - TOP_LEVEL_ROUTES = %w[ - - - .well-known - abuse_reports - admin - api - assets - autocomplete - ci - dashboard - explore - files - groups - health_check - help - import - invites - jwt - koding - notification_settings - oauth - profile - projects - public - robots.txt - s - search - sent_notifications - snippets - u - unicorn_test - unsubscribes - uploads - users - ].freeze - - PROJECT_WILDCARD_ROUTES = %w[ - badges - blame - blob - builds - commits - create - create_dir - edit - environments/folders - files - find_file - gitlab-lfs/objects - info/lfs/objects - new - preview - raw - refs - tree - update - wikis - ].freeze - - GROUP_ROUTES = %w[ - activity - analytics - audit_events - avatar - edit - group_members - hooks - issues - labels - ldap - ldap_group_links - merge_requests - milestones - notification_setting - pipeline_quota - projects - ].freeze - - def up - disable_statement_timeout do - TOP_LEVEL_ROUTES.each { |route| rename_root_paths(route) } - PROJECT_WILDCARD_ROUTES.each { |route| rename_wildcard_paths(route) } - GROUP_ROUTES.each { |route| rename_child_paths(route) } - end - end - - def down - disable_statement_timeout do - revert_renames - end - end -end diff --git a/db/post_migrate/20170526185842_migrate_pipeline_stages.rb b/db/post_migrate/20170526185842_migrate_pipeline_stages.rb deleted file mode 100644 index 53743fc16e6..00000000000 --- a/db/post_migrate/20170526185842_migrate_pipeline_stages.rb +++ /dev/null @@ -1,22 +0,0 @@ -class MigratePipelineStages < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - disable_statement_timeout do - execute <<-SQL.strip_heredoc - INSERT INTO ci_stages (project_id, pipeline_id, name) - SELECT project_id, commit_id, stage FROM ci_builds - WHERE stage IS NOT NULL - AND stage_id IS NULL - AND EXISTS (SELECT 1 FROM projects WHERE projects.id = ci_builds.project_id) - AND EXISTS (SELECT 1 FROM ci_pipelines WHERE ci_pipelines.id = ci_builds.commit_id) - GROUP BY project_id, commit_id, stage - ORDER BY MAX(stage_idx) - SQL - end - end -end diff --git a/db/post_migrate/20170526185858_create_index_in_pipeline_stages.rb b/db/post_migrate/20170526185858_create_index_in_pipeline_stages.rb deleted file mode 100644 index dc7b1d6d026..00000000000 --- a/db/post_migrate/20170526185858_create_index_in_pipeline_stages.rb +++ /dev/null @@ -1,15 +0,0 @@ -class CreateIndexInPipelineStages < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - add_concurrent_index(:ci_stages, [:pipeline_id, :name]) - end - - def down - remove_concurrent_index(:ci_stages, [:pipeline_id, :name]) - end -end diff --git a/db/post_migrate/20170526185901_remove_stage_id_index_from_builds.rb b/db/post_migrate/20170526185901_remove_stage_id_index_from_builds.rb deleted file mode 100644 index de473e7bb91..00000000000 --- a/db/post_migrate/20170526185901_remove_stage_id_index_from_builds.rb +++ /dev/null @@ -1,18 +0,0 @@ -class RemoveStageIdIndexFromBuilds < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - if index_exists?(:ci_builds, :stage_id) - remove_foreign_key(:ci_builds, column: :stage_id) - remove_concurrent_index(:ci_builds, :stage_id) - end - end - - def down - # noop - end -end diff --git a/db/post_migrate/20170526185921_migrate_build_stage_reference.rb b/db/post_migrate/20170526185921_migrate_build_stage_reference.rb deleted file mode 100644 index a9b392314fa..00000000000 --- a/db/post_migrate/20170526185921_migrate_build_stage_reference.rb +++ /dev/null @@ -1,19 +0,0 @@ -class MigrateBuildStageReference < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - ## - # This is an empty migration, content has been moved to a new one: - # post migrate 20170526190000 MigrateBuildStageReferenceAgain - # - # See gitlab-org/gitlab-ce!12337 for more details. - - def up - # noop - end - - def down - # noop - end -end diff --git a/db/post_migrate/20170526190000_migrate_build_stage_reference_again.rb b/db/post_migrate/20170526190000_migrate_build_stage_reference_again.rb deleted file mode 100644 index 01b6cf3a158..00000000000 --- a/db/post_migrate/20170526190000_migrate_build_stage_reference_again.rb +++ /dev/null @@ -1,28 +0,0 @@ -# rubocop:disable Migration/UpdateLargeTable -class MigrateBuildStageReferenceAgain < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - stage_id = Arel.sql <<-SQL.strip_heredoc - (SELECT id FROM ci_stages - WHERE ci_stages.pipeline_id = ci_builds.commit_id - AND ci_stages.name = ci_builds.stage) - SQL - - disable_statement_timeout do - update_column_in_batches(:ci_builds, :stage_id, stage_id) do |table, query| - query.where(table[:stage_id].eq(nil)) - end - end - end - - def down - disable_statement_timeout do - update_column_in_batches(:ci_builds, :stage_id, nil) - end - end -end diff --git a/db/post_migrate/20170531203055_cleanup_users_ldap_email_rename.rb b/db/post_migrate/20170531203055_cleanup_users_ldap_email_rename.rb deleted file mode 100644 index 3d75c7e3eaf..00000000000 --- a/db/post_migrate/20170531203055_cleanup_users_ldap_email_rename.rb +++ /dev/null @@ -1,16 +0,0 @@ -class CleanupUsersLdapEmailRename < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - cleanup_concurrent_column_rename :users, :ldap_email, :external_email - end - - def down - # rubocop:disable Migration/UpdateLargeTable - rename_column_concurrently :users, :external_email, :ldap_email - end -end diff --git a/db/post_migrate/20170606202615_move_appearance_to_system_dir.rb b/db/post_migrate/20170606202615_move_appearance_to_system_dir.rb deleted file mode 100644 index fb9ac8d6daf..00000000000 --- a/db/post_migrate/20170606202615_move_appearance_to_system_dir.rb +++ /dev/null @@ -1,57 +0,0 @@ -class MoveAppearanceToSystemDir < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - disable_ddl_transaction! - - DOWNTIME = false - DIRECTORY_TO_MOVE = 'appearance'.freeze - - def up - source = File.join(old_upload_dir, DIRECTORY_TO_MOVE) - destination = File.join(new_upload_dir, DIRECTORY_TO_MOVE) - - move_directory(source, destination) - end - - def down - source = File.join(new_upload_dir, DIRECTORY_TO_MOVE) - destination = File.join(old_upload_dir, DIRECTORY_TO_MOVE) - - move_directory(source, destination) - end - - def move_directory(source, destination) - unless file_storage? - say 'Not using file storage, skipping' - return - end - - unless File.directory?(source) - say "#{source} did not exist, skipping" - return - end - - if File.directory?(destination) - say "#{destination} already existed, skipping" - return - end - - say "Moving #{source} -> #{destination}" - FileUtils.mv(source, destination) - end - - def file_storage? - CarrierWave::Uploader::Base.storage == CarrierWave::Storage::File - end - - def base_directory - Rails.root - end - - def old_upload_dir - File.join(base_directory, "public", "uploads") - end - - def new_upload_dir - File.join(base_directory, "public", "uploads", "-", "system") - end -end diff --git a/db/post_migrate/20170607121233_convert_custom_notification_settings_to_columns.rb b/db/post_migrate/20170607121233_convert_custom_notification_settings_to_columns.rb deleted file mode 100644 index 8ff26130cba..00000000000 --- a/db/post_migrate/20170607121233_convert_custom_notification_settings_to_columns.rb +++ /dev/null @@ -1,55 +0,0 @@ -class ConvertCustomNotificationSettingsToColumns < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - class NotificationSetting < ActiveRecord::Base - self.table_name = 'notification_settings' - - store :events, coder: JSON - end - - EMAIL_EVENTS = [ - :new_note, - :new_issue, - :reopen_issue, - :close_issue, - :reassign_issue, - :new_merge_request, - :reopen_merge_request, - :close_merge_request, - :reassign_merge_request, - :merge_merge_request, - :failed_pipeline, - :success_pipeline - ] - - # We only need to migrate (up or down) rows where at least one of these - # settings is set. - def up - NotificationSetting.where("events LIKE '%true%'").find_each do |notification_setting| - EMAIL_EVENTS.each do |event| - notification_setting[event] = notification_setting.events[event] - end - - notification_setting[:events] = nil - notification_setting.save! - end - end - - def down - NotificationSetting.where(EMAIL_EVENTS.join(' OR ')).find_each do |notification_setting| - events = {} - - EMAIL_EVENTS.each do |event| - events[event] = !!notification_setting.public_send(event) - notification_setting[event] = nil - end - - notification_setting[:events] = events - notification_setting.save! - end - end -end diff --git a/db/post_migrate/20170609183112_remove_position_from_issuables.rb b/db/post_migrate/20170609183112_remove_position_from_issuables.rb deleted file mode 100644 index edad0a502b4..00000000000 --- a/db/post_migrate/20170609183112_remove_position_from_issuables.rb +++ /dev/null @@ -1,8 +0,0 @@ -class RemovePositionFromIssuables < ActiveRecord::Migration[4.2] - DOWNTIME = false - - def change - remove_column :issues, :position, :integer - remove_column :merge_requests, :position, :integer - end -end diff --git a/db/post_migrate/20170612071012_move_personal_snippets_files.rb b/db/post_migrate/20170612071012_move_personal_snippets_files.rb deleted file mode 100644 index d32d92637fa..00000000000 --- a/db/post_migrate/20170612071012_move_personal_snippets_files.rb +++ /dev/null @@ -1,92 +0,0 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. -class MovePersonalSnippetsFiles < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - disable_ddl_transaction! - - DOWNTIME = false - - def up - return unless file_storage? - - @source_relative_location = File.join('/uploads', 'personal_snippet') - @destination_relative_location = File.join('/uploads', '-', 'system', 'personal_snippet') - - move_personal_snippet_files - end - - def down - return unless file_storage? - - @source_relative_location = File.join('/uploads', '-', 'system', 'personal_snippet') - @destination_relative_location = File.join('/uploads', 'personal_snippet') - - move_personal_snippet_files - end - - def move_personal_snippet_files - query = "SELECT uploads.path, uploads.model_id, snippets.description FROM uploads "\ - "INNER JOIN snippets ON snippets.id = uploads.model_id WHERE uploader = 'PersonalFileUploader'" - select_all(query).each do |upload| - secret = upload['path'].split('/')[0] - file_name = upload['path'].split('/')[1] - - next unless move_file(upload['model_id'], secret, file_name) - - update_markdown(upload['model_id'], secret, file_name, upload['description']) - end - end - - def move_file(snippet_id, secret, file_name) - source_dir = File.join(base_directory, @source_relative_location, snippet_id.to_s, secret) - destination_dir = File.join(base_directory, @destination_relative_location, snippet_id.to_s, secret) - - source_file_path = File.join(source_dir, file_name) - destination_file_path = File.join(destination_dir, file_name) - - unless File.exist?(source_file_path) - say "Source file `#{source_file_path}` doesn't exist. Skipping." - return - end - - say "Moving file #{source_file_path} -> #{destination_file_path}" - - FileUtils.mkdir_p(destination_dir) - FileUtils.move(source_file_path, destination_file_path) - - true - end - - def update_markdown(snippet_id, secret, file_name, description) - source_markdown_path = File.join(@source_relative_location, snippet_id.to_s, secret, file_name) - destination_markdown_path = File.join(@destination_relative_location, snippet_id.to_s, secret, file_name) - - source_markdown = "](#{source_markdown_path})" - destination_markdown = "](#{destination_markdown_path})" - - if description.present? - description = description.gsub(source_markdown, destination_markdown) - quoted_description = quote_string(description) - - execute("UPDATE snippets SET description = '#{quoted_description}', description_html = NULL "\ - "WHERE id = #{snippet_id}") - end - - query = "SELECT id, note FROM notes WHERE noteable_id = #{snippet_id} "\ - "AND noteable_type = 'Snippet' AND note IS NOT NULL" - select_all(query).each do |note| - text = note['note'].gsub(source_markdown, destination_markdown) - quoted_text = quote_string(text) - - execute("UPDATE notes SET note = '#{quoted_text}', note_html = NULL WHERE id = #{note['id']}") - end - end - - def base_directory - File.join(Rails.root, 'public') - end - - def file_storage? - CarrierWave::Uploader::Base.storage == CarrierWave::Storage::File - end -end diff --git a/db/post_migrate/20170613111224_clean_appearance_symlinks.rb b/db/post_migrate/20170613111224_clean_appearance_symlinks.rb deleted file mode 100644 index 14511bff3db..00000000000 --- a/db/post_migrate/20170613111224_clean_appearance_symlinks.rb +++ /dev/null @@ -1,53 +0,0 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class CleanAppearanceSymlinks < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - disable_ddl_transaction! - - DOWNTIME = false - - def up - return unless file_storage? - - symlink_location = File.join(old_upload_dir, dir) - - return unless File.symlink?(symlink_location) - - say "removing symlink: #{symlink_location}" - FileUtils.rm(symlink_location) - end - - def down - return unless file_storage? - - symlink = File.join(old_upload_dir, dir) - destination = File.join(new_upload_dir, dir) - - return if File.directory?(symlink) - return unless File.directory?(destination) - - say "Creating symlink #{symlink} -> #{destination}" - FileUtils.ln_s(destination, symlink) - end - - def file_storage? - CarrierWave::Uploader::Base.storage == CarrierWave::Storage::File - end - - def dir - 'appearance' - end - - def base_directory - Rails.root - end - - def old_upload_dir - File.join(base_directory, "public", "uploads") - end - - def new_upload_dir - File.join(base_directory, "public", "uploads", "system") - end -end diff --git a/db/post_migrate/20170621102400_add_stage_id_index_to_builds.rb b/db/post_migrate/20170621102400_add_stage_id_index_to_builds.rb deleted file mode 100644 index cca9b488547..00000000000 --- a/db/post_migrate/20170621102400_add_stage_id_index_to_builds.rb +++ /dev/null @@ -1,17 +0,0 @@ -class AddStageIdIndexToBuilds < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - ## - # Improved in 20170703102400_add_stage_id_foreign_key_to_builds.rb - # - - def up - # noop - end - - def down - # noop - end -end diff --git a/db/post_migrate/20170627101016_schedule_event_migrations.rb b/db/post_migrate/20170627101016_schedule_event_migrations.rb deleted file mode 100644 index f026a86bc0f..00000000000 --- a/db/post_migrate/20170627101016_schedule_event_migrations.rb +++ /dev/null @@ -1,40 +0,0 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class ScheduleEventMigrations < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - BUFFER_SIZE = 1000 - - disable_ddl_transaction! - - class Event < ActiveRecord::Base - include EachBatch - - self.table_name = 'events' - end - - def up - jobs = [] - - Event.each_batch(of: 1000) do |relation| - min, max = relation.pluck('MIN(id), MAX(id)').first - - if jobs.length == BUFFER_SIZE - # We push multiple jobs at a time to reduce the time spent in - # Sidekiq/Redis operations. We're using this buffer based approach so we - # don't need to run additional queries for every range. - BackgroundMigrationWorker.bulk_perform_async(jobs) - jobs.clear - end - - jobs << ['MigrateEventsToPushEventPayloads', [min, max]] - end - - BackgroundMigrationWorker.bulk_perform_async(jobs) unless jobs.empty? - end - - def down - end -end diff --git a/db/post_migrate/20170628080858_migrate_stage_id_reference_in_background.rb b/db/post_migrate/20170628080858_migrate_stage_id_reference_in_background.rb deleted file mode 100644 index 36aac3df071..00000000000 --- a/db/post_migrate/20170628080858_migrate_stage_id_reference_in_background.rb +++ /dev/null @@ -1,33 +0,0 @@ -class MigrateStageIdReferenceInBackground < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - BATCH_SIZE = 10000 - RANGE_SIZE = 1000 - MIGRATION = 'MigrateBuildStageIdReference'.freeze - - disable_ddl_transaction! - - class Build < ActiveRecord::Base - self.table_name = 'ci_builds' - include ::EachBatch - end - - ## - # It will take around 3 days to process 20M ci_builds. - # - def up - Build.where(stage_id: nil).each_batch(of: BATCH_SIZE) do |relation, index| - relation.each_batch(of: RANGE_SIZE) do |relation| - range = relation.pluck('MIN(id)', 'MAX(id)').first - - BackgroundMigrationWorker - .perform_in(index * 2.minutes, MIGRATION, range) - end - end - end - - def down - # noop - end -end diff --git a/db/post_migrate/20170629180131_cleanup_application_settings_signin_enabled_rename.rb b/db/post_migrate/20170629180131_cleanup_application_settings_signin_enabled_rename.rb deleted file mode 100644 index 87268fb4b31..00000000000 --- a/db/post_migrate/20170629180131_cleanup_application_settings_signin_enabled_rename.rb +++ /dev/null @@ -1,15 +0,0 @@ -class CleanupApplicationSettingsSigninEnabledRename < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - cleanup_concurrent_column_rename :application_settings, :signin_enabled, :password_authentication_enabled - end - - def down - rename_column_concurrently :application_settings, :password_authentication_enabled, :signin_enabled - end -end diff --git a/db/post_migrate/20170711145558_migrate_stages_statuses.rb b/db/post_migrate/20170711145558_migrate_stages_statuses.rb deleted file mode 100644 index 8ba69ea4dce..00000000000 --- a/db/post_migrate/20170711145558_migrate_stages_statuses.rb +++ /dev/null @@ -1,34 +0,0 @@ -class MigrateStagesStatuses < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - BATCH_SIZE = 10000 - RANGE_SIZE = 100 - MIGRATION = 'MigrateStageStatus'.freeze - - class Stage < ActiveRecord::Base - self.table_name = 'ci_stages' - include ::EachBatch - end - - def up - Stage.where(status: nil).each_batch(of: BATCH_SIZE) do |relation, index| - relation.each_batch(of: RANGE_SIZE) do |batch| - range = batch.pluck('MIN(id)', 'MAX(id)').first - delay = index * 5.minutes - - BackgroundMigrationWorker.perform_in(delay, MIGRATION, range) - end - end - end - - def down - disable_statement_timeout do - # rubocop:disable Migration/UpdateLargeTable - update_column_in_batches(:ci_stages, :status, nil) - end - end -end diff --git a/db/post_migrate/20170717111152_cleanup_move_system_upload_folder_symlink.rb b/db/post_migrate/20170717111152_cleanup_move_system_upload_folder_symlink.rb deleted file mode 100644 index 392c4f71532..00000000000 --- a/db/post_migrate/20170717111152_cleanup_move_system_upload_folder_symlink.rb +++ /dev/null @@ -1,40 +0,0 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class CleanupMoveSystemUploadFolderSymlink < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - if File.symlink?(old_directory) - say "Removing #{old_directory} -> #{new_directory} symlink" - FileUtils.rm(old_directory) - else - say "Symlink #{old_directory} non existent, nothing to do." - end - end - - def down - if File.directory?(new_directory) - say "Symlinking #{old_directory} -> #{new_directory}" - FileUtils.ln_s(new_directory, old_directory) unless File.exist?(old_directory) - else - say "#{new_directory} doesn't exist, skipping." - end - end - - def new_directory - File.join(base_directory, '-', 'system') - end - - def old_directory - File.join(base_directory, 'system') - end - - def base_directory - File.join(Rails.root, 'public', 'uploads') - end -end diff --git a/db/post_migrate/20170717150329_enqueue_migrate_system_uploads_to_new_folder.rb b/db/post_migrate/20170717150329_enqueue_migrate_system_uploads_to_new_folder.rb deleted file mode 100644 index fdd990ae2e5..00000000000 --- a/db/post_migrate/20170717150329_enqueue_migrate_system_uploads_to_new_folder.rb +++ /dev/null @@ -1,20 +0,0 @@ -class EnqueueMigrateSystemUploadsToNewFolder < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - OLD_FOLDER = 'uploads/system/' - NEW_FOLDER = 'uploads/-/system/' - - disable_ddl_transaction! - - def up - BackgroundMigrationWorker.perform_async('MigrateSystemUploadsToNewFolder', - [OLD_FOLDER, NEW_FOLDER]) - end - - def down - BackgroundMigrationWorker.perform_async('MigrateSystemUploadsToNewFolder', - [NEW_FOLDER, OLD_FOLDER]) - end -end diff --git a/db/post_migrate/20170719150301_merge_issuable_reopened_into_opened_state.rb b/db/post_migrate/20170719150301_merge_issuable_reopened_into_opened_state.rb deleted file mode 100644 index 7af1d04f0cc..00000000000 --- a/db/post_migrate/20170719150301_merge_issuable_reopened_into_opened_state.rb +++ /dev/null @@ -1,32 +0,0 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class MergeIssuableReopenedIntoOpenedState < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - class Issue < ActiveRecord::Base - self.table_name = 'issues' - - include EachBatch - end - - class MergeRequest < ActiveRecord::Base - self.table_name = 'merge_requests' - - include EachBatch - end - - def up - [Issue, MergeRequest].each do |model| - say "Changing #{model.table_name}.state from 'reopened' to 'opened'" - - model.where(state: 'reopened').each_batch do |batch| - batch.update_all(state: 'opened') - end - end - end -end diff --git a/db/post_migrate/20170728101014_remove_events_from_notification_settings.rb b/db/post_migrate/20170728101014_remove_events_from_notification_settings.rb deleted file mode 100644 index f1b0a1daec5..00000000000 --- a/db/post_migrate/20170728101014_remove_events_from_notification_settings.rb +++ /dev/null @@ -1,9 +0,0 @@ -class RemoveEventsFromNotificationSettings < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def change - remove_column :notification_settings, :events, :text - end -end diff --git a/db/post_migrate/20170803090603_calculate_conv_dev_index_percentages.rb b/db/post_migrate/20170803090603_calculate_conv_dev_index_percentages.rb deleted file mode 100644 index a148586ca89..00000000000 --- a/db/post_migrate/20170803090603_calculate_conv_dev_index_percentages.rb +++ /dev/null @@ -1,30 +0,0 @@ -class CalculateConvDevIndexPercentages < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - DOWNTIME = false - - class ConversationalDevelopmentIndexMetric < ActiveRecord::Base - self.table_name = 'conversational_development_index_metrics' - - METRICS = %w[boards ci_pipelines deployments environments issues merge_requests milestones notes - projects_prometheus_active service_desk_issues] - end - - def up - ConversationalDevelopmentIndexMetric.find_each do |conv_dev_index| - update = [] - - ConversationalDevelopmentIndexMetric::METRICS.each do |metric| - instance_score = conv_dev_index["instance_#{metric}"].to_f - leader_score = conv_dev_index["leader_#{metric}"].to_f - - percentage = leader_score.zero? ? 0.0 : (instance_score / leader_score) * 100 - update << "percentage_#{metric} = '#{percentage}'" - end - - execute("UPDATE conversational_development_index_metrics SET #{update.join(',')} WHERE id = #{conv_dev_index.id}") - end - end - - def down - end -end diff --git a/db/post_migrate/20170807160457_remove_locked_at_column_from_merge_requests.rb b/db/post_migrate/20170807160457_remove_locked_at_column_from_merge_requests.rb deleted file mode 100644 index 6dc49211e5a..00000000000 --- a/db/post_migrate/20170807160457_remove_locked_at_column_from_merge_requests.rb +++ /dev/null @@ -1,11 +0,0 @@ -class RemoveLockedAtColumnFromMergeRequests < ActiveRecord::Migration[4.2] - DOWNTIME = false - - def up - remove_column :merge_requests, :locked_at - end - - def down - add_column :merge_requests, :locked_at, :datetime_with_timezone - end -end diff --git a/db/post_migrate/20170807190736_move_personal_snippet_files_into_correct_folder.rb b/db/post_migrate/20170807190736_move_personal_snippet_files_into_correct_folder.rb deleted file mode 100644 index 8341ac39c25..00000000000 --- a/db/post_migrate/20170807190736_move_personal_snippet_files_into_correct_folder.rb +++ /dev/null @@ -1,29 +0,0 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class MovePersonalSnippetFilesIntoCorrectFolder < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - disable_ddl_transaction! - - DOWNTIME = false - NEW_DIRECTORY = File.join('/uploads', '-', 'system', 'personal_snippet') - OLD_DIRECTORY = File.join('/uploads', 'system', 'personal_snippet') - - def up - return unless file_storage? - - BackgroundMigrationWorker.perform_async('MovePersonalSnippetFiles', - [OLD_DIRECTORY, NEW_DIRECTORY]) - end - - def down - return unless file_storage? - - BackgroundMigrationWorker.perform_async('MovePersonalSnippetFiles', - [NEW_DIRECTORY, OLD_DIRECTORY]) - end - - def file_storage? - CarrierWave::Uploader::Base.storage == CarrierWave::Storage::File - end -end diff --git a/db/post_migrate/20170815060945_remove_duplicate_mr_events.rb b/db/post_migrate/20170815060945_remove_duplicate_mr_events.rb deleted file mode 100644 index fdc126b8fd6..00000000000 --- a/db/post_migrate/20170815060945_remove_duplicate_mr_events.rb +++ /dev/null @@ -1,26 +0,0 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class RemoveDuplicateMrEvents < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - DOWNTIME = false - - class Event < ActiveRecord::Base - self.table_name = 'events' - end - - def up - base_condition = "action = 1 AND target_type = 'MergeRequest' AND created_at > '2017-08-13'" - Event.select('target_id, count(*)') - .where(base_condition) - .group('target_id').having('count(*) > 1').each do |event| - duplicates = Event.where("#{base_condition} AND target_id = #{event.target_id}").pluck(:id) - duplicates.shift - - Event.where(id: duplicates).delete_all - end - end - - def down - end -end diff --git a/db/post_migrate/20170816102555_cleanup_nonexisting_namespace_pending_delete_projects.rb b/db/post_migrate/20170816102555_cleanup_nonexisting_namespace_pending_delete_projects.rb deleted file mode 100644 index 27656fd926d..00000000000 --- a/db/post_migrate/20170816102555_cleanup_nonexisting_namespace_pending_delete_projects.rb +++ /dev/null @@ -1,54 +0,0 @@ -# Follow up of CleanupNamespacelessPendingDeleteProjects and it cleans -# all projects with `pending_delete = true` and for which the -# namespace no longer exists. -class CleanupNonexistingNamespacePendingDeleteProjects < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - class Project < ActiveRecord::Base - self.table_name = 'projects' - - include ::EachBatch - end - - class Namespace < ActiveRecord::Base - self.table_name = 'namespaces' - end - - def up - find_projects.each_batch do |batch| - args = batch.pluck(:id).map { |id| [id] } - - NamespacelessProjectDestroyWorker.bulk_perform_async(args) - end - end - - def down - # NOOP - end - - private - - def find_projects - projects = Project.arel_table - namespaces = Namespace.arel_table - - namespace_query = namespaces.project(1) - .where(namespaces[:id].eq(projects[:namespace_id])) - .exists.not - - # SELECT "projects"."id" - # FROM "projects" - # WHERE "projects"."pending_delete" = 't' - # AND (NOT (EXISTS - # (SELECT 1 - # FROM "namespaces" - # WHERE "namespaces"."id" = "projects"."namespace_id"))) - Project.where(projects[:pending_delete].eq(true)) - .where(namespace_query) - .select(:id) - end -end diff --git a/db/post_migrate/20170822101017_migrate_pipeline_sidekiq_queues.rb b/db/post_migrate/20170822101017_migrate_pipeline_sidekiq_queues.rb deleted file mode 100644 index 825bc9250bd..00000000000 --- a/db/post_migrate/20170822101017_migrate_pipeline_sidekiq_queues.rb +++ /dev/null @@ -1,17 +0,0 @@ -class MigratePipelineSidekiqQueues < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def up - sidekiq_queue_migrate 'build', to: 'pipeline_default' - sidekiq_queue_migrate 'pipeline', to: 'pipeline_default' - end - - def down - sidekiq_queue_migrate 'pipeline_default', to: 'pipeline' - sidekiq_queue_migrate 'pipeline_processing', to: 'pipeline' - sidekiq_queue_migrate 'pipeline_hooks', to: 'pipeline' - sidekiq_queue_migrate 'pipeline_cache', to: 'pipeline' - end -end diff --git a/db/post_migrate/20170828170502_post_deploy_migrate_user_external_mail_data.rb b/db/post_migrate/20170828170502_post_deploy_migrate_user_external_mail_data.rb deleted file mode 100644 index 533155aeb7a..00000000000 --- a/db/post_migrate/20170828170502_post_deploy_migrate_user_external_mail_data.rb +++ /dev/null @@ -1,57 +0,0 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class PostDeployMigrateUserExternalMailData < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - class User < ActiveRecord::Base - self.table_name = 'users' - - include EachBatch - end - - class UserSyncedAttributesMetadata < ActiveRecord::Base - self.table_name = 'user_synced_attributes_metadata' - - include EachBatch - end - - def up - User.each_batch do |batch| - start_id, end_id = batch.pluck('MIN(id), MAX(id)').first - - execute <<-EOF - INSERT INTO user_synced_attributes_metadata (user_id, provider, email_synced) - SELECT id, email_provider, external_email - FROM users - WHERE external_email = TRUE - AND NOT EXISTS ( - SELECT true - FROM user_synced_attributes_metadata - WHERE user_id = users.id - AND (provider = users.email_provider OR (provider IS NULL AND users.email_provider IS NULL)) - ) - AND id BETWEEN #{start_id} AND #{end_id} - EOF - end - end - - def down - UserSyncedAttributesMetadata.each_batch do |batch| - start_id, end_id = batch.pluck('MIN(id), MAX(id)').first - - execute <<-EOF - UPDATE users - SET users.email_provider = metadata.provider, users.external_email = metadata.email_synced - FROM user_synced_attributes_metadata as metadata, users - WHERE metadata.email_synced = TRUE - AND metadata.user_id = users.id - AND id BETWEEN #{start_id} AND #{end_id} - EOF - end - end -end diff --git a/db/post_migrate/20170828170513_remove_user_email_provider_column.rb b/db/post_migrate/20170828170513_remove_user_email_provider_column.rb deleted file mode 100644 index bfc8aede540..00000000000 --- a/db/post_migrate/20170828170513_remove_user_email_provider_column.rb +++ /dev/null @@ -1,12 +0,0 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class RemoveUserEmailProviderColumn < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def change - remove_column :users, :email_provider, :string - end -end diff --git a/db/post_migrate/20170828170516_remove_user_external_mail_columns.rb b/db/post_migrate/20170828170516_remove_user_external_mail_columns.rb deleted file mode 100644 index 0104955e5c8..00000000000 --- a/db/post_migrate/20170828170516_remove_user_external_mail_columns.rb +++ /dev/null @@ -1,12 +0,0 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class RemoveUserExternalMailColumns < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def change - remove_column :users, :external_email, :boolean - end -end diff --git a/db/post_migrate/20170830084744_destroy_gpg_signatures.rb b/db/post_migrate/20170830084744_destroy_gpg_signatures.rb deleted file mode 100644 index 2945eb9fde6..00000000000 --- a/db/post_migrate/20170830084744_destroy_gpg_signatures.rb +++ /dev/null @@ -1,10 +0,0 @@ -class DestroyGpgSignatures < ActiveRecord::Migration[4.2] - DOWNTIME = false - - def up - truncate(:gpg_signatures) - end - - def down - end -end diff --git a/db/post_migrate/20170830150306_drop_events_for_migration_table.rb b/db/post_migrate/20170830150306_drop_events_for_migration_table.rb deleted file mode 100644 index 3538b52b004..00000000000 --- a/db/post_migrate/20170830150306_drop_events_for_migration_table.rb +++ /dev/null @@ -1,47 +0,0 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class DropEventsForMigrationTable < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - class Event < ActiveRecord::Base - include EachBatch - end - - def up - transaction do - drop_table :events_for_migration - end - end - - def down - create_table :events_for_migration do |t| - t.string :target_type, index: true - t.integer :target_id, index: true - t.string :title - t.text :data - t.integer :project_id - t.datetime :created_at, index: true - t.datetime :updated_at - t.integer :action, index: true - t.integer :author_id, index: true - - t.index [:project_id, :id] - end - - Event.all.each_batch do |relation| - start_id, stop_id = relation.pluck('MIN(id), MAX(id)').first - - execute <<-EOF.strip_heredoc - INSERT INTO events_for_migration (target_type, target_id, project_id, created_at, updated_at, action, author_id) - SELECT target_type, target_id, project_id, created_at, updated_at, action, author_id - FROM events - WHERE id BETWEEN #{start_id} AND #{stop_id} - EOF - end - end -end diff --git a/db/post_migrate/20170831195038_remove_valid_signature_from_gpg_signatures.rb b/db/post_migrate/20170831195038_remove_valid_signature_from_gpg_signatures.rb deleted file mode 100644 index 8e264c1ab41..00000000000 --- a/db/post_migrate/20170831195038_remove_valid_signature_from_gpg_signatures.rb +++ /dev/null @@ -1,11 +0,0 @@ -class RemoveValidSignatureFromGpgSignatures < ActiveRecord::Migration[4.2] - DOWNTIME = false - - def up - remove_column :gpg_signatures, :valid_signature - end - - def down - add_column :gpg_signatures, :valid_signature, :boolean - end -end diff --git a/db/post_migrate/20170907170235_delete_conflicting_redirect_routes.rb b/db/post_migrate/20170907170235_delete_conflicting_redirect_routes.rb deleted file mode 100644 index 95abf2474dd..00000000000 --- a/db/post_migrate/20170907170235_delete_conflicting_redirect_routes.rb +++ /dev/null @@ -1,13 +0,0 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class DeleteConflictingRedirectRoutes < ActiveRecord::Migration[4.2] - def up - # No-op. - # See https://gitlab.com/gitlab-com/infrastructure/issues/3460#note_53223252 - end - - def down - # nothing - end -end diff --git a/db/post_migrate/20170913180600_fix_projects_without_project_feature.rb b/db/post_migrate/20170913180600_fix_projects_without_project_feature.rb deleted file mode 100644 index bbc624ac7c0..00000000000 --- a/db/post_migrate/20170913180600_fix_projects_without_project_feature.rb +++ /dev/null @@ -1,33 +0,0 @@ -class FixProjectsWithoutProjectFeature < ActiveRecord::Migration[4.2] - DOWNTIME = false - - def up - # Deletes corrupted project features - sql = "DELETE FROM project_features WHERE project_id IS NULL" - execute(sql) - - # Creates missing project features with private visibility - sql = - %Q{ - INSERT INTO project_features(project_id, repository_access_level, issues_access_level, merge_requests_access_level, wiki_access_level, - builds_access_level, snippets_access_level, created_at, updated_at) - SELECT projects.id as project_id, - 10 as repository_access_level, - 10 as issues_access_level, - 10 as merge_requests_access_level, - 10 as wiki_access_level, - 10 as builds_access_level , - 10 as snippets_access_level, - projects.created_at, - projects.updated_at - FROM projects - LEFT OUTER JOIN project_features ON project_features.project_id = projects.id - WHERE (project_features.id IS NULL) - } - - execute(sql) - end - - def down - end -end diff --git a/db/post_migrate/20170921101004_normalize_ldap_extern_uids.rb b/db/post_migrate/20170921101004_normalize_ldap_extern_uids.rb deleted file mode 100644 index 9080acee1d6..00000000000 --- a/db/post_migrate/20170921101004_normalize_ldap_extern_uids.rb +++ /dev/null @@ -1,29 +0,0 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class NormalizeLdapExternUids < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - MIGRATION = 'NormalizeLdapExternUidsRange'.freeze - DELAY_INTERVAL = 10.seconds - - disable_ddl_transaction! - - class Identity < ActiveRecord::Base - include EachBatch - - self.table_name = 'identities' - end - - def up - ldap_identities = Identity.where("provider like 'ldap%'") - - if ldap_identities.any? - queue_background_migration_jobs_by_range_at_intervals(Identity, MIGRATION, DELAY_INTERVAL) - end - end - - def down - end -end diff --git a/db/post_migrate/20170927112318_update_legacy_diff_notes_type_for_import.rb b/db/post_migrate/20170927112318_update_legacy_diff_notes_type_for_import.rb deleted file mode 100644 index 83c21c203e0..00000000000 --- a/db/post_migrate/20170927112318_update_legacy_diff_notes_type_for_import.rb +++ /dev/null @@ -1,17 +0,0 @@ -# rubocop:disable Migration/UpdateLargeTable -class UpdateLegacyDiffNotesTypeForImport < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - update_column_in_batches(:notes, :type, 'LegacyDiffNote') do |table, query| - query.where(table[:type].eq('Github::Import::LegacyDiffNote')) - end - end - - def down - end -end diff --git a/db/post_migrate/20170927112319_update_notes_type_for_import.rb b/db/post_migrate/20170927112319_update_notes_type_for_import.rb deleted file mode 100644 index 8c691de3192..00000000000 --- a/db/post_migrate/20170927112319_update_notes_type_for_import.rb +++ /dev/null @@ -1,17 +0,0 @@ -# rubocop:disable Migration/UpdateLargeTable -class UpdateNotesTypeForImport < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - update_column_in_batches(:notes, :type, 'Note') do |table, query| - query.where(table[:type].eq('Github::Import::Note')) - end - end - - def down - end -end diff --git a/db/post_migrate/20171012150314_remove_user_authentication_token.rb b/db/post_migrate/20171012150314_remove_user_authentication_token.rb deleted file mode 100644 index 9313986ce85..00000000000 --- a/db/post_migrate/20171012150314_remove_user_authentication_token.rb +++ /dev/null @@ -1,20 +0,0 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class RemoveUserAuthenticationToken < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - remove_column :users, :authentication_token - end - - def down - add_column :users, :authentication_token, :string - - add_concurrent_index :users, :authentication_token, unique: true - end -end diff --git a/db/post_migrate/20171013104327_migrate_gcp_clusters_to_new_clusters_architectures.rb b/db/post_migrate/20171013104327_migrate_gcp_clusters_to_new_clusters_architectures.rb deleted file mode 100644 index 9c90aa611a4..00000000000 --- a/db/post_migrate/20171013104327_migrate_gcp_clusters_to_new_clusters_architectures.rb +++ /dev/null @@ -1,98 +0,0 @@ -class MigrateGcpClustersToNewClustersArchitectures < ActiveRecord::Migration[4.2] - DOWNTIME = false - - class GcpCluster < ActiveRecord::Base - self.table_name = 'gcp_clusters' - - belongs_to :project, class_name: 'Project' - - include EachBatch - end - - class Cluster < ActiveRecord::Base - self.table_name = 'clusters' - - has_many :cluster_projects, class_name: 'ClustersProject' - has_many :projects, through: :cluster_projects, class_name: 'Project' - has_one :provider_gcp, class_name: 'ProvidersGcp' - has_one :platform_kubernetes, class_name: 'PlatformsKubernetes' - - accepts_nested_attributes_for :provider_gcp - accepts_nested_attributes_for :platform_kubernetes - - enum platform_type: { - kubernetes: 1 - } - - enum provider_type: { - user: 0, - gcp: 1 - } - end - - class Project < ActiveRecord::Base - self.table_name = 'projects' - - has_one :cluster_project, class_name: 'ClustersProject' - has_one :cluster, through: :cluster_project, class_name: 'Cluster' - end - - class ClustersProject < ActiveRecord::Base - self.table_name = 'cluster_projects' - - belongs_to :cluster, class_name: 'Cluster' - belongs_to :project, class_name: 'Project' - end - - class ProvidersGcp < ActiveRecord::Base - self.table_name = 'cluster_providers_gcp' - end - - class PlatformsKubernetes < ActiveRecord::Base - self.table_name = 'cluster_platforms_kubernetes' - end - - def up - GcpCluster.all.find_each(batch_size: 1) do |gcp_cluster| - Cluster.create( - enabled: gcp_cluster.enabled, - user_id: gcp_cluster.user_id, - name: gcp_cluster.gcp_cluster_name, - provider_type: Cluster.provider_types[:gcp], - platform_type: Cluster.platform_types[:kubernetes], - projects: [gcp_cluster.project], - provider_gcp_attributes: { - status: gcp_cluster.status, - status_reason: gcp_cluster.status_reason, - gcp_project_id: gcp_cluster.gcp_project_id, - zone: gcp_cluster.gcp_cluster_zone, - num_nodes: gcp_cluster.gcp_cluster_size, - machine_type: gcp_cluster.gcp_machine_type, - operation_id: gcp_cluster.gcp_operation_id, - endpoint: gcp_cluster.endpoint, - encrypted_access_token: gcp_cluster.encrypted_gcp_token, - encrypted_access_token_iv: gcp_cluster.encrypted_gcp_token_iv - }, - platform_kubernetes_attributes: { - api_url: api_url(gcp_cluster.endpoint), - ca_cert: gcp_cluster.ca_cert, - namespace: gcp_cluster.project_namespace, - username: gcp_cluster.username, - encrypted_password: gcp_cluster.encrypted_password, - encrypted_password_iv: gcp_cluster.encrypted_password_iv, - encrypted_token: gcp_cluster.encrypted_kubernetes_token, - encrypted_token_iv: gcp_cluster.encrypted_kubernetes_token_iv - } ) - end - end - - def down - execute('DELETE FROM clusters') - end - - private - - def api_url(endpoint) - endpoint ? 'https://' + endpoint : nil - end -end diff --git a/db/post_migrate/20171026082505_schedule_merge_request_latest_merge_request_diff_id_migrations.rb b/db/post_migrate/20171026082505_schedule_merge_request_latest_merge_request_diff_id_migrations.rb deleted file mode 100644 index 764561de997..00000000000 --- a/db/post_migrate/20171026082505_schedule_merge_request_latest_merge_request_diff_id_migrations.rb +++ /dev/null @@ -1,29 +0,0 @@ -class ScheduleMergeRequestLatestMergeRequestDiffIdMigrations < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - BATCH_SIZE = 50_000 - MIGRATION = 'PopulateMergeRequestsLatestMergeRequestDiffId' - - disable_ddl_transaction! - - class MergeRequest < ActiveRecord::Base - self.table_name = 'merge_requests' - - include ::EachBatch - end - - # On GitLab.com, we saw that we generated about 500,000 dead tuples over 5 minutes. - # To keep replication lag from ballooning, we'll aim for 50,000 updates over 5 minutes. - # - # Assuming that there are 5 million rows affected (which is more than on - # GitLab.com), and that each batch of 50,000 rows takes up to 5 minutes, then - # we can migrate all the rows in 8.5 hours. - def up - MergeRequest.where(latest_merge_request_diff_id: nil).each_batch(of: BATCH_SIZE) do |relation, index| - range = relation.pluck('MIN(id)', 'MAX(id)').first - - BackgroundMigrationWorker.perform_in(index * 5.minutes, MIGRATION, range) - end - end -end diff --git a/db/post_migrate/20171101134435_remove_ref_fetched_from_merge_requests.rb b/db/post_migrate/20171101134435_remove_ref_fetched_from_merge_requests.rb deleted file mode 100644 index e6a5ffc8649..00000000000 --- a/db/post_migrate/20171101134435_remove_ref_fetched_from_merge_requests.rb +++ /dev/null @@ -1,14 +0,0 @@ -class RemoveRefFetchedFromMergeRequests < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - # Set this constant to true if this migration requires downtime. - DOWNTIME = false - - # We don't need to cache this anymore: the refs are now created - # upon save/update and there is no more use for this flag - # - # See https://gitlab.com/gitlab-org/gitlab-ce/issues/36061 - def change - remove_column :merge_requests, :ref_fetched, :boolean - end -end diff --git a/db/post_migrate/20171103140253_track_untracked_uploads.rb b/db/post_migrate/20171103140253_track_untracked_uploads.rb deleted file mode 100644 index 6891ef5ba12..00000000000 --- a/db/post_migrate/20171103140253_track_untracked_uploads.rb +++ /dev/null @@ -1,21 +0,0 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class TrackUntrackedUploads < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - disable_ddl_transaction! - - DOWNTIME = false - MIGRATION = 'PrepareUntrackedUploads' - - def up - BackgroundMigrationWorker.perform_async(MIGRATION) - end - - def down - if table_exists?(:untracked_files_for_uploads) - drop_table :untracked_files_for_uploads - end - end -end diff --git a/db/post_migrate/20171106133144_cleanup_application_settings_password_authentication_enabled_rename.rb b/db/post_migrate/20171106133144_cleanup_application_settings_password_authentication_enabled_rename.rb deleted file mode 100644 index 4a01bf75f50..00000000000 --- a/db/post_migrate/20171106133144_cleanup_application_settings_password_authentication_enabled_rename.rb +++ /dev/null @@ -1,15 +0,0 @@ -class CleanupApplicationSettingsPasswordAuthenticationEnabledRename < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - cleanup_concurrent_column_rename :application_settings, :password_authentication_enabled, :password_authentication_enabled_for_web - end - - def down - rename_column_concurrently :application_settings, :password_authentication_enabled_for_web, :password_authentication_enabled - end -end diff --git a/db/post_migrate/20171106154015_remove_issues_branch_name.rb b/db/post_migrate/20171106154015_remove_issues_branch_name.rb deleted file mode 100644 index 4e71aa2f163..00000000000 --- a/db/post_migrate/20171106154015_remove_issues_branch_name.rb +++ /dev/null @@ -1,13 +0,0 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class RemoveIssuesBranchName < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - # Set this constant to true if this migration requires downtime. - DOWNTIME = false - - def change - remove_column :issues, :branch_name, :string - end -end diff --git a/db/post_migrate/20171106180641_cleanup_add_timezone_to_issues_closed_at.rb b/db/post_migrate/20171106180641_cleanup_add_timezone_to_issues_closed_at.rb deleted file mode 100644 index 8187d3971fc..00000000000 --- a/db/post_migrate/20171106180641_cleanup_add_timezone_to_issues_closed_at.rb +++ /dev/null @@ -1,20 +0,0 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class CleanupAddTimezoneToIssuesClosedAt < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - cleanup_concurrent_column_type_change(:issues, :closed_at) - end - - # rubocop:disable Migration/Datetime - # rubocop:disable Migration/UpdateLargeTable - def down - change_column_type_concurrently(:issues, :closed_at, :datetime) - end -end diff --git a/db/post_migrate/20171114104051_remove_empty_fork_networks.rb b/db/post_migrate/20171114104051_remove_empty_fork_networks.rb deleted file mode 100644 index 76862cccf60..00000000000 --- a/db/post_migrate/20171114104051_remove_empty_fork_networks.rb +++ /dev/null @@ -1,36 +0,0 @@ -class RemoveEmptyForkNetworks < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - BATCH_SIZE = 10_000 - - class MigrationForkNetwork < ActiveRecord::Base - include EachBatch - - self.table_name = 'fork_networks' - end - - class MigrationForkNetworkMembers < ActiveRecord::Base - self.table_name = 'fork_network_members' - end - - disable_ddl_transaction! - - def up - say 'Deleting empty ForkNetworks in batches' - - has_members = MigrationForkNetworkMembers - .where('fork_network_members.fork_network_id = fork_networks.id') - .select(1) - MigrationForkNetwork.where('NOT EXISTS (?)', has_members) - .each_batch(of: BATCH_SIZE) do |networks| - deleted = networks.delete_all - - say "Deleted #{deleted} rows in batch" - end - end - - def down - # nothing - end -end diff --git a/db/post_migrate/20171121160421_remove_merge_request_diff_st_commits_and_st_diffs.rb b/db/post_migrate/20171121160421_remove_merge_request_diff_st_commits_and_st_diffs.rb deleted file mode 100644 index 93a97993f1f..00000000000 --- a/db/post_migrate/20171121160421_remove_merge_request_diff_st_commits_and_st_diffs.rb +++ /dev/null @@ -1,10 +0,0 @@ -class RemoveMergeRequestDiffStCommitsAndStDiffs < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def change - remove_column :merge_request_diffs, :st_commits, :text - remove_column :merge_request_diffs, :st_diffs, :text - end -end diff --git a/db/post_migrate/20171123101020_update_circuitbreaker_defaults.rb b/db/post_migrate/20171123101020_update_circuitbreaker_defaults.rb deleted file mode 100644 index ae954289291..00000000000 --- a/db/post_migrate/20171123101020_update_circuitbreaker_defaults.rb +++ /dev/null @@ -1,34 +0,0 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class UpdateCircuitbreakerDefaults < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - class ApplicationSetting < ActiveRecord::Base; end - - def up - change_column_default :application_settings, - :circuitbreaker_failure_count_threshold, - 3 - change_column_default :application_settings, - :circuitbreaker_storage_timeout, - 15 - - ApplicationSetting.update_all(circuitbreaker_failure_count_threshold: 3, - circuitbreaker_storage_timeout: 15) - end - - def down - change_column_default :application_settings, - :circuitbreaker_failure_count_threshold, - 160 - change_column_default :application_settings, - :circuitbreaker_storage_timeout, - 30 - - ApplicationSetting.update_all(circuitbreaker_failure_count_threshold: 160, - circuitbreaker_storage_timeout: 30) - end -end diff --git a/db/post_migrate/20171123101046_remove_old_circuitbreaker_config.rb b/db/post_migrate/20171123101046_remove_old_circuitbreaker_config.rb deleted file mode 100644 index 3f2c1b2170a..00000000000 --- a/db/post_migrate/20171123101046_remove_old_circuitbreaker_config.rb +++ /dev/null @@ -1,26 +0,0 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class RemoveOldCircuitbreakerConfig < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def up - remove_column :application_settings, - :circuitbreaker_backoff_threshold - remove_column :application_settings, - :circuitbreaker_failure_wait_time - end - - def down - add_column :application_settings, - :circuitbreaker_backoff_threshold, - :integer, - default: 80 - add_column :application_settings, - :circuitbreaker_failure_wait_time, - :integer, - default: 30 - end -end diff --git a/db/post_migrate/20171124095655_add_index_on_merge_request_diffs_merge_request_id_and_id.rb b/db/post_migrate/20171124095655_add_index_on_merge_request_diffs_merge_request_id_and_id.rb deleted file mode 100644 index 2c65a4ae4f5..00000000000 --- a/db/post_migrate/20171124095655_add_index_on_merge_request_diffs_merge_request_id_and_id.rb +++ /dev/null @@ -1,17 +0,0 @@ -class AddIndexOnMergeRequestDiffsMergeRequestIdAndId < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - add_concurrent_index(:merge_request_diffs, [:merge_request_id, :id]) - end - - def down - if index_exists?(:merge_request_diffs, [:merge_request_id, :id]) - remove_concurrent_index(:merge_request_diffs, [:merge_request_id, :id]) - end - end -end diff --git a/db/post_migrate/20171124100152_remove_index_on_merge_request_diffs_merge_request_diff_id.rb b/db/post_migrate/20171124100152_remove_index_on_merge_request_diffs_merge_request_diff_id.rb deleted file mode 100644 index efd3714d668..00000000000 --- a/db/post_migrate/20171124100152_remove_index_on_merge_request_diffs_merge_request_diff_id.rb +++ /dev/null @@ -1,17 +0,0 @@ -class RemoveIndexOnMergeRequestDiffsMergeRequestDiffId < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - if index_exists?(:merge_request_diffs, :merge_request_id) - remove_concurrent_index(:merge_request_diffs, :merge_request_id) - end - end - - def down - add_concurrent_index(:merge_request_diffs, :merge_request_id) - end -end diff --git a/db/post_migrate/20171124104327_migrate_kubernetes_service_to_new_clusters_architectures.rb b/db/post_migrate/20171124104327_migrate_kubernetes_service_to_new_clusters_architectures.rb deleted file mode 100644 index 58ceefe3c97..00000000000 --- a/db/post_migrate/20171124104327_migrate_kubernetes_service_to_new_clusters_architectures.rb +++ /dev/null @@ -1,151 +0,0 @@ -class MigrateKubernetesServiceToNewClustersArchitectures < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - DEFAULT_KUBERNETES_SERVICE_CLUSTER_NAME = 'KubernetesService'.freeze - - disable_ddl_transaction! - - class Project < ActiveRecord::Base - self.table_name = 'projects' - - has_many :cluster_projects, class_name: 'MigrateKubernetesServiceToNewClustersArchitectures::ClustersProject' - has_many :clusters, through: :cluster_projects, class_name: 'MigrateKubernetesServiceToNewClustersArchitectures::Cluster' - has_many :services, class_name: 'MigrateKubernetesServiceToNewClustersArchitectures::Service' - has_one :kubernetes_service, -> { where(category: 'deployment', type: 'KubernetesService') }, class_name: 'MigrateKubernetesServiceToNewClustersArchitectures::Service', inverse_of: :project, foreign_key: :project_id - end - - class Cluster < ActiveRecord::Base - self.table_name = 'clusters' - - has_many :cluster_projects, class_name: 'MigrateKubernetesServiceToNewClustersArchitectures::ClustersProject' - has_many :projects, through: :cluster_projects, class_name: 'MigrateKubernetesServiceToNewClustersArchitectures::Project' - has_one :platform_kubernetes, class_name: 'MigrateKubernetesServiceToNewClustersArchitectures::PlatformsKubernetes' - - accepts_nested_attributes_for :platform_kubernetes - - enum platform_type: { - kubernetes: 1 - } - - enum provider_type: { - user: 0, - gcp: 1 - } - end - - class ClustersProject < ActiveRecord::Base - self.table_name = 'cluster_projects' - - belongs_to :cluster, class_name: 'MigrateKubernetesServiceToNewClustersArchitectures::Cluster' - belongs_to :project, class_name: 'MigrateKubernetesServiceToNewClustersArchitectures::Project' - end - - class PlatformsKubernetes < ActiveRecord::Base - self.table_name = 'cluster_platforms_kubernetes' - - belongs_to :cluster, class_name: 'MigrateKubernetesServiceToNewClustersArchitectures::Cluster' - - attr_encrypted :token, - mode: :per_attribute_iv, - key: Settings.attr_encrypted_db_key_base_truncated, - algorithm: 'aes-256-cbc' - end - - class Service < ActiveRecord::Base - include EachBatch - - self.table_name = 'services' - self.inheritance_column = :_type_disabled # Disable STI, otherwise KubernetesModel will be looked up - - belongs_to :project, class_name: 'MigrateKubernetesServiceToNewClustersArchitectures::Project', foreign_key: :project_id - - scope :unmanaged_kubernetes_service, -> do - joins('LEFT JOIN projects ON projects.id = services.project_id') - .joins('LEFT JOIN cluster_projects ON cluster_projects.project_id = projects.id') - .joins('LEFT JOIN cluster_platforms_kubernetes ON cluster_platforms_kubernetes.cluster_id = cluster_projects.cluster_id') - .where(category: 'deployment', type: 'KubernetesService', template: false) - .where("services.properties LIKE '%api_url%'") - .where("(services.properties NOT LIKE CONCAT('%', cluster_platforms_kubernetes.api_url, '%')) OR cluster_platforms_kubernetes.api_url IS NULL") - .group(:id) - .order(id: :asc) - end - - scope :kubernetes_service_without_template, -> do - where(category: 'deployment', type: 'KubernetesService', template: false) - end - - def api_url - parsed_properties['api_url'] - end - - def ca_pem - parsed_properties['ca_pem'] - end - - def namespace - parsed_properties['namespace'] - end - - def token - parsed_properties['token'] - end - - private - - def parsed_properties - @parsed_properties ||= JSON.parse(self.properties) - end - end - - def find_dedicated_environement_scope(project) - environment_scopes = project.clusters.map(&:environment_scope) - - return '*' if environment_scopes.exclude?('*') # KubernetesService should be added as a default cluster (environment_scope: '*') at first place - return 'migrated/*' if environment_scopes.exclude?('migrated/*') # If it's conflicted, the KubernetesService added as a migrated cluster - - unique_iid = 0 - - # If it's still conflicted, finding an unique environment scope incrementaly - loop do - candidate = "migrated#{unique_iid}/*" - return candidate if environment_scopes.exclude?(candidate) - - unique_iid += 1 - end - end - - def up - ActiveRecord::Base.transaction do - MigrateKubernetesServiceToNewClustersArchitectures::Service - .unmanaged_kubernetes_service.find_each(batch_size: 1) do |kubernetes_service| - MigrateKubernetesServiceToNewClustersArchitectures::Cluster.create( - enabled: kubernetes_service.active, - user_id: nil, # KubernetesService doesn't have - name: DEFAULT_KUBERNETES_SERVICE_CLUSTER_NAME, - provider_type: MigrateKubernetesServiceToNewClustersArchitectures::Cluster.provider_types[:user], - platform_type: MigrateKubernetesServiceToNewClustersArchitectures::Cluster.platform_types[:kubernetes], - projects: [kubernetes_service.project], - environment_scope: find_dedicated_environement_scope(kubernetes_service.project), - platform_kubernetes_attributes: { - api_url: kubernetes_service.api_url, - ca_cert: kubernetes_service.ca_pem, - namespace: kubernetes_service.namespace, - username: nil, # KubernetesService doesn't have - encrypted_password: nil, # KubernetesService doesn't have - encrypted_password_iv: nil, # KubernetesService doesn't have - token: kubernetes_service.token # encrypted_token and encrypted_token_iv - } ) - end - end - - MigrateKubernetesServiceToNewClustersArchitectures::Service - .kubernetes_service_without_template.each_batch(of: 100) do |kubernetes_service| - kubernetes_service.update_all(active: false) - end - end - - def down - # noop - end -end diff --git a/db/post_migrate/20171124150326_reschedule_fork_network_creation.rb b/db/post_migrate/20171124150326_reschedule_fork_network_creation.rb deleted file mode 100644 index 8e320ea9e8d..00000000000 --- a/db/post_migrate/20171124150326_reschedule_fork_network_creation.rb +++ /dev/null @@ -1,13 +0,0 @@ -class RescheduleForkNetworkCreation < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def up - say 'Fork networks will be populated in 20171205190711 - RescheduleForkNetworkCreationCaller' - end - - def down - # nothing - end -end diff --git a/db/post_migrate/20171205190711_reschedule_fork_network_creation_caller.rb b/db/post_migrate/20171205190711_reschedule_fork_network_creation_caller.rb deleted file mode 100644 index 058f3a40817..00000000000 --- a/db/post_migrate/20171205190711_reschedule_fork_network_creation_caller.rb +++ /dev/null @@ -1,27 +0,0 @@ -class RescheduleForkNetworkCreationCaller < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - MIGRATION = 'PopulateForkNetworksRange'.freeze - BATCH_SIZE = 100 - DELAY_INTERVAL = 15.seconds - - disable_ddl_transaction! - - class ForkedProjectLink < ActiveRecord::Base - include EachBatch - - self.table_name = 'forked_project_links' - end - - def up - say 'Populating the `fork_networks` based on existing `forked_project_links`' - - queue_background_migration_jobs_by_range_at_intervals(ForkedProjectLink, MIGRATION, DELAY_INTERVAL, batch_size: BATCH_SIZE) - end - - def down - # nothing - end -end diff --git a/db/post_migrate/20171207150300_remove_project_labels_group_id_copy.rb b/db/post_migrate/20171207150300_remove_project_labels_group_id_copy.rb deleted file mode 100644 index 44273cebc9d..00000000000 --- a/db/post_migrate/20171207150300_remove_project_labels_group_id_copy.rb +++ /dev/null @@ -1,21 +0,0 @@ -# Copy of 20180202111106 - this one should run before 20171207150343 to fix issues related to -# the removal of groups with labels. - -class RemoveProjectLabelsGroupIdCopy < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - def up - # rubocop:disable Migration/UpdateColumnInBatches - update_column_in_batches(:labels, :group_id, nil) do |table, query| - query.where(table[:type].eq('ProjectLabel').and(table[:group_id].not_eq(nil))) - end - # rubocop:enable Migration/UpdateColumnInBatches - end - - def down - end -end diff --git a/db/post_migrate/20171207150344_remove_deleted_at_columns.rb b/db/post_migrate/20171207150344_remove_deleted_at_columns.rb deleted file mode 100644 index 5f1c70a2797..00000000000 --- a/db/post_migrate/20171207150344_remove_deleted_at_columns.rb +++ /dev/null @@ -1,31 +0,0 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class RemoveDeletedAtColumns < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - TABLES = %i[issues merge_requests namespaces ci_pipeline_schedules ci_triggers].freeze - COLUMN = :deleted_at - - def up - TABLES.each do |table| - remove_column(table, COLUMN) if column_exists?(table, COLUMN) - end - end - - def down - TABLES.each do |table| - unless column_exists?(table, COLUMN) - add_column(table, COLUMN, :datetime_with_timezone) - end - - unless index_exists?(table, COLUMN) - add_concurrent_index(table, COLUMN) - end - end - end -end diff --git a/db/post_migrate/20171213160445_migrate_github_importer_advance_stage_sidekiq_queue.rb b/db/post_migrate/20171213160445_migrate_github_importer_advance_stage_sidekiq_queue.rb deleted file mode 100644 index 088c4b5d46b..00000000000 --- a/db/post_migrate/20171213160445_migrate_github_importer_advance_stage_sidekiq_queue.rb +++ /dev/null @@ -1,16 +0,0 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class MigrateGithubImporterAdvanceStageSidekiqQueue < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - def up - sidekiq_queue_migrate 'github_importer_advance_stage', to: 'github_import_advance_stage' - end - - def down - sidekiq_queue_migrate 'github_import_advance_stage', to: 'github_importer_advance_stage' - end -end diff --git a/db/post_migrate/20171215121205_post_populate_can_push_from_deploy_keys_projects.rb b/db/post_migrate/20171215121205_post_populate_can_push_from_deploy_keys_projects.rb deleted file mode 100644 index 1c81e56db55..00000000000 --- a/db/post_migrate/20171215121205_post_populate_can_push_from_deploy_keys_projects.rb +++ /dev/null @@ -1,63 +0,0 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class PostPopulateCanPushFromDeployKeysProjects < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - DATABASE_NAME = Gitlab::Database.database_name - - disable_ddl_transaction! - - class DeploysKeyProject < ActiveRecord::Base - include EachBatch - - self.table_name = 'deploy_keys_projects' - end - - def up - DeploysKeyProject.each_batch(of: 10_000) do |batch| - start_id, end_id = batch.pluck('MIN(id), MAX(id)').first - - if Gitlab::Database.mysql? - execute <<-EOF.strip_heredoc - UPDATE deploy_keys_projects, #{DATABASE_NAME}.keys - SET deploy_keys_projects.can_push = #{DATABASE_NAME}.keys.can_push - WHERE deploy_keys_projects.deploy_key_id = #{DATABASE_NAME}.keys.id - AND deploy_keys_projects.id BETWEEN #{start_id} AND #{end_id} - EOF - else - execute <<-EOF.strip_heredoc - UPDATE deploy_keys_projects - SET can_push = keys.can_push - FROM keys - WHERE deploy_key_id = keys.id - AND deploy_keys_projects.id BETWEEN #{start_id} AND #{end_id} - EOF - end - end - end - - def down - DeploysKeyProject.each_batch(of: 10_000) do |batch| - start_id, end_id = batch.pluck('MIN(id), MAX(id)').first - - if Gitlab::Database.mysql? - execute <<-EOF.strip_heredoc - UPDATE deploy_keys_projects, #{DATABASE_NAME}.keys - SET #{DATABASE_NAME}.keys.can_push = deploy_keys_projects.can_push - WHERE deploy_keys_projects.deploy_key_id = #{DATABASE_NAME}.keys.id - AND deploy_keys_projects.id BETWEEN #{start_id} AND #{end_id} - EOF - else - execute <<-EOF.strip_heredoc - UPDATE keys - SET can_push = deploy_keys_projects.can_push - FROM deploy_keys_projects - WHERE deploy_keys_projects.deploy_key_id = keys.id - AND deploy_keys_projects.id BETWEEN #{start_id} AND #{end_id} - EOF - end - end - end -end diff --git a/db/post_migrate/20171215121259_remove_can_push_from_keys.rb b/db/post_migrate/20171215121259_remove_can_push_from_keys.rb deleted file mode 100644 index fc4045a383d..00000000000 --- a/db/post_migrate/20171215121259_remove_can_push_from_keys.rb +++ /dev/null @@ -1,17 +0,0 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class RemoveCanPushFromKeys < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - disable_ddl_transaction! - - def up - remove_column :keys, :can_push - end - - def down - add_column_with_default :keys, :can_push, :boolean, default: false, allow_null: false - end -end diff --git a/db/post_migrate/20171219121201_normalize_extern_uid_from_identities.rb b/db/post_migrate/20171219121201_normalize_extern_uid_from_identities.rb deleted file mode 100644 index 45ef75fdb98..00000000000 --- a/db/post_migrate/20171219121201_normalize_extern_uid_from_identities.rb +++ /dev/null @@ -1,29 +0,0 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class NormalizeExternUidFromIdentities < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - MIGRATION = 'NormalizeLdapExternUidsRange'.freeze - DELAY_INTERVAL = 10.seconds - - disable_ddl_transaction! - - class Identity < ActiveRecord::Base - include EachBatch - - self.table_name = 'identities' - end - - def up - ldap_identities = Identity.where("provider like 'ldap%'") - - if ldap_identities.any? - queue_background_migration_jobs_by_range_at_intervals(Identity, MIGRATION, DELAY_INTERVAL) - end - end - - def down - end -end diff --git a/db/post_migrate/20171221140220_schedule_issues_closed_at_type_change.rb b/db/post_migrate/20171221140220_schedule_issues_closed_at_type_change.rb deleted file mode 100644 index 6b5e6202688..00000000000 --- a/db/post_migrate/20171221140220_schedule_issues_closed_at_type_change.rb +++ /dev/null @@ -1,45 +0,0 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. -# rubocop:disable Migration/Datetime -class ScheduleIssuesClosedAtTypeChange < ActiveRecord::Migration[4.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - - disable_ddl_transaction! - - class Issue < ActiveRecord::Base - self.table_name = 'issues' - include EachBatch - - def self.to_migrate - where('closed_at IS NOT NULL') - end - end - - def up - return unless migrate_column_type? - - change_column_type_using_background_migration( - Issue.to_migrate, - :closed_at, - :datetime_with_timezone - ) - end - - def down - return if migrate_column_type? - - change_column_type_using_background_migration( - Issue.to_migrate, - :closed_at, - :datetime - ) - end - - def migrate_column_type? - # Some environments may have already executed the previous version of this - # migration, thus we don't need to migrate those environments again. - column_for('issues', 'closed_at').type == :datetime - end -end |