Created
January 9, 2020 12:41
-
-
Save MihaelIsaev/78292a8b5ac0c894b4de9e8f3e5cca37 to your computer and use it in GitHub Desktop.
This file contains 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 FluentKit | |
import Vapor | |
final class Todo: Model, Content { | |
static let schema = "todos" | |
@iID(key: "id", .uuid, .identifier(auto: false)) | |
var id: UUID? | |
@iField(key: "title", .string, .required) | |
var title: String | |
@iTimestamp(key: "created_at", on: .create) | |
public var createdAt: Date? | |
@iTimestamp(key: "updated_at", on: .update) | |
public var updatedAt: Date? | |
init() { } | |
init(id: UUID? = nil, title: String) { | |
self.id = id | |
self.title = title | |
} | |
} | |
extension Todo: Migration { | |
func prepare(on database: Database) -> EventLoopFuture<Void> { | |
create(on: database) { | |
\.$id | |
\.$title | |
\.$createdAt | |
\.$updatedAt | |
} | |
} | |
func revert(on database: Database) -> EventLoopFuture<Void> { | |
database.schema(Self.schema).delete() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment