Module: ActiveRecord::Tasks::DatabaseTasks

Defined in:
lib/multi_db/active_record_patches.rb

Instance Method Summary collapse

Instance Method Details

#create(*arguments) ⇒ Object



102
103
104
# File 'lib/multi_db/active_record_patches.rb', line 102

def create(*arguments)
  create_or_drop(:create, arguments)
end

#create_or_drop(*arguments) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/multi_db/active_record_patches.rb', line 111

def create_or_drop(*arguments)
  create_or_drop = arguments[0]
  arguments = arguments[1]
  
  _config = arguments.shift
  config_name = ActiveRecord::Base.configurations.invert[_config]
  is_test = (config_name == 'test')
  config = _config.dup
  
  case ENV['RAILS_ORG']
  when nil
    # set default org database
    raise "No database name specified in configuration \"#{config_name}\"" unless config['database']
    config['database'] += '_org1'
  when 'sessions'
    # do nothing
  when 'master'
    config = ActiveRecord::Base.master_configuration(is_test ? 'test' : nil)
  else
    config['database'] += '_' + ENV['RAILS_ORG']
  end
  
  arguments.unshift config
  
  case create_or_drop
    when :create then create_without_multidb(*arguments)
    when :drop then drop_without_multidb(*arguments)
  end
end

#create_without_multidbObject



101
# File 'lib/multi_db/active_record_patches.rb', line 101

alias :create_without_multidb :create

#drop(*arguments) ⇒ Object



107
108
109
# File 'lib/multi_db/active_record_patches.rb', line 107

def drop(*arguments)
  create_or_drop(:drop, arguments)
end

#drop_without_multidbObject



106
# File 'lib/multi_db/active_record_patches.rb', line 106

alias :drop_without_multidb :drop