7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/mule_migrations/generator.rb', line 7
def self.migration(name, db, type, options="")
generator_params = [name] + options.split(" ")
migration_path = Rails.root.join(db, "db/migrate")
old_files = Dir.glob(File.join(migration_path, "*"))
Rails::Generators.invoke "active_record:migration", generator_params,
:destination_root => Rails.root.join(db)
new_files = Dir.glob(File.join(migration_path, "*"))
new_migration_file = get_new_migration_file(old_files, new_files)
if new_migration_file and type == 'sql'
filename = File.basename(new_migration_file, ".rb")
sql_scripts = create_sql_scripts(db, filename)
nmf = File.open(new_migration_file, "r") {|f| f.read}
updated_nmf = inject_sql_execution_code_into_migration(nmf, filename, sql_scripts)
File.open(new_migration_file, 'w') {|f| f.write(updated_nmf)}
end
end
|