59 lines
1.6 KiB
JavaScript
59 lines
1.6 KiB
JavaScript
const NULL_UUID = '00000000-0000-0000-0000-000000000000';
|
|
|
|
exports.up = async knex => {
|
|
await knex.schema.createTable('games', table => {
|
|
table.uuid('id').primary();
|
|
table.index('id');
|
|
table.timestamps();
|
|
table.binary('data').notNullable();
|
|
});
|
|
|
|
await knex.schema.createTable('instances', table => {
|
|
table.uuid('id').primary();
|
|
table.index('id');
|
|
table.timestamps();
|
|
|
|
table.binary('data').notNullable();
|
|
table.boolean('open')
|
|
.defaultTo(true)
|
|
.notNullable();
|
|
|
|
await knex.schema.raw(
|
|
// eslint-disable-next-line max-len
|
|
'CREATE UNIQUE INDEX instances_joinable ON instances WHERE open = true;'
|
|
);
|
|
});
|
|
|
|
await knex.schema.createTable('players', table => {
|
|
table.uuid('id').primary();
|
|
table.index('id');
|
|
|
|
// 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']);
|
|
|
|
});
|
|
|
|
// not really sure if this is a good idea
|
|
await knex('instances').insert({
|
|
id: NULL_UUID,
|
|
data: 'INVALID',
|
|
joinable: false,
|
|
});
|
|
};
|
|
|
|
exports.down = async () => {}; |