1700559209029_api_tokens.ts 846 B

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