Fix migration

Signed-off-by: Arthur DANJOU <arthurdanjou@outlook.fr>
This commit is contained in:
2021-07-03 18:46:51 +02:00
parent debaac81a6
commit cc049e675a
8 changed files with 0 additions and 169 deletions

View File

@@ -1,36 +0,0 @@
import BaseSchema from '@ioc:Adonis/Lucid/Schema'
import Hash from "@ioc:Adonis/Core/Hash";
export default class Users extends BaseSchema {
protected tableName = 'users'
public async up () {
this.schema.createTable(this.tableName, (table) => {
table.increments('id').primary()
table.string('username', 255).notNullable()
table.string('email', 255).notNullable()
table.string('password', 180).defaultTo(this.randomPassword()).notNullable()
table.boolean('is_confirmed').defaultTo(false).notNullable()
table.string('remember_me_token').defaultTo(null).nullable()
table.string('confirmation_token').defaultTo(null).nullable()
table.timestamps(true, true)
})
}
private randomPassword(): string {
let password = ''
const char = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!.:=+-_$*^&@#%ù/àçè()é"'
const size = 64
for (let i = 0; i < size; i++) {
password += char.charAt(Math.random() * char.length)
}
Hash.make(password).then((value => {
password = value
}))
return password
}
public async down () {
this.schema.dropTable(this.tableName)
}
}