Skip to content

Instantly share code, notes, and snippets.

@kevinbreaker
Last active September 13, 2019 15:09
Show Gist options
  • Save kevinbreaker/457e5b9ede3576a057f4dc8929f807d1 to your computer and use it in GitHub Desktop.
Save kevinbreaker/457e5b9ede3576a057f4dc8929f807d1 to your computer and use it in GitHub Desktop.
Minhas migrations
'use strict'
/** @type {import('@adonisjs/lucid/src/Schema')} */
const Schema = use('Schema')
class AvaliationsSchema extends Schema {
up () {
this.create('avaliations', (table) => {
table.increments()
table
.string('user_email')
.unsigned()
.notNullable()
.references('id')
.inTable('users')
.onUpdate('CASCADE')
.onDelete('CASCADE')
table.string('comment', 400),
table.string('placeId', 255).notNullable()
table.integer('rating', 5).defaultTo(0)
table.timestamps()
})
}
down () {
this.drop('avaliations')
}
}
module.exports = AvaliationsSchema
'use strict'
/** @type {import('@adonisjs/lucid/src/Schema')} */
const Schema = use('Schema')
class FavoritesSchema extends Schema {
up () {
this.create('favorites', (table) => {
table.increments()
table
.integer('user_id')
.unsigned()
.notNullable()
.references('id')
.inTable('users')
.onUpdate('CASCADE')
.onDelete('CASCADE')
table.string('placeId', 255).notNullable()
table.string('placeName', 255).notNullable()
table.string('placeIcon', 255)
table.timestamps()
})
}
down () {
this.drop('favorites')
}
}
module.exports = FavoritesSchema
'use strict'
/** @type {import('@adonisjs/lucid/src/Schema')} */
const Schema = use('Schema')
class UserSchema extends Schema {
up () {
this.create('users', (table) => {
table.increments()
table.string('name', 80).notNullable()
table.string('email', 254).notNullable().unique()
table.string('password', 60).notNullable()
table.timestamps()
})
}
down () {
this.drop('users')
}
}
module.exports = UserSchema
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment