-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenvironment.rb
41 lines (39 loc) · 1.23 KB
/
environment.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require 'rubygems'
require 'active_record'
require 'sinatra/base' unless defined?(Sinatra)
# only tested on 2.3.5
# this file is a huge hack and I don't advise anyone run it at all
module Weed
module ActiveRecord
# include ::ActiveRecord
class Base < ::ActiveRecord::Base
self.abstract_class = true
cattr_accessor :connection_args
end
class Migrator < ::ActiveRecord::Migrator
class << self
# this probably isn't threadsafe?
# but then migrations probably it doesn't matter?
def with_connection(&block)
old_connection = ActiveRecord::Base.connected? && ActiveRecord::Base.connection.instance_variable_get(:"@config")
::ActiveRecord::Base.establish_connection Weed::ActiveRecord::Base.connection_args
yield
ensure
if old_connection
::ActiveRecord::Base.establish_connection old_connection
else
::ActiveRecord::Base.remove_connection
end
end
def migrate_with_db(*args)
with_connection do
migrate_without_db(*args)
end
end
self.alias_method_chain :migrate, :db
end
end
class Migration < ::ActiveRecord::Migration
end
end
end