mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-12-01 12:24:28 +01:00
20 lines
571 B
Ruby
20 lines
571 B
Ruby
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
|