Question is following: How to implement additional migration on already existing table without revert or recreating DB?
Original migration:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16struct CreateTile: Migration {
// Prepares the database for storing Tile models.
func prepare(on database: Database) -> EventLoopFuture<Void> {
database.schema("tiles")
.id()
.field("x", .int, .required)
.field("y", .int, .required)
.field("z", .int, .required)
.create()
}
// Optionally reverts the changes made in the prepare method.
func revert(on database: Database) -> EventLoopFuture<Void> {
database.schema("tiles").delete()
}
}
Now you want to extend the table by additional column called new which is of type Int. Therefore you have to implement new migration.1
2
3
4
5
6
7
8
9
10
11
12
13struct UpdateTile: Migration {
// Prepares the database for storing Tile models.
func prepare(on database: Database) -> EventLoopFuture<Void> {
database.schema("tiles")
.field("new", .int)
.update()
}
// Optionally reverts the changes made in the prepare method.
func revert(on database: Database) -> EventLoopFuture<Void> {
database.schema("tiles").deleteField("new").update()
}
}
Last step is to register your new migration in configure.swift file similar as the original one