【发布时间】:2018-02-02 22:02:05
【问题描述】:
我一直在尝试使用 Knex.js 在我的表中的一列上添加 GIN 索引,但我无法做到这一点。我正在尝试做这样的事情-
exports.up = function(knex, Promise) {
return knex.schema.createTable('prediction_models', function(table){
table.increments('id');
table.string('model_name').index();
table.jsonb('model_params');
table.timestamp('createdAt').defaultTo(knex.fn.now());
})
.then(createGinIndex());
function createGinIndex() {
return knex.raw('CREATE INDEX modelgin ON public.prediction_models USING GIN (model_params);');
}
};
exports.down = function(knex, Promise) {
return knex.schema.dropTable('prediction_models');
};
我正在使用 PostgreSQL 数据库。谁能告诉我这是否是实现这一点的正确方法?如果是,我的代码有什么问题,如果不是,如何实现?谢谢!
【问题讨论】:
标签: javascript node.js postgresql knex.js