-var util = require("util");
+var util = require("util");
var config = require("./configure.js");
-var async = require("async");
-var MySQLPool = new require("./mysql_pool.js");
-var pool = new MySQLPool({
- host : config.db_host,
- user : config.db_user,
- password : config.db_password,
- port : config.db_port,
- database : "webchat",
- });
-
-async.waterfall([
- function(next){
- var query = GetDropTableQuery("list");
- pool.query(query,null,next);
- },
- function(result,next){
- var query = GetCreateQuery(config.alias,"list");
- pool.query(query,null,next);
- },
- function(result,next){
- var query = GetDropTableQuery("ipbanlist");
- pool.query(query,null,next);
- },
- function(result,next){
- var def = {
- ip:{
- type : "text",
- length : 64,
- primary : true,
- },
- type:{
- type : "text",
- length : 1,
- primary : true,
- },
- };
- var query = GetCreateQuery(def,"ipbanlist");
- pool.query(query,null,next);
- },
- function(result,next){
- var query = GetDropTableQuery("rooms");
- pool.query(query,null,next);
- },
- function(result,next){
- var def = {
- number:
- {
- type : "unsignednumber",
- length:2,
- isnotempty : true,
+module.exports = function(callback){
+ var async = require("async");
+
+ var MySQLPool = new require("./mysql_pool.js");
+ var pool = new MySQLPool({
+ host : config.db_host,
+ user : config.db_user,
+ password : config.db_password,
+ port : config.db_port,
+ database : config.db_name,
+ });
+
+ if("name_hash" in config.alias)
+ {
+ if(config.alias["name_hash"].type != "unsignednumber")
+ throw "name_hashの型はunsignednumberでなければなりません";
+ }else{
+ throw "name_hashが存在しません";
+ }
+
+ if("name" in config.alias)
+ {
+ if(config.alias["name"].type != "text")
+ throw "nameの型はtextでなければなりません";
+ }else{
+ throw "nameが存在しません";
+ }
+
+ if("password" in config.alias)
+ {
+ if(config.alias["password"].type != "password")
+ throw "nameの型はpasswordでなければなりません";
+ }else{
+ throw "passwordが存在しません";
+ }
+
+ if("lastmodified" in config.alias)
+ {
+ if(config.alias["lastmodified"].type != "datetime")
+ throw "lastmodifiedの型はtextでなければなりません";
+ }else{
+ throw "lastmodifiedが存在しません";
+ }
+
+ async.waterfall([
+ function(next){
+ var query = GetDropTableQuery("profilelist");
+ pool.query(query,null,next);
+ },
+ function(result,next){
+ var query = GetCreateQuery(config.alias,"profilelist");
+ pool.query(query,null,next);
+ },
+ function(result,next){
+ var query = GetDropTableQuery("ipbanlist");
+ pool.query(query,null,next);
+ },
+ function(result,next){
+ var def = {
+ ip:{
+ type : "text",
+ length : 64,
primary : true,
},
- password:{
- type : "text",
- length : 16,
- },
- hiddenlog:{
- type : "bool",
- },
- };
- var query = GetCreateQuery(def,"rooms");
- pool.query(query,null,next);
- },
-],function(err){
- console.log(err);
- process.exit();
-});
-
+ type:{
+ type : "text",
+ length : 1,
+ primary : true,
+ },
+ };
+ var query = GetCreateQuery(def,"ipbanlist");
+ pool.query(query,null,next);
+ },
+ function(result,next){
+ var query = GetDropTableQuery("rooms");
+ pool.query(query,null,next);
+ },
+ function(result,next){
+ var def = {
+ number:
+ {
+ type : "unsignednumber",
+ length:2,
+ isnotempty : true,
+ primary : true,
+ },
+ password:{
+ type : "text",
+ length : 16,
+ },
+ hiddenlog:{
+ type : "bool",
+ },
+ };
+ var query = GetCreateQuery(def,"rooms");
+ pool.query(query,null,next);
+ },
+ ],callback);
+}
function GetDropTableQuery(tablename)
{
var result = "CREATE TABLE " + tablename + "(";
for(key in def)
{
+ if(typeof(def[key].nodefinetable) != "undefined" && def[key].nodefinetable)
+ continue;
switch(def[key].type)
{
case "text":