@@ -1,16 +1,21 | |||||
1 | class ChangeRepositoriesToFullSti < ActiveRecord::Migration |
|
1 | class ChangeRepositoriesToFullSti < ActiveRecord::Migration | |
2 | def up |
|
2 | def up | |
3 | Repository.connection.select_rows("SELECT id, type FROM #{Repository.table_name}").each do |repository_id, repository_type| |
|
3 | Repository.connection. | |
|
4 | select_rows("SELECT id, type FROM #{Repository.table_name}"). | |||
|
5 | each do |repository_id, repository_type| | |||
4 | unless repository_type =~ /^Repository::/ |
|
6 | unless repository_type =~ /^Repository::/ | |
5 |
Repository. |
|
7 | Repository.where(["id = ?", repository_id]). | |
|
8 | update_all(["type = ?", "Repository::#{repository_type}"]) | |||
6 | end |
|
9 | end | |
7 | end |
|
10 | end | |
8 | end |
|
11 | end | |
9 |
|
12 | |||
10 | def down |
|
13 | def down | |
11 | Repository.connection.select_rows("SELECT id, type FROM #{Repository.table_name}").each do |repository_id, repository_type| |
|
14 | Repository.connection. | |
|
15 | select_rows("SELECT id, type FROM #{Repository.table_name}"). | |||
|
16 | each do |repository_id, repository_type| | |||
12 | if repository_type =~ /^Repository::(.+)$/ |
|
17 | if repository_type =~ /^Repository::(.+)$/ | |
13 |
Repository.update_all |
|
18 | Repository.where(["id = ?", repository_id]).update_all(["type = ?", $1]) | |
14 | end |
|
19 | end | |
15 | end |
|
20 | end | |
16 | end |
|
21 | end |
General Comments 0
You need to be logged in to leave comments.
Login now