This commit is contained in:
ntr
2019-02-21 12:05:27 +11:00
parent 94eb259409
commit 613444d066
8 changed files with 311 additions and 129 deletions
+36 -13
View File
@@ -1,35 +1,58 @@
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('joinable')
.defaultTo(true)
.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 game itself
table.uuid('game').notNullable()
table.foreign('game')
.references('id')
.inTable('games')
.onDelete('CASCADE');
table.index('game');
// 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');
.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,
});
};
-36
View File
@@ -1,36 +0,0 @@
const NULL_UUID = '00000000-0000-0000-0000-000000000000';
exports.up = async knex => {
await knex.schema.createTable('vbox', table => {
table.timestamps();
table.uuid('id').primary();
table.uuid('account').notNullable()
table.uuid('game').notNullable()
table.binary('data').notNullable();
table.foreign('game')
.references('id')
.inTable('games')
.onDelete('CASCADE');
table.foreign('account')
.references('id')
.inTable('accounts')
.onDelete('CASCADE');
table.index('id');
table.index('account');
table.unique(['account', 'game']);
});
// not really sure if this is a good idea
await knex('games').insert({
id: NULL_UUID,
data: 'INVALID',
joinable: false,
});
return true;
};
exports.down = async () => {};