7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'app/sql/lib/migration_generator.rb', line 7
def self.create_migration(name, up_content, down_content)
timestamp = Time.now.to_i
file_name = "#{timestamp}_#{name.underscore}"
class_name = name.camelize
output_file = "#{Dir.pwd}/config/db/migrations/#{file_name}.rb"
FileUtils.mkdir_p(File.dirname(output_file))
content = " class \#{class_name} < Volt::Migration\n def up\n \#{indent_string(up_content, 4)}\n end\n\n def down\n \#{indent_string(down_content, 4)}\n end\n end\n END\n\n File.open(output_file, 'w') {|f| f.write(content) }\n\n # return the path to the file\n output_file\nend\n".gsub(/^ {8}/, '')
|