Migrator
addIndex()
Signature
Section titled “Signature”addIndex() — returns void
Available in: migration
Category: Migration Functions
Description
Section titled “Description”Add database index on a table column Only available in a migration CFC
Parameters
Section titled “Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
table | string | yes | — | The table name to perform the index operation on |
columnNames | string | no | — | One or more column names to index, comma separated |
unique | boolean | no | false | If true will create a unique index constraint |
indexName | string | no | — | The name of the index to add: Defaults to table name + underscore + first column name |
Examples
Section titled “Examples”// 1. Add a basic index on a single column
addIndex(table="users", columnNames="email");
// 2. Add a unique index to enforce uniqueness on a column
addIndex(table="members", columnNames="username", unique=true);
// 3. Add a composite index on multiple columns
addIndex(table="orders", columnNames="customerId,createdAt");
// 4. Add an index with a custom index name
// (defaults to tableName_firstColumnName, e.g. "posts_publishedAt")
addIndex(table="posts", columnNames="publishedAt", indexName="idx_posts_published");