diff options
Diffstat (limited to 'db/post_migrate/20210215095328_migrate_delayed_project_removal_from_namespaces_to_namespace_settings.rb')
-rw-r--r-- | db/post_migrate/20210215095328_migrate_delayed_project_removal_from_namespaces_to_namespace_settings.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/db/post_migrate/20210215095328_migrate_delayed_project_removal_from_namespaces_to_namespace_settings.rb b/db/post_migrate/20210215095328_migrate_delayed_project_removal_from_namespaces_to_namespace_settings.rb new file mode 100644 index 00000000000..12e156d3b8a --- /dev/null +++ b/db/post_migrate/20210215095328_migrate_delayed_project_removal_from_namespaces_to_namespace_settings.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +class MigrateDelayedProjectRemovalFromNamespacesToNamespaceSettings < ActiveRecord::Migration[6.0] + DOWNTIME = false + + class Namespace < ActiveRecord::Base + self.table_name = 'namespaces' + + include ::EachBatch + end + + def up + Namespace.select(:id).where(delayed_project_removal: true).each_batch do |batch| + values = batch.map { |record| "(#{record.id}, TRUE, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)" } + + execute <<-EOF.strip_heredoc + INSERT INTO namespace_settings (namespace_id, delayed_project_removal, created_at, updated_at) + VALUES #{values.join(', ')} + ON CONFLICT (namespace_id) DO UPDATE + SET delayed_project_removal = TRUE + EOF + end + end + + def down + # no-op + end +end |