From be62e239c93c4d89b35b2b794ae2772116089845 Mon Sep 17 00:00:00 2001 From: gdkhd812 Date: Sat, 31 May 2014 18:55:29 +0900 Subject: [PATCH] =?utf8?q?name=5Fhash=E3=81=AF=E8=A2=AB=E3=82=8B=E5=8F=AF?= =?utf8?q?=E8=83=BD=E6=80=A7=E3=81=8C=E3=81=82=E3=82=8B=E3=81=AE=E3=81=A7?= =?utf8?q?=E3=80=81primary=E3=81=A7=E3=81=AF=E3=81=AA=E3=81=8Findex?= =?utf8?q?=E3=82=92=E6=8C=87=E5=AE=9A=E3=81=99=E3=82=8B=E3=82=88=E3=81=86?= =?utf8?q?=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- configure.js | 1 - init.js | 49 +++++++++++++++++++++++++++++-------------------- init.sql | 1 + 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/configure.js b/configure.js index 9a14799..120ee7e 100644 --- a/configure.js +++ b/configure.js @@ -61,7 +61,6 @@ name : "名前(ハッシュ)", type : "unsignednumber", length : 4, - primary : true, visible : false, visible_edit : false, visible_registor : false, 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; } diff --git a/init.sql b/init.sql index e41a128..5d25fd2 100644 --- a/init.sql +++ b/init.sql @@ -3,6 +3,7 @@ grant select, delete, create, drop, + index, update on *.* to user identified by 'user'; flush privileges; CREATE DATABASE IF NOT EXISTS webchat DEFAULT CHARSET=utf8; -- 2.11.0