Last active
September 1, 2022 20:56
-
-
Save aronbudinszky/8dcce4fae605dd2699c0d4c1642f6793 to your computer and use it in GitHub Desktop.
Part of Medium article: https://medium.com/hoursofoperation/add-indexes-to-your-fluent-sql-databases-in-vapor-784f6b29a83f
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Fluent | |
import SQLKit | |
struct CreateVersionsCreatedAtIndex: AsyncMigration { | |
func prepare(on database: Database) async throws { | |
try await (database as! SQLDatabase) | |
.create(index: "versions_created_at_index") // Index name | |
.on("versions") // Table name | |
.column("created_at") | |
// You can also add more columns here if you want a multi-column index... | |
.run() | |
} | |
func revert(on database: Database) async throws { | |
try await (database as! SQLDatabase) | |
.drop(index: "versions_created_at_index") | |
.run() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment