wip
This commit is contained in:
@@ -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,
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -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 () => {};
|
||||
Reference in New Issue
Block a user