計劃a: 您可以嘗試分析表issues
並查找錯誤移動的所有問題。 你知道新的project_id,你知道大致的變化時間戳。並寫入sql查詢(或使用rails控制檯)來撤消操作。 例如(代碼沒有經過測試!)
new_project_id = Project.find(ID).id # note that ID is project identificator not id of record!
timestamp = DateTime.parse('2013-10-30 12:20:45')
issues = Issue.where(project_id: new_project_id).where('updated_at > ? AND updated_at < ?', timestamp - 1.minute, timestamp + 1.minute)
# check that all selected issues must be updated!!!
issues.update_all(project_id: old_project_id) # note that old_project_id is correct id (integer value) of record in DB
B計劃: 你可以找到已在正確的DB PROJECT_ID所有ISSUE_ID。然後應用SQL查詢來更新項目ID以糾正所有問題的值where id IN (issue_ids)
損壞的數據庫
# load correct DATABASE and start rails console
project = Project.find(OLD_ID) # note that OLD_ID is project identificator not id of record!
issue_ids = project.issue_ids
# save somewhere issue_ids
# load corrupted database and start rails console
issue_ids = [saved_array_of_ids_from_previous_step]
Issue.where(id: issue_ids).update_all(project_id: correct_project_id) # note that correct_project_id is correct id (integer value) of record in DB
非常感謝您的回答! – denial