1 var util = require("util");
2 var config = require("./configure.js");
3 var async = require("async");
5 var MySQLPool = new require("./mysql_pool.js");
6 var pool = new MySQLPool({
9 password : config.db_password,
10 port : config.db_port,
14 if("name_hash" in config.alias)
16 if(config.alias["name_hash"].type != "unsignednumber")
17 throw "name_hashの型はunsignednumberでなければなりません";
19 throw "name_hashが存在しません";
22 if("name" in config.alias)
24 if(config.alias["name"].type != "text")
25 throw "nameの型はtextでなければなりません";
30 if("password" in config.alias)
32 if(config.alias["password"].type != "password")
33 throw "nameの型はpasswordでなければなりません";
35 throw "passwordが存在しません";
38 if("lastmodified" in config.alias)
40 if(config.alias["lastmodified"].type != "datetime")
41 throw "lastmodifiedの型はtextでなければなりません";
43 throw "lastmodifiedが存在しません";
48 var query = GetDropTableQuery("profilelist");
49 pool.query(query,null,next);
51 function(result,next){
52 var query = GetCreateQuery(config.alias,"profilelist");
53 pool.query(query,null,next);
55 function(result,next){
56 var query = GetDropTableQuery("ipbanlist");
57 pool.query(query,null,next);
59 function(result,next){
72 var query = GetCreateQuery(def,"ipbanlist");
73 pool.query(query,null,next);
75 function(result,next){
76 var query = GetDropTableQuery("rooms");
77 pool.query(query,null,next);
79 function(result,next){
83 type : "unsignednumber",
96 var query = GetCreateQuery(def,"rooms");
97 pool.query(query,null,next);
106 function GetDropTableQuery(tablename)
108 var result = util.format("DROP TABLE IF EXISTS %s;",tablename);
115 function GetCreateQuery(def,tablename)
117 var result = "CREATE TABLE " + tablename + "(";
120 if(typeof(def[key].nodefinetable) != "undefined" && def[key].nodefinetable)
122 switch(def[key].type)
125 result += util.format("%s VARCHAR(%d) ",key,def[key].length);
128 result += util.format("%s %s ",key,GetIntType(def[key].length));
130 case "unsignednumber":
131 result += util.format("%s %s UNSIGNED ",key,GetIntType(def[key].length));
134 result += util.format("%s VARCHAR(%d) ",key,def[key].length);
137 result += util.format("%s VARCHAR(%d) ",key,def[key].length);
140 result += util.format("%s TEXT ",key);
143 result += util.format("%s BOOL ",key);
146 result += util.format("%s DATETIME ",key);
149 throw util.format("invaild %s type:%s",key,def[key].type);
151 if(typeof(def[key].isnotempty) != "undefined" && def[key].isnotempty)
152 result += " NOT NULL ";
158 if(typeof(def[key].primary) != "undefined" && def[key].primary)
160 result += util.format("PRIMARY KEY(%s)",key);
171 function GetIntType(len)
183 throw "Invaild Length";