默认情况下,当您创建一个新的Adonisjs项目时,已经有了一个具有所需值的现成令牌模型迁移。我把它删了。如何恢复此迁移?
发布于 2021-04-22 21:28:56
好吧,我必须创建一个新的项目,并从那里开始(我只是想有某种命令来恢复令牌迁移)。令牌迁移:
'use strict'
/** @type {import('@adonisjs/lucid/src/Schema')} */
const Schema = use('Schema')
class TokensSchema extends Schema {
up () {
this.create('tokens', (table) => {
table.increments()
table.integer('user_id').unsigned().references('id').inTable('users')
table.string('token', 255).notNullable().unique().index()
table.string('type', 80).notNullable()
table.boolean('is_revoked').defaultTo(false)
table.timestamps()
})
}
down () {
this.drop('tokens')
}
}
module.exports = TokensSchema用户模型:
'use strict'
/** @type {import('@adonisjs/framework/src/Hash')} */
const Hash = use('Hash')
/** @type {typeof import('@adonisjs/lucid/src/Lucid/Model')} */
const Model = use('Model')
class User extends Model {
static boot () {
super.boot()
/**
* A hook to hash the user password before saving
* it to the database.
*/
this.addHook('beforeSave', async (userInstance) => {
if (userInstance.dirty.password) {
userInstance.password = await Hash.make(userInstance.password)
}
})
}
/**
* A relationship on tokens is required for auth to
* work. Since features like `refreshTokens` or
* `rememberToken` will be saved inside the
* tokens table.
*
* @method tokens
*
* @return {Object}
*/
tokens () {
return this.hasMany('App/Models/Token')
}
}
module.exports = Userhttps://stackoverflow.com/questions/67204684
复制相似问题