[Title] add Mysql database creation
authorjiil.hyoun <jiil.hyoun@samsung.com>
Tue, 30 Oct 2012 07:30:02 +0000 (16:30 +0900)
committerjiil.hyoun <jiil.hyoun@samsung.com>
Tue, 30 Oct 2012 07:30:02 +0000 (16:30 +0900)
[Type] Feature
[Module] Toolchain /
[Priority] Major
[Jira#]
[Redmine#]
[Problem]
[Cause]
[Solution]
[TestCase]

Change-Id: Idc7ecff6503ca28859ad68203847a23a1980462b

src/build_server/BuildServer.rb

index 2c77ce53d700a3107a39c583d5b4c006ed36747c..4c98eaa53726b8fc89af2b33f2738c8255c40ef5 100644 (file)
@@ -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"