mnml/ops/migrations/20181020104420_games.js
2019-07-27 19:24:52 +10:00

55 lines
1.4 KiB
JavaScript

exports.up = async knex => {
await knex.schema.createTable('games', table => {
table.uuid('id').primary();
table.index('id');
table.timestamps(true, true);
table.binary('data').notNullable();
table.timestamp('upkeep');
table.boolean('finished')
.defaultTo(false)
.notNullable()
.index();
});
await knex.schema.createTable('instances', async table => {
table.uuid('id').primary();
table.index('id');
table.timestamps(true, true);
table.binary('data').notNullable();
table.boolean('finished')
.defaultTo(false)
.notNullable()
.index();
table.timestamp('upkeep');
});
await knex.schema.createTable('players', table => {
table.uuid('id').primary();
table.index('id');
table.timestamps(true, true);
// the instance
table.uuid('instance').notNullable()
table.foreign('instance')
.references('id')
.inTable('instances')
.onDelete('CASCADE');
table.index('instance');
// account in a game
table.uuid('account').notNullable()
table.foreign('account')
.references('id')
.inTable('accounts')
.onDelete('CASCADE');
table.index('account');
table.unique(['account', 'instance']);
});
};
exports.down = async () => {};