mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-11-29 10:24:20 +01:00
22 lines
606 B
Ruby
22 lines
606 B
Ruby
# 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
|