Skip to content

Instantly share code, notes, and snippets.

@aronbudinszky
Last active October 2, 2022 13:30
Show Gist options
  • Save aronbudinszky/2068622cb09cb2fc125029c7bac21488 to your computer and use it in GitHub Desktop.
Save aronbudinszky/2068622cb09cb2fc125029c7bac21488 to your computer and use it in GitHub Desktop.
Run a custom migration via raw query on a Vapor Fluent database.
struct CustomRawMigration: AsyncMigration {
func prepare(on database: Database) async throws {
try await (database as! SQLDatabase)
.raw("ALTER TABLE `table_name` MODIFY `field_name` ENUM('case1', 'case2', 'case3') DEFAULT 'case1'")
.run()
}
func revert(on database: Database) async throws {
try await (database as! SQLDatabase)
.raw("ALTER TABLE `table_name` MODIFY `field_name` ENUM('case1', 'case2') DEFAULT 'case1'")
.run()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment