Class: ROM::SQL::Migration::Migrator
- Inherits:
-
Object
- Object
- ROM::SQL::Migration::Migrator
- Includes:
- Options
- Defined in:
- lib/rom/sql/migration/migrator.rb
Constant Summary collapse
- DEFAULT_PATH =
'db/migrate'.freeze
- VERSION_FORMAT =
'%Y%m%d%H%M%S'.freeze
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Instance Method Summary collapse
- #create_file(name, version = generate_version) ⇒ Object
- #generate_version ⇒ Object
-
#initialize(connection, options = {}) ⇒ Migrator
constructor
A new instance of Migrator.
- #migration(&block) ⇒ Object
- #migration_file_content ⇒ Object
- #pending? ⇒ Boolean
- #run(options = {}) ⇒ Object
Constructor Details
#initialize(connection, options = {}) ⇒ Migrator
Returns a new instance of Migrator.
14 15 16 17 |
# File 'lib/rom/sql/migration/migrator.rb', line 14 def initialize(connection, = {}) super @connection = connection end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
12 13 14 |
# File 'lib/rom/sql/migration/migrator.rb', line 12 def connection @connection end |
Instance Method Details
#create_file(name, version = generate_version) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rom/sql/migration/migrator.rb', line 31 def create_file(name, version = generate_version) filename = "#{version}_#{name}.rb" dirname = Pathname(path) fullpath = dirname.join(filename) FileUtils.mkdir_p(dirname) File.write(fullpath, migration_file_content) fullpath end |
#generate_version ⇒ Object
42 43 44 |
# File 'lib/rom/sql/migration/migrator.rb', line 42 def generate_version Time.now.utc.strftime(VERSION_FORMAT) end |
#migration(&block) ⇒ Object
27 28 29 |
# File 'lib/rom/sql/migration/migrator.rb', line 27 def migration(&block) Sequel.migration(&block) end |
#migration_file_content ⇒ Object
46 47 48 |
# File 'lib/rom/sql/migration/migrator.rb', line 46 def migration_file_content File.read(Pathname(__FILE__).dirname.join('template.rb').realpath) end |
#pending? ⇒ Boolean
23 24 25 |
# File 'lib/rom/sql/migration/migrator.rb', line 23 def pending? !Sequel::Migrator.is_current?(connection, path.to_s) end |
#run(options = {}) ⇒ Object
19 20 21 |
# File 'lib/rom/sql/migration/migrator.rb', line 19 def run( = {}) Sequel::Migrator.run(connection, path.to_s, ) end |