Commit 12fd7b7558fa31f16783f8469fe1e227ea88e0c0
1 parent
6a0b8035
Exists in
master
and in
2 other branches
Add a second migration to change softwares dates
Showing
1 changed file
with
40 additions
and
0 deletions
Show diff stats
db/migrate/20150828201023_second_software_release_date.rb
0 → 100644
... | ... | @@ -0,0 +1,40 @@ |
1 | +class SecondSoftwareReleaseDate < ActiveRecord::Migration | |
2 | + def up | |
3 | + softwares = SoftwareInfo.all | |
4 | + softwares.each do |software| | |
5 | + if software.community | |
6 | + name = software.community.name.strip | |
7 | + software.community.name = name | |
8 | + software.community.save | |
9 | + else | |
10 | + software.destroy | |
11 | + end | |
12 | + end | |
13 | + | |
14 | + file = File.new("plugins/spb_migrations/files/date-communities.txt", "r") | |
15 | + while (line = file.gets) | |
16 | + result = line.split('|') | |
17 | + software_name = result[2].gsub("/n", "") | |
18 | + software = Community.where("name ILIKE ?", software_name.strip) | |
19 | + | |
20 | + if software && software.count == 1 | |
21 | + software = software.first | |
22 | + software.created_at = Time.zone.parse(result[1]) | |
23 | + if software.save | |
24 | + print "." | |
25 | + else | |
26 | + print "F" | |
27 | + end | |
28 | + else | |
29 | + print "F" | |
30 | + puts software_name | |
31 | + end | |
32 | + end | |
33 | + file.close | |
34 | + puts "" | |
35 | + end | |
36 | + | |
37 | + def down | |
38 | + say "This can't be reverted" | |
39 | + end | |
40 | +end | ... | ... |