diff options
Diffstat (limited to 'db/migrate/20210503105845_add_project_value_stream_id_to_project_stages.rb')
-rw-r--r-- | db/migrate/20210503105845_add_project_value_stream_id_to_project_stages.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/db/migrate/20210503105845_add_project_value_stream_id_to_project_stages.rb b/db/migrate/20210503105845_add_project_value_stream_id_to_project_stages.rb new file mode 100644 index 00000000000..d888ab4943c --- /dev/null +++ b/db/migrate/20210503105845_add_project_value_stream_id_to_project_stages.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class AddProjectValueStreamIdToProjectStages < ActiveRecord::Migration[6.0] + disable_ddl_transaction! + + INDEX_NAME = 'index_analytics_ca_project_stages_on_value_stream_id' + + class ProjectValueStream < ActiveRecord::Base + self.table_name = 'analytics_cycle_analytics_project_stages' + + include EachBatch + end + + def up + ProjectValueStream.reset_column_information + # The table was never used, there is no user-facing code that modifies the table, it should be empty. + # Since there is no functionality present that depends on this data, it's safe to delete the rows. + ProjectValueStream.each_batch(of: 100) do |relation| + relation.delete_all + end + + transaction do + add_reference :analytics_cycle_analytics_project_stages, :project_value_stream, null: false, index: { name: INDEX_NAME }, foreign_key: { on_delete: :cascade, to_table: :analytics_cycle_analytics_project_value_streams }, type: :bigint # rubocop: disable Migration/AddReference, Rails/NotNullColumn + end + end + + def down + remove_reference :analytics_cycle_analytics_project_stages, :project_value_stream + end +end |