Skip to content

Commit feac4d8

Browse files
committed
doc/indexes: add annotations supported by atlasgo.io
1 parent 36a1063 commit feac4d8

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

doc/md/schema-indexes.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,49 @@ CREATE INDEX `users_description` ON `users`(`description`(128))
212212
CREATE INDEX `users_c1_c2_c3` ON `users`(`c1`(100), `c2`(200), `c3`)
213213
```
214214

215+
## Atlas Support
216+
217+
Starting with v0.10, Ent supports running migration with [Atlas](migrate.md#atlas-integration). This option provides
218+
more control on indexes such as, configuring their types or define indexes in a reverse order.
219+
```go
220+
func (User) Indexes() []ent.Index {
221+
return []ent.Index{
222+
index.Fields("c1").
223+
Annotations(entsql.Desc()),
224+
index.Fields("c1", "c2", "c3").
225+
Annotation(entsql.DescColumns("c1", "c2")),
226+
index.Fields("c4").
227+
Annotations(entsql.IndexType("HASH")),
228+
// Enable FULLTEXT search on MySQL,
229+
// and GIN on PostgreSQL.
230+
index.Fields("c5").
231+
Annotations(
232+
entsql.IndexTypes(map[string]string{
233+
dialect.MySQL: "FULLTEXT",
234+
dialect.Postgres: "GIN",
235+
}),
236+
),
237+
}
238+
}
239+
```
240+
241+
The code above generates the following SQL statements:
242+
243+
```sql
244+
CREATE INDEX `users_c1` ON `users` (`c1` DESC)
245+
246+
CREATE INDEX `users_c1_c2_c3` ON `users` (`c1` DESC, `c2` DESC, `c3`)
247+
248+
CREATE INDEX `users_c4` ON `users` USING HASH (`c4`)
249+
250+
-- MySQL only.
251+
CREATE FULLTEXT INDEX `users_c5` ON `users` (`c5`)
252+
253+
-- PostgreSQL only.
254+
CREATE INDEX `users_c5` ON `users` USING GIN (`c5`)
255+
```
256+
257+
215258
## Storage Key
216259

217260
Like Fields, custom index name can be configured using the `StorageKey` method.

0 commit comments

Comments
 (0)