Skip to content

Instantly share code, notes, and snippets.

@goguelu
Created July 20, 2009 13:00
Show Gist options
  • Save goguelu/150328 to your computer and use it in GitHub Desktop.
Save goguelu/150328 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
require 'rubygems'
require 'active_record'
require 'active_support'
require 'parseconfig'
config = ParseConfig.new( '/path/to/conf/file.conf' )
db_number = config.get_value( 'database_count' ).to_i
array = Array.new
results = Array.new
variable = 1
while variable < ( db_number + 1 ) do
db = config.get_value( 'DB' + variable.to_s )
db_parameters = db[1..-2].split(',')
array.push db_parameters
variable = variable + 1
end
array.each do |db_parameters|
ActiveRecord::Base.establish_connection(
:adapter => db_parameters[0],
:host => db_parameters[1],
:port => db_parameters[2].to_i,
:database => db_parameters[3],
:username => db_parameters[4],
:password => db_parameters[5]
)
class Order < ActiveRecord::Base
set_table_name "Orders"
end
results.push Order.count('ID')
end
allgood = true
variable = 0
results.each do |size_db|
if variable == 0
variable = size_db
elsif variable != size_db
allgood = false
end
end
if allgood
puts "OK"
exit 0
else
array.each do |db_parameters|
print " " + db_parameters.last + " " + results[array.index(db_parameters)].to_s + " "
end
exit 2
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment