Tôi đang xây dựng động cơ Rails bằng đá quý ruby. Nó bao gồm một số di cư ngay bây giờ được gọi là khi bạn chạy:Thêm di chuyển mới từ đá quý động cơ Rails vào ứng dụng qua máy phát điện
rails g myengine:install
Các mã trong các máy phát điện như sau:
module MyEngine
module Generators
class InstallGenerator < ::Rails::Generators::Base
include Rails::Generators::Migration
source_root File.expand_path('../templates', __FILE__)
# ...
def copy_migrations
migration_template "migrations/migration1.rb", "db/migrate/migration1.rb"
migration_template "migrations/migration2.rb", "db/migrate/migration2.rb"
end
# ...
end
end
end
Tuy nhiên, nếu tôi chạy rails g myengine:install
một lần nữa, nó không thành công với lỗi này:
Another migration is already named migration1: /Users/jh/Code/Web/demoapp/db/migrate/20130327222221_migration1.rb
Tôi muốn nó chỉ lặng lẽ bỏ qua thực tế là đã có di chuyển và tiếp tục di chuyển tiếp theo. Cách tốt nhất để làm điều này là gì?
EDIT:
mỗi Dmitry của câu trả lời, đây là giải pháp của tôi:
def copy_migrations
copy_migration "migration1"
copy_migration "migration2"
end
protected
def copy_migration(filename)
if self.class.migration_exists?("db/migrate", "#{filename}")
say_status("skipped", "Migration #{filename}.rb already exists")
else
migration_template "migrations/#{filename}.rb", "db/migrate/#{filename}.rb"
end
end
@Mischa, tôi có tên có ý nghĩa trong ứng dụng thực tế. Điều đó không giúp được gì khi bạn chạy lại trình tạo cài đặt để nâng cấp nó. –
Ah, tôi hiểu rồi. Vui vì bạn đã giải quyết nó ... – Mischa