I have some existing columns in my table that I want to add an index on. How can I proceed? From the documentation it says:
table..index([indexName], [indexType]) // Specifies column as an index.
But what does indexName mean?
I have some existing columns in my table that I want to add an index on. How can I proceed? From the documentation it says:
table..index([indexName], [indexType]) // Specifies column as an index.
But what does indexName mean?
I should have head over to the Knex.js documentation.
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.
Here is how I did it:
/**************************************************************************
* 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