/**
 * @param { import("knex").Knex } knex
 * @returns { Promise<void> }
 */
exports.up = function(knex) {
    // Check if environment is development
    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('alias', function(table) {
        table.string('address', 255).primary();
        table.text('goto').notNullable();
        table.string('domain', 255).notNullable();
        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.comment('Postfix Admin - Virtual Aliases');
        table.index('domain');
    });
};

/**
 * @param { import("knex").Knex } knex
 * @returns { Promise<void> }
 */
exports.down = function(knex) {
    // Check if environment is development
    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('alias');
};