Vapor4.0数据库增加字段

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
16
struct 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
13
struct 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