X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=init.js;fp=init.js;h=392e4bc7b787fb4699d9ea852a0de2573b820de5;hb=be62e239c93c4d89b35b2b794ae2772116089845;hp=cbd80a6e373ec102718d6f877f2f11502640ffb3;hpb=f1b33cf06fa5a63db6715de7ac205c143d3499c3;p=webchat%2FWebChat.git diff --git a/init.js b/init.js index cbd80a6..392e4bc 100644 --- a/init.js +++ b/init.js @@ -40,15 +40,17 @@ module.exports = function(callback){ }else{ throw "lastmodifiedが存在しません"; } + + var Sequelize = require("sequelize"); + var pool = new Sequelize(config.db_name, config.db_user, config.db_password,{ + host:config.db_host, + port:config.db_port + }); + var fs = require("fs"); + async.waterfall([ function(next){ - var Sequelize = require("sequelize"); - var pool = new Sequelize(config.db_name, config.db_user, config.db_password,{ - host:config.db_host, - port:config.db_port - }); - var query = GetCreateQuery(Sequelize,config.alias,"profilelist"); var profilelist = pool.define("profilelist",query); module.exports.GetProfileColletion = profilelist; @@ -62,7 +64,6 @@ module.exports = function(callback){ type:{ type : "text", length : 1, - primary : true, }, }; var query = GetCreateQuery(Sequelize,def,"ipbanlist"); @@ -95,25 +96,33 @@ module.exports = function(callback){ }, function(exists,next){ if(exists) - next(null); + next(true); else fs.open("inited","a",function(err,fd){ fs.closeSync(fd); - - module.exports.GetProfileColletion.drop(); - module.exports.GetProfileColletion.sync(); - - module.exports.GetIpBanColletion.drop(); - module.exports.GetIpBanColletion.sync(); - - module.exports.GetRoomInfomation.drop(); - module.exports.GetRoomInfomation.sync(); - next(null); }); + }, + function(next){ + module.exports.GetProfileColletion.sync({force:true}).done(next); + }, + function(result,next){ + pool.getQueryInterface().addIndex( + module.exports.GetProfileColletion.tableName, + ["name_hash"] + ).done(next); + }, + function(result,next){ + module.exports.GetIpBanColletion.sync({force:true}).done(next); + }, + function(result,next){ + module.exports.GetRoomInfomation.sync({force:true}).done(next); } ],function(err){ - callback(err); + if(err) + callback(null); + else + callback(err); }); } @@ -156,7 +165,7 @@ function GetCreateQuery(Sequelize,def,tablename) } if(typeof(def[key].isnotempty) != "undefined" && def[key].isnotempty) option["allowNull"] = true; - else if(typeof(def[key].primary) != "undefined" && def[key].primary) + if(typeof(def[key].primary) != "undefined" && def[key].primary) option["primaryKey"] = true; result[key] = option; }