Module: Debci::DB

Defined in:
lib/debci/db.rb

Constant Summary collapse

LEGACY_MIGRATION =
if version_isnewer
  ActiveRecord::Migration
else
  ActiveRecord::Migration[4.2]
end

Class Method Summary collapse

Class Method Details

.configObject



6
7
8
# File 'lib/debci/db.rb', line 6

def self.config
  @config ||= ENV['DATABASE_URL'] || Debci.config.database_url
end

.establish_connectionObject



10
11
12
# File 'lib/debci/db.rb', line 10

def self.establish_connection
  ActiveRecord::Base.establish_connection(config)
end

.migrateObject



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/debci/db.rb', line 14

def self.migrate
  migrations_path = File.join(File.dirname(__FILE__), 'db', 'migrations')
  ActiveRecord::Migration.verbose = !Debci.config.quiet
  if ActiveRecord.version.release >= Gem::Version.new('6.0')    # ActiveRecord 6+

    ActiveRecord::MigrationContext.new(migrations_path, ActiveRecord::SchemaMigration).migrate
  else
    # ActiveRecord 5.2
    ActiveRecord::MigrationContext.new(migrations_path).migrate
  end
end