7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'app/controllers/migration_manager/migration_builder_controller.rb', line 7
def create
operation = params[:operation] table_name = params[:table_name].presence
columns = params[:columns] || []
return redirect_to request.referer, alert: "Table name is required" if table_name.blank?
migration_name = generate_migration_name(operation, table_name, columns)
timestamp = Time.now.strftime('%Y%m%d%H%M%S')
formatted_file_name = migration_name.underscore
file_name = "#{timestamp}_#{formatted_file_name}.rb"
file_path = Rails.root.join("db/migrate/#{file_name}")
migration_content = generate_migration_content(migration_name, operation, table_name, columns)
File.open(file_path, "w") { |file| file.write(migration_content) }
redirect_to "#{request.base_url}/migration_manager/home", notice: "Migration #{file_name} created successfully!"
end
|