Skip to content

Instantly share code, notes, and snippets.

@MihaelIsaev
Created January 9, 2020 12:41
Show Gist options
  • Save MihaelIsaev/78292a8b5ac0c894b4de9e8f3e5cca37 to your computer and use it in GitHub Desktop.
Save MihaelIsaev/78292a8b5ac0c894b4de9e8f3e5cca37 to your computer and use it in GitHub Desktop.
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