class SimplestMigrations::Database
Public Class Methods
configuration(db = nil)
click to toggle source
# File lib/simplest_migrations/database.rb, line 27 def self.configuration(db = nil) @config ||= {} db_name = db || name @config[db_name] ||= begin url = ENV["DATABASE_URL"] uri = URI.parse(url) { database: db_name, adapter: 'postgresql', host: uri.host, port: uri.port || 5432, encoding: 'unicode', pool: 5, username: uri.user, password: uri.password || '' } end @config[db_name] end
connection!(db = nil)
click to toggle source
# File lib/simplest_migrations/database.rb, line 22 def self.connection!(db = nil) ActiveRecord::Base.establish_connection configuration(db) ActiveRecord::Base end
execute(cmd, db = nil)
click to toggle source
# File lib/simplest_migrations/database.rb, line 13 def self.execute(cmd, db = nil) connection!(db) ActiveRecord::Base.connection.execute cmd end
migrate()
click to toggle source
# File lib/simplest_migrations/database.rb, line 7 def self.migrate connection! ActiveRecord::Migration.verbose = true ActiveRecord::Migrator.migrate 'db/migrate', ENV['VERSION'] ? ENV['VERSION'].to_i : nil end
name()
click to toggle source
# File lib/simplest_migrations/database.rb, line 18 def self.name ENV['DATABASE_NAME'] end
set_pg_environment()
click to toggle source
# File lib/simplest_migrations/database.rb, line 50 def self.set_pg_environment config = configuration ENV['PGHOST'] = config[:host].to_s ENV['PGPORT'] = config[:port].to_s ENV['PGPASSWORD'] = config[:password].to_s ENV['PGUSER'] = config[:username].to_s end