我的nodejs / sequelizejs(5.7.6)/ postgres(11.2)应用程序具有一个套接字列表模型,该模型最近进行了如下更新:
const SocketList = db.define('socketlist', {
user_ids: {type: Sql.ARRAY(Sql.INTEGER),
},
fort_token: {
type: Sql.STRING
},
server_id: {type: Sql.STRING
},
}, {
timestamps: false,
indexes: [
{
fields: ['fort_token']
},
{
fields: ['server_id']
},
]
});
我正在使用sync
创建数据库表:
db.sync({force:true})
.then((res) => {
console.log("db done!");
console.log(res);
}); //create db
问题在于创建的socketlist
表仍然基于已经更新的旧模式,我不知道sync
在哪里缓存了过时的模式代码。我试图删除整个数据库或表,但结果始终相同-旧的和过时的架构。到目前为止,sync
一直运行良好。是sequelizejs
的错误吗?代码有什么问题?
findOne()
也使用过时的架构,如控制台输出所示:
Socketio server is initialized
Executing (default): SELECT "id", "user_id", "socket_id", "event_id", "server_id", "active" FROM "socketlists" AS "socketlist" WHERE "socketlist"."fort_token" = '12345678901234567890' LIMIT 1;
我卸下并重新安装了sequelize
,问题仍然存在。
这是数据库连接:
const Sql = require("sequelize");
const db = new Sql('myDB', 'postgres', `${process.env.DB_PASSWORD}`, {
host: 'localhost',
dialect: 'postgres',
port:5433,
} );
这是旧的(过时的)SocketList模式:
const Sql = require("sequelize");
//const Op = Sql.Op;
const db = require("../startup/db");
const Joi = require('joi');
const SocketList = db.define('socketlist', {
id: {type: Sql.INTEGER,
primaryKey:true,
autoIncrement: true,
min: 1
},
socket_id: {type: Sql.STRING,
min: 1
},
event_id: {type: Sql.INTEGER,
min: 1
},
server_id: {type: Sql.STRING
},
active: {type: Sql.BOOLEAN,
defaultValue: true,
},
}, {
timestamps: false
}, {
indexes: [
{
//socket_id
fields: ['socket_id']
},
{
fields: ['active']
},
{
fields: ['server_id']
},
{
fields: ['event_id']
},
]
});
module.exports.SocketList = SocketList;