Adonis:如何为已经存在的列添加索引?
Adonis: How to add an index to a column that already exists?
我的 table 中有一些现有的列,我想为其添加索引。我该如何进行?从文档中可以看出:
table..index([indexName], [indexType]) // Specifies column as an index.
但是 indexName 是什么意思?
index — table.index(columns, [indexName], [indexType])
Adds an index to a table over the given columns. A default index name using the columns is used
unless indexName is specified. The indexType can be optionally specified for PostgreSQL and
MySQL. Amazon Redshift does not allow creating an index.
我是这样做的:
/**************************************************************************
* 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
我的 table 中有一些现有的列,我想为其添加索引。我该如何进行?从文档中可以看出:
table..index([indexName], [indexType]) // Specifies column as an index.
但是 indexName 是什么意思?
index — table.index(columns, [indexName], [indexType])
Adds an index to a table over the given columns. A default index name using the columns is used unless indexName is specified. The indexType can be optionally specified for PostgreSQL and MySQL. Amazon Redshift does not allow creating an index.
我是这样做的:
/**************************************************************************
* 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