/**
 * @param { import("knex").Knex } knex
 * @returns { Promise<void> }
 */
exports.up = function(knex) {  
  const env = process.env.NODE_ENV || 'development';
    if (env !== 'development') {
        console.warn('This migration is only meant to run in development environment');
        return Promise.resolve();
    }
    return knex.schema.createTable('domain', function(table) {
        table.string('domain', 255).primary();
        table.string('description', 255).notNullable();
        table.integer('aliases').notNullable().defaultTo(0);
        table.integer('mailboxes').notNullable().defaultTo(0);
        table.bigInteger('maxquota').notNullable().defaultTo(0);
        table.bigInteger('quota').notNullable().defaultTo(0);
        table.string('transport', 255).notNullable();
        table.boolean('backupmx').notNullable().defaultTo(0);
        table.datetime('created').notNullable().defaultTo('2000-01-01 00:00:00');
        table.datetime('modified').notNullable().defaultTo('2000-01-01 00:00:00');
        table.boolean('active').notNullable().defaultTo(1);
        table.integer('password_expiry').notNullable().defaultTo(0);

        table.comment('Postfix Admin - Virtual Domains');
    });
};

/**
 * @param { import("knex").Knex } knex
 * @returns { Promise<void> }
 */
exports.down = function(knex) {
  const env = process.env.NODE_ENV || 'development';
    if (env !== 'development') {
        console.warn('This migration is only meant to run in development environment');
        return Promise.resolve();
    }
  return knex.schema.dropTable('domain');
};