Files
artdanj-api/database/migrations/1605093087010_api_tokens.ts
2020-12-16 15:54:29 +01:00

26 lines
793 B
TypeScript

import BaseSchema from '@ioc:Adonis/Lucid/Schema'
export default class ApiTokens extends BaseSchema {
protected tableName = 'api_tokens'
public async up () {
this.schema.createTable(this.tableName, (table) => {
table.increments('id').primary()
table.integer('user_id').unsigned().references('id').inTable('users').onDelete('CASCADE')
table.string('name').notNullable()
table.string('type').notNullable()
table.string('token', 64).notNullable()
/**
* "useTz: true" utilizes timezone option in PostgreSQL and MSSQL
*/
table.timestamp('expires_at', { useTz: true }).nullable()
table.timestamp('created_at', { useTz: true }).notNullable()
})
}
public async down () {
this.schema.dropTable(this.tableName)
}
}