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

20 lines
571 B
Ruby
Raw Normal View History

class AddStepNbToProjectStep < ActiveRecord::Migration
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