chore(release): 0.4.0
[risinglegends.git] / migrations / 20230908160725_dungeons.ts
1 import { Knex } from "knex";
2
3
4 export async function up(knex: Knex): Promise<void> {
5   return knex.schema.createTable('dungeons', function(table) {
6     table.string('id').primary().defaultTo(knex.raw('uuid_generate_v4()'));
7     table.string('name');
8     table.uuid('starting_room');
9   }).createTable('dungeon_rooms', function(table) {
10       table.uuid('id').defaultTo(knex.raw('uuid_generate_v4()')).primary();
11       table.uuid('dungeon_id');
12       table.text('description');
13       table.json('exits').defaultTo(knex.raw("'[]'::json"));
14       table.json('settings').defaultTo('{}');
15     }).createTable('dungeon_things', function(table) {
16       table.uuid('room_id');
17       table.uuid('id').defaultTo(knex.raw('uuid_generate_v4()')).primary();
18       table.string('name');
19       table.json('properties').defaultTo({})
20     }).createTable('dungeon_players', function(table) {
21       table.uuid('player_id').primary();
22       table.uuid('dungeon_id');
23       table.uuid('current_room_id');
24       table.uuid('target_room_id'); // only used when movement is interrupted by a fight
25     }).createTable('dungeon_state', function(table) {
26       table.uuid('id').primary().defaultTo(knex.raw('uuid_generate_v4()'));
27       table.uuid('player_id');
28       table.uuid('dungeon_id');
29       table.string('event_name');
30       table.json('event_props');
31       table.timestamp('create_date').defaultTo(knex.raw('NOW()'))
32       table.index(['player_id', 'dungeon_id']);
33       table.index(['player_id', 'dungeon_id', 'event_name']);
34     })
35 }
36
37
38 export async function down(knex: Knex): Promise<void> {
39   return knex.schema.dropTable('dungeon_rooms')
40                     .dropTable('dungeon_things')
41                     .dropTable('dungeon_players')
42                     .dropTable('dungeon_state')
43                     .dropTable('dungeons');
44 }