You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20120422150750_change_repositories_to_full_sti.rb 741B

12345678910111213141516171819202122
  1. class ChangeRepositoriesToFullSti < ActiveRecord::Migration[4.2]
  2. def up
  3. Repository.connection.
  4. select_rows("SELECT id, type FROM #{Repository.table_name}").
  5. each do |repository_id, repository_type|
  6. unless /^Repository::/.match?(repository_type)
  7. Repository.where(["id = ?", repository_id]).
  8. update_all(["type = ?", "Repository::#{repository_type}"])
  9. end
  10. end
  11. end
  12. def down
  13. Repository.connection.
  14. select_rows("SELECT id, type FROM #{Repository.table_name}").
  15. each do |repository_id, repository_type|
  16. if repository_type =~ /^Repository::(.+)$/
  17. Repository.where(["id = ?", repository_id]).update_all(["type = ?", $1])
  18. end
  19. end
  20. end
  21. end