adonis.js - Adonis:如何为已存在的列添加索引?
问题描述
我的表中有一些现有的列,我想在这些列上添加索引。我该如何进行?从文档中它说:
table..index([indexName], [indexType]) // 将列指定为索引。
但是 indexName 是什么意思呢?
解决方案
我应该去看 Knex.js 文档。
index — table.index(columns, [indexName], [indexType])
在给定列上向表中添加索引。除非指定 indexName,否则使用使用列的默认索引名称。可以选择为 PostgreSQL 和 MySQL 指定 indexType。Amazon Redshift 不允许创建索引。
这是我的做法:
/**************************************************************************
* IMPORTS
***************************************************************************/
// Providers
const Schema = use('Schema')
/**************************************************************************
* MIGRATIONS
***************************************************************************/
class AddDomainsIndexSchema extends Schema {
up() {
this.table('domains', (table) => {
table.index('domain')
table.index('fetched')
})
}
down() {
this.table('domains', (table) => {
table.dropIndex('domain')
table.dropIndex('fetched')
})
}
}
module.exports = AddDomainsIndexSchema
推荐阅读
- parameters - 我的 Dialogflow 代理的第二个后续意图无法捕获其父参数的值
- html - 在 html 输入中保留初始空格
- python - 矩阵操作:在 numpy 中减去 2D 矩阵和 3D 矩阵
- soap - 创建在生成的请求中显示的评论?WSDL SOAP xml
- python - 在 python 中使用路由器的最佳实践是什么?
- jsf-1.2 - 将 JSF1.2 应用程序从 Jboss 4.2 迁移到 Wildfly 13
- java - IntelliJ IDEA 中的逗号优先 Java 格式
- yii - 获取模块配置参数
- tensorflow - 如何在 Jetson TX1 上更新 Protocol Buffer 运行时库?
- c# - 生成文件路径并修剪“.aspx”