Class: GdshowsdatabaseUpgradeGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/gdshowsdb/generators/gdshowsdatabase_upgrade_generator.rb

Constant Summary collapse

@@migrations_dir =
File.expand_path('../../templates', __FILE__)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(path) ⇒ Object



9
10
11
# File 'lib/gdshowsdb/generators/gdshowsdatabase_upgrade_generator.rb', line 9

def self.next_migration_number(path)
  Time.now.utc.strftime("%Y%m%d%H%M%S")
end

Instance Method Details

#create_update_migration_fileObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/gdshowsdb/generators/gdshowsdatabase_upgrade_generator.rb', line 13

def create_update_migration_file
  song_ref_diff = Gdshowsdb::SongRefDiff.new
  @added_song_refs = song_ref_diff.added
  @updated_song_refs = song_ref_diff.updated
  @removed_song_refs = song_ref_diff.removed

  @added_shows = []
  @updated_shows = []
  @removed_shows = []
  @added_sets = []
  @updated_sets = []
  @removed_sets = []
  @added_songs = []
  @updated_songs = []
  @removed_songs = []
  (1965..1995).each do |year|
    show_diff = Gdshowsdb::ShowDiff.new(year)
    @added_shows.concat(show_diff.added)
    @updated_shows.concat(show_diff.updated)
    @removed_shows.concat(show_diff.removed)

    set_diff = Gdshowsdb::SetDiff.new(year)
    @added_sets.concat(set_diff.added)
    @updated_sets.concat(set_diff.updated)
    @removed_sets.concat(set_diff.removed)      

    song_diff = Gdshowsdb::SongDiff.new(year)
    @added_songs.concat(song_diff.added)
    @updated_songs.concat(song_diff.updated)
    @removed_songs.concat(song_diff.removed)      
  end

  file = @@migrations_dir + "/update_migration.rb.erb"
  migration_template(file, "db/migrate/update_gdshowsdb_data.rb")
end