Last active
November 29, 2018 16:44
-
-
Save natebird/f16c30895c6b2a62c0c1251cf4b07730 to your computer and use it in GitHub Desktop.
Vapor database migration examples using addProperties function
This file contains hidden or 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
extension Quote: Migration { | |
static func prepare(on connection: PostgreSQLConnection) -> Future<Void> { | |
return Database.create(self, on: connection) { builder in | |
// Add fields from above | |
try addProperties(to: builder) | |
// Add FOREIGN KEY reference | |
builder.reference(from: \.authorID, to: \Author.id) | |
// make content UNIQUE and indexed | |
builder.unique(on: \.content) | |
} | |
} | |
} |
This file contains hidden or 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
extension Quote: Migration { | |
static func prepare(on connection: PostgreSQLConnection) -> Future<Void> { | |
return Database.create(self, on: connection) { builder in | |
builder.field(for: \.id, type: .uuid) | |
builder.field(for: \.content) | |
builder.field(for: \.authorID, type: .uuid) | |
builder.field(for: \.createdAt) | |
builder.field(for: \.updatedAt) | |
// Add FOREIGN KEY reference | |
builder.reference(from: \.authorID, to: \Author.id) | |
// make content UNIQUE and indexed | |
builder.unique(on: \.content) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment