|
|
@ -9,6 +9,7 @@ class JoinTableForActiveActivities < ActiveRecord::Migration[6.0] |
|
|
|
|
|
|
|
|
|
|
|
def up |
|
|
|
def up |
|
|
|
create_join_table |
|
|
|
create_join_table |
|
|
|
|
|
|
|
delete_invalid_project_activities |
|
|
|
link_time_entries_to_root_activities |
|
|
|
link_time_entries_to_root_activities |
|
|
|
fill_new_join_table |
|
|
|
fill_new_join_table |
|
|
|
delete_inherited_activities |
|
|
|
delete_inherited_activities |
|
|
@ -33,6 +34,19 @@ class JoinTableForActiveActivities < ActiveRecord::Migration[6.0] |
|
|
|
name: 'index_teap_on_project_id_and_activity_id' |
|
|
|
name: 'index_teap_on_project_id_and_activity_id' |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Delete all references from enumerations to projects which point to no longer |
|
|
|
|
|
|
|
# existing projects. |
|
|
|
|
|
|
|
def delete_invalid_project_activities |
|
|
|
|
|
|
|
ActiveRecord::Base.connection.exec_query( |
|
|
|
|
|
|
|
<<-SQL |
|
|
|
|
|
|
|
DELETE FROM enumerations |
|
|
|
|
|
|
|
USING enumerations AS enums |
|
|
|
|
|
|
|
LEFT OUTER JOIN projects on enums.project_id = projects.id |
|
|
|
|
|
|
|
WHERE enums.id = enumerations.id AND enums.type='TimeEntryActivity' AND projects.id IS NULL AND enums.project_id IS NOT NULL |
|
|
|
|
|
|
|
SQL |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def link_time_entries_to_root_activities |
|
|
|
def link_time_entries_to_root_activities |
|
|
|
ActiveRecord::Base.connection.exec_query( |
|
|
|
ActiveRecord::Base.connection.exec_query( |
|
|
|
<<-SQL |
|
|
|
<<-SQL |
|
|
|