Sha256: 1d1a9eca9e5422c6a2a795ccd4200d7684c4cef7cea3ff9937dde8d19c7622eb

Contents?: true

Size: 768 Bytes

Versions: 5

Compression:

Stored size: 768 Bytes

Contents

module Coupler
  class Database < Delegator
    include Singleton

    def initialize
      @env = ENV['COUPLER_ENV']
      connection_string = Base.connection_string('coupler')
      @database = Sequel.connect(connection_string, :loggers => [Coupler::Logger.instance], :max_connections => 20)
      super(@database)
    end

    def __getobj__
      @database
    end

    def rollback!
      version = @database[:schema_info].first[:version]
      migrate!(version - 1)
    end

    def migrate!(to = nil, from = nil)
      dir = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'db', 'migrate'))
      args = [@database, dir]
      if to
        args << to
        args << from  if from
      end
      Sequel::Migrator.apply(*args)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
coupler-0.0.6-java lib/coupler/database.rb
coupler-0.0.4-java lib/coupler/database.rb
coupler-0.0.3-java lib/coupler/database.rb
coupler-0.0.2-java lib/coupler/database.rb
coupler-0.0.1-java lib/coupler/database.rb