lib/flydata/compatibility_check.rb in flydata-0.3.13 vs lib/flydata/compatibility_check.rb in flydata-0.3.14
- old
+ new
@@ -76,17 +76,20 @@
class MysqlCompatibilityError < StandardError
end
SELECT_QUERY_TMPLT = "SELECT %s"
BINLOG_RETENTION_HOURS = 24
+ SELECT_TABLE_INFO_TMPLT = "SELECT table_name, table_type, engine FROM information_schema.tables WHERE table_schema = '%s' and table_name in(%s)"
#def initialize(de_hash, dump_dir=nil)
def initialize(dp_hash, de_hash, options={})
super
- @db_opts = [:host, :port, :username, :password, :database].inject({}) {|h, sym| h[sym] = de_hash[sym.to_s]; h}
+ @db_opts = [:host, :port, :username, :password, :database, :ssl_ca].inject({}) {|h, sym| h[sym] = de_hash[sym.to_s]; h}
+ @db_opts[:sslca] = @db_opts[:ssl_ca] # for mysql2 gem
@dump_dir = options[:dump_dir] || nil
@backup_dir = options[:backup_dir] || nil
+ @tables = de_hash['tables']
end
def print_errors
return if @errors.empty?
log_error_stderr "There may be some compatibility issues with your MySQL credentials: "
@@ -197,9 +200,25 @@
write_errors << full_path unless File.writable?(full_path) and File.executable?(full_path)
end
unless write_errors.empty?
error_dir = write_errors.join(", ")
raise MysqlCompatibilityError, "We cannot access the directories: #{error_dir}"
+ end
+ end
+
+ # If table_type='VIEW' or engine='MEMORY', raise error.
+ def check_mysql_table_types
+ return if @tables.empty?
+ client = Mysql2::Client.new(@db_opts)
+ sel_query = SELECT_TABLE_INFO_TMPLT % [client.escape(@db_opts[:database]), @tables.collect{|t| "'#{client.escape(t)}'"}.join(", ")]
+ begin
+ invalid_tables = []
+ client.query(sel_query).each do |r|
+ invalid_tables.push(r['table_name']) if r['table_type'] == 'VIEW' || r['engine'] == 'MEMORY'
+ end
+ raise MysqlCompatibilityError, "FlyData does not support VIEW and MEMORY ENGINE table. Remove following tables from data entry: #{invalid_tables.join(", ")}" unless invalid_tables.empty?
+ ensure
+ client.close
end
end
def run_mysql_retention_check(mysql_client)
expire_logs_days_limit = BINLOG_RETENTION_HOURS / 24