Sha256: f3e2b4d2bcebc37fc39dfec4b02f6746b8a26d0ad245c8f7767d43f9d47d615e

Contents?: true

Size: 1.09 KB

Versions: 10

Compression:

Stored size: 1.09 KB

Contents

module ROM
  module SQL
    module Migration
      class Migrator
        include Options

        DEFAULT_PATH = 'db/migrate'.freeze
        VERSION_FORMAT = '%Y%m%d%H%M%S'.freeze

        option :path, reader: true, default: DEFAULT_PATH

        attr_reader :connection

        def initialize(connection, options = {})
          super
          @connection = connection
        end

        def run(options = {})
          Sequel::Migrator.run(connection, path.to_s, options)
        end

        def migration(&block)
          Sequel.migration(&block)
        end

        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

        def generate_version
          Time.now.utc.strftime(VERSION_FORMAT)
        end

        def migration_file_content
          File.read(Pathname(__FILE__).dirname.join('template.rb').realpath)
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rom-sql-0.6.1 lib/rom/sql/migration/migrator.rb
rom-sql-0.6.0 lib/rom/sql/migration/migrator.rb
rom-sql-0.6.0.rc1 lib/rom/sql/migration/migrator.rb
rom-sql-0.6.0.beta1 lib/rom/sql/migration/migrator.rb
rom-sql-0.5.3 lib/rom/sql/migration/migrator.rb
rom-sql-0.5.2 lib/rom/sql/migration/migrator.rb
rom-sql-0.5.1 lib/rom/sql/migration/migrator.rb
rom-sql-0.5.0 lib/rom/sql/migration/migrator.rb
rom-sql-0.4.3 lib/rom/sql/migration/migrator.rb
rom-sql-0.4.1 lib/rom/sql/migration/migrator.rb