Commit a9c5d461 authored by Antonio Terceiro's avatar Antonio Terceiro

Debci::DB: add support for ActiveRecord 5.2

Tip from https://github.com/influitive/apartment/pull/523/files plus
some local thought into how to support both 4.2 and 5.2
parent 4eb7b7fe
......@@ -4,6 +4,8 @@ require 'active_record'
module Debci
module DB
LEGACY = ActiveRecord.version.release() < Gem::Version.new('5.2.0')
def self.config
@config ||= ENV['DATABASE_URL'] || Debci.config.database_url
end
......@@ -15,9 +17,22 @@ module Debci
def self.migrate
migrations_path = File.join(File.dirname(__FILE__), 'db', 'migrations')
ActiveRecord::Migration.verbose = !Debci.config.quiet
ActiveRecord::Migrator.migrate(migrations_path, nil)
version = nil
if LEGACY
ActiveRecord::Migrator.migrate(migrations_path, nil)
else
ActiveRecord::MigrationContext.new(migrations_path).migrate
end
end
if LEGACY
LegacyMigration = ActiveRecord::Migration
else
LegacyMigration = ActiveRecord::Migration[4.2]
end
end
end
Debci::DB.establish_connection
class CreateJobs < ActiveRecord::Migration
class CreateJobs < Debci::DB::LegacyMigration
def up
create_table(:jobs, primary_key: 'run_id') do |t|
t.timestamps(null: false)
......
class CreateKeys < ActiveRecord::Migration
class CreateKeys < Debci::DB::LegacyMigration
def up
create_table(:keys) do |t|
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment