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
|
# File 'lib/data_plan/generators/migration/sinatra.rb', line 14
def create_migration(migration_name, version = nil)
mg = MigrationGeneratorCore.new
up,down,hints,migration_name = mg.calculate_migration( migration_name )
migration_number = Time.now.utc.strftime("%Y%m%d%H%M%S")
migration_file = File.join(migrations_dir, "#{migration_number}_#{migration_name}.rb")
FileUtils.mkdir_p(migrations_dir)
File.open(migration_file, 'w') do |file|
file.write "class \#{ migration_name.camelize } < ActiveRecord::Migration\n def self.up\n\#{ up }\n end\n\n def self.down\n\#{ down }\n end\nend\n\n\#{ hints }\n".strip_heredoc
end
end
|