From e711d7bcce382d2426f768cf4fbef26233fe5776 Mon Sep 17 00:00:00 2001 From: "jiil.hyoun" Date: Tue, 30 Oct 2012 16:30:02 +0900 Subject: [PATCH] [Title] add Mysql database creation [Type] Feature [Module] Toolchain / [Priority] Major [Jira#] [Redmine#] [Problem] [Cause] [Solution] [TestCase] Change-Id: Idc7ecff6503ca28859ad68203847a23a1980462b --- src/build_server/BuildServer.rb | 45 +++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/build_server/BuildServer.rb b/src/build_server/BuildServer.rb index 2c77ce5..4c98eaa 100644 --- a/src/build_server/BuildServer.rb +++ b/src/build_server/BuildServer.rb @@ -468,8 +468,53 @@ class BuildServer return result end + def gen_db() + case @db_dsn + when /^SQLite3:/ then puts "SQLite3 DB#{@db_dsn.split(':')[1]} generating" + when /^Mysql:/ then + name = nil + host = nil + port = nil + socket = nil + flag = nil + dsn = @db_dsn.split(':') + if dsn[2].nil? then + dsn[1].split(';').each do |attr| + case attr.split('=')[0].strip.eql? "database" + when /database/i then + name = attr.split('=')[1].strip + when /host/i then + host = attr.split('=')[1].strip + when /port/i then + port = attr.split('=')[1].strip + when /socket/i then + socket = attr.split('=')[1].strip + when /flag/i then + flag = attr.split('=')[1].strip + else + etc = attr.split('=')[1].strip + end + end + else + name = dsn[1].strip + host = dsn[2].strip + end + if host.eql? "localhost" or host.eql? "127.0.0.1" then + File.open("create_db.txt","w") do |f| + f.puts "GRANT ALL ON #{name}.* TO '#{@db_user}'@'#{host}' IDENTIFIED BY '#{@db_passwd}';" + f.puts "CREATE DATABASE #{name};" + end + socket_str = "" + socket_str = "--socket=#{socket}" if not socket.nil? + puts "Mysql DB #{name} generating" + system("mysql -h #{host} #{socket_str} -u #{@db_user} --password=#{@db_passwd} < create_db.txt") + end + else puts "not support DB #{@db_dsn}" + end + end def create_db() + gen_db() result = get_db_connection() do |db| case @db_dsn when /^SQLite3:/ then inc="AUTOINCREMENT" -- 2.34.1