Add indexes to your Fluent SQL databases in Vapor
Vapor’s Fluent ORM allows you to easily create models as Swift structs that correspond to your SQL database tables. The database schema is generally defined as a migration to automatomatically create and update your database table in accordance with your app’s models.
You will find some documentation on Vapor’s site on how to perform basic database migrations, but a lot is missing — including how to add indexes to your database tables.
Though not directly supported by Fluent, the Migrations API allows you to drop to lower-level APIs easily. As such you can use `SQLKit` to add a migration like so:
Finally, don’t forget to add the struct to your migrations:
app.migrations.add(CreateVersionsCreatedAtIndex())