💡️ Tip: If you are creating an index on a single column, you can use the Column Index Shorthand syntax on the Column.
return [
'users' => [
'columns' => [
...
],
'indexes' => [
'users' => [
'type' => IndexType::unique,
'indexColumns' => [
'team_id',
'email',
],
],
],
],
],
];
Property | Description | Type |
---|---|---|
<array key> | Name of the index | string |
type |
Type of the index (see below) | IndexType enum |
indexColumns |
Array of column names for the index | array |
The following index types are supported in the IndexType enum.
IndexType::index
IndexType::fullText
IndexType::primary
IndexType::spatialIndex
(⚠️ untested)IndexType::unique
For more details, see the Laravel documentation on index types.
💡If your index is on a single column, you can use the Column Index Shorthand syntax on the column definition.
To create a new index, add a new entry to the indexes
array in the schema definition.
return [
'users' => [
'columns' => [
...
],
'indexes' => [
+ 'users' => [
+ 'type' => IndexType::unique,
+ 'indexColumns' => [
+ 'team_id',
+ 'email',
+ ],
+ ],
],
],
];
Then run the Diff command to generate the migrations.
realoquentId
property. Realoquent will add this automatically.
To delete an index, simply remove the array key from the schema.php
file and run the Diff command.
To change an index name, simply change the array key in the schema.php
file and run the Diff command.
'indexes' => [
- 'users' => [
+ 'users_unqiue_team_email' => [
'type' => IndexType::unique,
'indexColumns' => [
'team_id',
'email',
],
],
],
See Laravel documentation for which databases support index renames.