我使用 dynamoose 创建了一个简单的模型,现在我想使用 sequelize 将它迁移到 postgresql 中。我熟悉 dynamodb 以及如何在其中设置哈希键和范围键,但是如何使用 sequelize 在 postgresql 中完成相同的操作?下面是我以前使用 dynamoose 的模型以及我使用 sequelize 迁移它的努力,但我不确定如何处理这些键:
//dynamoose
var dynamoose = require("dynamoose");
var MessageRatingSchema = new dynamoose.Schema({
id: {
type: String,
index: {
global: true
}
},
chatId: {
type: String,
hashKey: true
},
ratingType: {
type: String,
enum: ["NEGATIVE", "POSITIVE", "NEUTRAL", "MIXED"],
rangeKey: true
},
rating: {
type: Number
}
});
module.exports = MessageRatingSchema;
尝试使用 sequelize 迁移它:
const Sequelize = require("sequelize");
const sequelize = new Sequelize('PGDATABASE', 'PGUSER', 'PGPASS', {
host: 'localhost',
dialect: 'postgres'
});
const MessageRating = sequelize.define('MessageRating', {
id: {
type: Sequelize.STRING,
primaryKey: true
},
chatId: {
type: Sequelize.STRING
//hashkey
},
ratingType: {
type: Sequelize.STRING,
enum: ["NEGATIVE", "POSITIVE", "NEUTRAL", "MIXED"]
//sortkey
},
rating:{
type: Sequelize.NUMBER
}
}, {
// options
});
module.exports = MessageRating;
请让我知道这是否是正确的方法以及如何使用 sequelize 设置相应的 hashKeys 和 rangeKeys。谢谢你。