exports.up = async knex => {
    await knex.schema.createTable('zones', async (table) => {
        table.uuid('id').primary();
        table.index('id');
        table.timestamps(true, true);

        table.binary('data').notNullable();

        table.boolean('active')
          .defaultTo(true)
          .notNullable();

        table.uuid('account').notNullable()
        table.foreign('account')
          .references('id')
          .inTable('accounts')
          .onDelete('CASCADE');

        table.index('account');

        await knex.schema.raw(
        // eslint-disable-next-line max-len
            'CREATE UNIQUE INDEX zones_account_active ON zones (account) WHERE active = true;'
        );
    });
};

exports.down = async () => {};