Skip to content

Instantly share code, notes, and snippets.

@joshuawright11
Last active August 13, 2020 06:02
Show Gist options
  • Save joshuawright11/5b777408dfef8397c4a681677e2d1d7e to your computer and use it in GitHub Desktop.
Save joshuawright11/5b777408dfef8397c4a681677e2d1d7e to your computer and use it in GitHub Desktop.
Sample migration
struct Sample: Migration {
func up(schema: Schema) {
schema.rename(table: "todos", to: "user_todos")
schema.create(table: "users") {
$0.uuid("id").primary()
$0.string("name").nullable(false)
$0.string("email").nullable(false).unique().index()
$0.uuid("mom").references("id", on: "users")
}
schema.drop(table: "referrals")
schema.alter(table: "tokens") {
$0.rename(column: "createdAt", to: "created_at")
$0.bool("is_expired").default(val: false)
$0.drop(column: "expiry_date")
}
}
func down(schema: Schema) {
schema.drop(table: "users")
}
}
protocol Migration {
func up(schema: Schema)
func down(schema: Schema)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment