1 var util = require("util");
2 var config = require("./configure.js");
4 module.exports = function(callback){
5 var async = require("async");
7 var MySQLPool = new require("./mysql_pool.js");
8 var pool = new MySQLPool({
10 user : config.db_user,
11 password : config.db_password,
12 port : config.db_port,
13 database : config.db_name,
16 if("name_hash" in config.alias)
18 if(config.alias["name_hash"].type != "unsignednumber")
19 throw "name_hashの型はunsignednumberでなければなりません";
21 throw "name_hashが存在しません";
24 if("name" in config.alias)
26 if(config.alias["name"].type != "text")
27 throw "nameの型はtextでなければなりません";
32 if("password" in config.alias)
34 if(config.alias["password"].type != "password")
35 throw "nameの型はpasswordでなければなりません";
37 throw "passwordが存在しません";
40 if("lastmodified" in config.alias)
42 if(config.alias["lastmodified"].type != "datetime")
43 throw "lastmodifiedの型はtextでなければなりません";
45 throw "lastmodifiedが存在しません";
50 var query = GetDropTableQuery("profilelist");
51 pool.query(query,null,next);
53 function(result,next){
54 var query = GetCreateQuery(config.alias,"profilelist");
55 pool.query(query,null,next);
57 function(result,next){
58 var query = GetDropTableQuery("ipbanlist");
59 pool.query(query,null,next);
61 function(result,next){
74 var query = GetCreateQuery(def,"ipbanlist");
75 pool.query(query,null,next);
77 function(result,next){
78 var query = GetDropTableQuery("rooms");
79 pool.query(query,null,next);
81 function(result,next){
85 type : "unsignednumber",
98 var query = GetCreateQuery(def,"rooms");
99 pool.query(query,null,next);
104 function GetDropTableQuery(tablename)
106 var result = util.format("DROP TABLE IF EXISTS %s;",tablename);
113 function GetCreateQuery(def,tablename)
115 var result = "CREATE TABLE " + tablename + "(";
118 if(typeof(def[key].nodefinetable) != "undefined" && def[key].nodefinetable)
120 switch(def[key].type)
123 result += util.format("%s VARCHAR(%d) ",key,def[key].length);
126 result += util.format("%s %s ",key,GetIntType(def[key].length));
128 case "unsignednumber":
129 result += util.format("%s %s UNSIGNED ",key,GetIntType(def[key].length));
132 result += util.format("%s VARCHAR(%d) ",key,def[key].length);
135 result += util.format("%s VARCHAR(%d) ",key,def[key].length);
138 result += util.format("%s TEXT ",key);
141 result += util.format("%s BOOL ",key);
144 result += util.format("%s DATETIME ",key);
147 throw util.format("invaild %s type:%s",key,def[key].type);
149 if(typeof(def[key].isnotempty) != "undefined" && def[key].isnotempty)
150 result += " NOT NULL ";
156 if(typeof(def[key].primary) != "undefined" && def[key].primary)
158 result += util.format("PRIMARY KEY(%s)",key);
169 function GetIntType(len)
181 throw "Invaild Length";