import BaseSchema from '@ioc:Adonis/Lucid/Schema'

export default class extends BaseSchema {
    protected tableName = 'sign_in_records'

    public async up() {
        this.schema.createTable(this.tableName, (table) => {
            table.increments('id')
            table.datetime('created_at', { useTz: true })
            table.datetime('updated_at', { useTz: true })
            table.date('date').notNullable()
            table.integer('user_id').unsigned().references('users.id').onDelete('CASCADE')
            table.decimal('reward', 19, 4).notNullable()

            table.unique(['date', 'user_id'])
        })
    }

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