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 = <<-END.gsub(/^ {8}/, '')
class #{class_name} < Volt::Migration
def up
#{indent_string(up_content, 4)}
end
def down
#{indent_string(down_content, 4)}
end
end
END
File.open(output_file, 'w') {|f| f.write(content) }
output_file
end
|