1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-01 12:24:28 +01:00
fab-manager/db/migrate/20160602075531_add_step_nb_to_project_step.rb

22 lines
606 B
Ruby
Raw Normal View History

# frozen_string_literal:true
class AddStepNbToProjectStep < ActiveRecord::Migration[4.2]
def up
add_column :project_steps, :step_nb, :integer
execute 'UPDATE project_steps
SET step_nb = subquery.index
FROM (
SELECT
id, project_id, created_at,
row_number() OVER (PARTITION BY project_id) AS index
FROM project_steps
ORDER BY created_at
) AS subquery
WHERE project_steps.id = subquery.id;'
end
def down
remove_column :project_steps, :step_nb
end
end