UNPKG

831 BPlain TextView Raw
1import BaseSchema from '@ioc:Adonis/Lucid/Schema'
2
3export default class {{ tokensSchemaName }} extends BaseSchema {
4 protected tableName = '{{ tokensTableName }}'
5
6 public async up() {
7 this.schema.createTable(this.tableName, (table) => {
8 table.increments('id').primary()
9 table.integer('user_id').unsigned().references('id').inTable('{{ usersTableName }}').onDelete('CASCADE')
10 table.string('name').notNullable()
11 table.string('type').notNullable()
12 table.string('token', 64).notNullable().unique()
13
14 /**
15 * Uses timestampz for PostgreSQL and DATETIME2 for MSSQL
16 */
17 table.timestamp('expires_at', { useTz: true }).nullable()
18 table.timestamp('created_at', { useTz: true }).notNullable()
19 })
20 }
21
22 public async down() {
23 this.schema.dropTable(this.tableName)
24 }
25}