Skip to content
Snippets Groups Projects
1698869795066_users.ts 864 B
Newer Older
Thomas SAUVAGE's avatar
Thomas SAUVAGE committed
import BaseSchema from '@ioc:Adonis/Lucid/Schema'

export default class extends BaseSchema {
Thomas SAUVAGE's avatar
Thomas SAUVAGE committed
  protected tableName = 'users'
Thomas SAUVAGE's avatar
Thomas SAUVAGE committed

  public async up() {
    this.schema.createTable(this.tableName, (table) => {
      table.increments('id').primary()
Thomas SAUVAGE's avatar
Thomas SAUVAGE committed

Thomas SAUVAGE's avatar
Thomas SAUVAGE committed
      table.string('username', 255).notNullable().unique()
Thomas SAUVAGE's avatar
Thomas SAUVAGE committed
      table.string('name', 255).notNullable()
      table.specificType('groups', 'text[]').notNullable()

      table.string('password', 180)

      table.boolean('is_sigma_user').notNullable()
Thomas SAUVAGE's avatar
Thomas SAUVAGE committed
      table.boolean('is_admin').notNullable().defaultTo(false)
Thomas SAUVAGE's avatar
Thomas SAUVAGE committed

      /**
       * Uses timestampz for PostgreSQL and DATETIME2 for MSSQL
       */
      table.timestamp('created_at', { useTz: true }).notNullable()
      table.timestamp('updated_at', { useTz: true }).notNullable()
    })
  }

  public async down() {
    this.schema.dropTable(this.tableName)
  }
}