exports.up = function(knex) {
  return knex.schema.createTable('payment', (table) => {
    table.increments();
    table.timestamps(true, true);

    // don't use an enum here because we will add random services later
    table.string('system', '10').notNull();

    // only four states really needed in most payment systems
    table.enum('status', ['pending', 'complete', 'failed', 'refunded']).notNull().default('pending');

    // this is *our* internal id that we give to the payment system
    table.uuid('internal_id').notNull();

    // there should always be a way to access the record in every system
    table.string('sys_primary_id').notNull();

    // this might not exist in some systems, so allow null
    table.string('sys_secondary_id');

    // not sure if this should be nullable or not
    table.datetime('sys_created_on').notNull();

    table.index('internal_id');
    table.index('sys_primary_id');
    table.index('sys_secondary_id');
  });
};

exports.down = function(knex) {
  return knex.schema.dropTable('payment');
};
