@takaro/db 0.0.13 → 0.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/migrations/sql/20241012183754-shop-orders-belong-to-player.d.ts +3 -0
- package/dist/migrations/sql/20241012183754-shop-orders-belong-to-player.js +38 -0
- package/dist/migrations/sql/20241012183754-shop-orders-belong-to-player.js.map +1 -0
- package/dist/migrations/sql/20241013173159-add-indexen-for-moduleId.d.ts +3 -0
- package/dist/migrations/sql/20241013173159-add-indexen-for-moduleId.js +52 -0
- package/dist/migrations/sql/20241013173159-add-indexen-for-moduleId.js.map +1 -0
- package/dist/migrations/sql/20241020133133-make-listing-name-required.d.ts +3 -0
- package/dist/migrations/sql/20241020133133-make-listing-name-required.js +13 -0
- package/dist/migrations/sql/20241020133133-make-listing-name-required.js.map +1 -0
- package/dist/migrations/sql/20241024164331-events-fk-fix.d.ts +3 -0
- package/dist/migrations/sql/20241024164331-events-fk-fix.js +14 -0
- package/dist/migrations/sql/20241024164331-events-fk-fix.js.map +1 -0
- package/dist/migrations/sql/20241030130613-index-for-roleId.d.ts +3 -0
- package/dist/migrations/sql/20241030130613-index-for-roleId.js +25 -0
- package/dist/migrations/sql/20241030130613-index-for-roleId.js.map +1 -0
- package/package.json +1 -1
- package/src/migrations/sql/20241012183754-shop-orders-belong-to-player.ts +44 -0
- package/src/migrations/sql/20241013173159-add-indexen-for-moduleId.ts +57 -0
- package/src/migrations/sql/20241020133133-make-listing-name-required.ts +16 -0
- package/src/migrations/sql/20241024164331-events-fk-fix.ts +16 -0
- package/src/migrations/sql/20241030130613-index-for-roleId.ts +31 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export async function up(knex) {
|
|
2
|
+
await knex.schema.alterTable('shopOrder', (table) => {
|
|
3
|
+
table.uuid('playerId').references('id').inTable('players');
|
|
4
|
+
});
|
|
5
|
+
// Migrate existing userId values to playerId by looking up the playerId from users
|
|
6
|
+
const shopOrders = await knex('shopOrder').select('id', 'userId');
|
|
7
|
+
for (const order of shopOrders) {
|
|
8
|
+
const user = await knex('users').where('id', order.userId).first();
|
|
9
|
+
if (user && user.playerId) {
|
|
10
|
+
await knex('shopOrder').where('id', order.id).update('playerId', user.playerId);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
await knex.schema.alterTable('shopOrder', (table) => {
|
|
14
|
+
table.dropColumn('userId');
|
|
15
|
+
table.uuid('playerId').notNullable().alter();
|
|
16
|
+
table.index('playerId');
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
export async function down(knex) {
|
|
20
|
+
// Add userId column back to the shopOrder table
|
|
21
|
+
await knex.schema.alterTable('shopOrder', (table) => {
|
|
22
|
+
table.uuid('userId').references('id').inTable('users');
|
|
23
|
+
});
|
|
24
|
+
// Migrate playerId values back to userId by looking up the user from players
|
|
25
|
+
const shopOrders = await knex('shopOrder').select('id', 'playerId');
|
|
26
|
+
for (const order of shopOrders) {
|
|
27
|
+
const player = await knex('players').where('id', order.playerId).first();
|
|
28
|
+
if (player) {
|
|
29
|
+
await knex('shopOrder').where('id', order.id).update('userId', player.id);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
// Drop playerId column
|
|
33
|
+
await knex.schema.alterTable('shopOrder', (table) => {
|
|
34
|
+
table.dropColumn('playerId');
|
|
35
|
+
table.uuid('userId').notNullable().alter();
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=20241012183754-shop-orders-belong-to-player.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"20241012183754-shop-orders-belong-to-player.js","sourceRoot":"","sources":["../../../src/migrations/sql/20241012183754-shop-orders-belong-to-player.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,KAAK,UAAU,EAAE,CAAC,IAAU;IACjC,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC,KAAK,EAAE,EAAE;QAClD,KAAK,CA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IAEH,6EAA6E;IAC7E,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;IACpE,KAAK,MAAM,KAAK,IAAI,UAAU,EAAE,CAAC;QAC/B,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,CAAC;QACzE,IAAI,MAAM,EAAE,CAAC;YACX,MAAM,IAAI,CAAC,WAAW,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC;QAC5E,CAAC;IACH,CAAC;IAED,uBAAuB;IACvB,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC,KAAK,EAAE,EAAE;QAClD,KAAK,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;QAC7B,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE,CAAC,KAAK,EAAE,CAAC;IAC7C,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// This follows some research done with https://github.com/ankane/pghero
|
|
2
|
+
export async function up(knex) {
|
|
3
|
+
// Remove duplicate indexes
|
|
4
|
+
await knex.schema.alterTable('events', (table) => {
|
|
5
|
+
table.dropIndex('domain', 'events_domain_index');
|
|
6
|
+
});
|
|
7
|
+
await knex.schema.alterTable('items', (table) => {
|
|
8
|
+
table.dropIndex('code', 'items_code_index');
|
|
9
|
+
});
|
|
10
|
+
await knex.schema.alterTable('players', (table) => {
|
|
11
|
+
table.dropIndex('domain', 'players_domain_index');
|
|
12
|
+
});
|
|
13
|
+
// Add indexes
|
|
14
|
+
await knex.schema.alterTable('commands', (table) => {
|
|
15
|
+
table.index('moduleId');
|
|
16
|
+
});
|
|
17
|
+
await knex.schema.alterTable('events', (table) => {
|
|
18
|
+
table.index(['domain', 'createdAt']);
|
|
19
|
+
});
|
|
20
|
+
await knex.schema.alterTable('functions', (table) => {
|
|
21
|
+
table.index('moduleId');
|
|
22
|
+
});
|
|
23
|
+
await knex.schema.alterTable('playerOnGameServer', (table) => {
|
|
24
|
+
table.index(['gameServerId', 'domain']);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
export async function down(knex) {
|
|
28
|
+
// Re-add removed indexes (if needed)
|
|
29
|
+
await knex.schema.alterTable('events', (table) => {
|
|
30
|
+
table.index('domain', 'events_domain_index');
|
|
31
|
+
});
|
|
32
|
+
await knex.schema.alterTable('items', (table) => {
|
|
33
|
+
table.index('code', 'items_code_index');
|
|
34
|
+
});
|
|
35
|
+
await knex.schema.alterTable('players', (table) => {
|
|
36
|
+
table.index('domain', 'players_domain_index');
|
|
37
|
+
});
|
|
38
|
+
// Drop added indexes
|
|
39
|
+
await knex.schema.alterTable('commands', (table) => {
|
|
40
|
+
table.dropIndex('moduleId');
|
|
41
|
+
});
|
|
42
|
+
await knex.schema.alterTable('events', (table) => {
|
|
43
|
+
table.dropIndex(['domain', 'createdAt']);
|
|
44
|
+
});
|
|
45
|
+
await knex.schema.alterTable('functions', (table) => {
|
|
46
|
+
table.dropIndex('moduleId');
|
|
47
|
+
});
|
|
48
|
+
await knex.schema.alterTable('playerOnGameServer', (table) => {
|
|
49
|
+
table.dropIndex(['gameServerId', 'domain']);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=20241013173159-add-indexen-for-moduleId.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"20241013173159-add-indexen-for-moduleId.js","sourceRoot":"","sources":["../../../src/migrations/sql/20241013173159-add-indexen-for-moduleId.ts"],"names":[],"mappings":"AAEA,wEAAwE;AAExE,MAAM,CAAC,KAAK,UAAU,EAAE,CAAC,IAAU;IACj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Q,CAAC,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export async function up(knex) {
|
|
2
|
+
// Set all listings w/o name to 'Unnamed'
|
|
3
|
+
await knex('shopListing').whereNull('name').update({ name: 'Unnamed' });
|
|
4
|
+
await knex.schema.alterTable('shopListing', (table) => {
|
|
5
|
+
table.string('name').notNullable().alter();
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
export async function down(knex) {
|
|
9
|
+
await knex.schema.alterTable('shopListing', (table) => {
|
|
10
|
+
table.string('name').nullable().alter();
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=20241020133133-make-listing-name-required.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"20241020133133-make-listing-name-required.js","sourceRoot":"","sources":["../../../src/migrations/sql/20241020133133-make-listing-name-required.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,KAAK,UAAU,EAAE,CAAC,IAAU;IACjC,yCAAyC;IACzC,MAAM,IAAI,CAAC,aAAa,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;IAExE,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,aAAa,EAAE,CAAC,KAAK,EAAE,EAAE;QACpD,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC,KAAK,EAAE,CAAC;IAC7C,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,IAAI,CAAC,IAAU;IACnC,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,aAAa,EAAE,CAAC,KAAK,EAAE,EAAE;QACpD,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC;IAC1C,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export async function up(knex) {
|
|
2
|
+
// When player, module, gameserver or userId is deleted, keep the event
|
|
3
|
+
await knex.schema.alterTable('events', (table) => {
|
|
4
|
+
table.dropForeign(['actingUserId']);
|
|
5
|
+
table.dropForeign(['actingModuleId']);
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
export async function down(knex) {
|
|
9
|
+
await knex.schema.alterTable('events', (table) => {
|
|
10
|
+
table.foreign('actingUserId').references('id').inTable('users').onDelete('CASCADE');
|
|
11
|
+
table.foreign('actingModuleId').references('id').inTable('modules').onDelete('CASCADE');
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=20241024164331-events-fk-fix.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"20241024164331-events-fk-fix.js","sourceRoot":"","sources":["../../../src/migrations/sql/20241024164331-events-fk-fix.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,KAAK,UAAU,EAAE,CAAC,IAAU;IACjC,uEAAuE;IACvE,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE;QAC/C,KAAK,CAAC,WAAW,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC;QACpC,KAAK,CAAC,WAAW,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,IAAI,CAAC,IAAU;IACnC,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE;QAC/C,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;QACpF,KAAK,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;IAC1F,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export async function up(knex) {
|
|
2
|
+
await knex.schema.alterTable('permissionOnRole', (table) => {
|
|
3
|
+
table.index(['roleId']);
|
|
4
|
+
});
|
|
5
|
+
await knex.schema.alterTable('playerOnGameServer', (table) => {
|
|
6
|
+
table.index(['domain', 'playerId']);
|
|
7
|
+
});
|
|
8
|
+
await knex.schema.alterTable('playerInventory', (table) => {
|
|
9
|
+
table.dropIndex(['playerId', 'domain']);
|
|
10
|
+
table.index(['playerId', 'domain', 'itemId']);
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
export async function down(knex) {
|
|
14
|
+
await knex.schema.alterTable('permissionOnRole', (table) => {
|
|
15
|
+
table.dropIndex(['roleId']);
|
|
16
|
+
});
|
|
17
|
+
await knex.schema.alterTable('playerOnGameServer', (table) => {
|
|
18
|
+
table.dropIndex(['domain', 'playerId']);
|
|
19
|
+
});
|
|
20
|
+
await knex.schema.alterTable('playerInventory', (table) => {
|
|
21
|
+
table.dropIndex(['playerId', 'domain', 'itemId']);
|
|
22
|
+
table.index(['playerId', 'domain']);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=20241030130613-index-for-roleId.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"20241030130613-index-for-roleId.js","sourceRoot":"","sources":["../../../src/migrations/sql/20241030130613-index-for-roleId.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,KAAK,UAAU,EAAE,CAAC,IAAU;IACjC,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,kBAAkB,EAAE,CAAC,KAAK,EAAE,EAAE;QACzD,KAAK,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,CAAC,C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
1
|
+
import { Knex } from 'knex';
|
|
2
|
+
|
|
3
|
+
export async function up(knex: Knex): Promise<void> {
|
|
4
|
+
await knex.schema.alterTable('shopOrder', (table) => {
|
|
5
|
+
table.uuid('playerId').references('id').inTable('players');
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
// Migrate existing userId values to playerId by looking up the playerId from users
|
|
9
|
+
const shopOrders = await knex('shopOrder').select('id', 'userId');
|
|
10
|
+
for (const order of shopOrders) {
|
|
11
|
+
const user = await knex('users').where('id', order.userId).first();
|
|
12
|
+
if (user && user.playerId) {
|
|
13
|
+
await knex('shopOrder').where('id', order.id).update('playerId', user.playerId);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
await knex.schema.alterTable('shopOrder', (table) => {
|
|
18
|
+
table.dropColumn('userId');
|
|
19
|
+
table.uuid('playerId').notNullable().alter();
|
|
20
|
+
table.index('playerId');
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function down(knex: Knex): Promise<void> {
|
|
25
|
+
// Add userId column back to the shopOrder table
|
|
26
|
+
await knex.schema.alterTable('shopOrder', (table) => {
|
|
27
|
+
table.uuid('userId').references('id').inTable('users');
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// Migrate playerId values back to userId by looking up the user from players
|
|
31
|
+
const shopOrders = await knex('shopOrder').select('id', 'playerId');
|
|
32
|
+
for (const order of shopOrders) {
|
|
33
|
+
const player = await knex('players').where('id', order.playerId).first();
|
|
34
|
+
if (player) {
|
|
35
|
+
await knex('shopOrder').where('id', order.id).update('userId', player.id);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Drop playerId column
|
|
40
|
+
await knex.schema.alterTable('shopOrder', (table) => {
|
|
41
|
+
table.dropColumn('playerId');
|
|
42
|
+
table.uuid('userId').notNullable().alter();
|
|
43
|
+
});
|
|
44
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Knex } from 'knex';
|
|
2
|
+
|
|
3
|
+
// This follows some research done with https://github.com/ankane/pghero
|
|
4
|
+
|
|
5
|
+
export async function up(knex: Knex): Promise<void> {
|
|
6
|
+
// Remove duplicate indexes
|
|
7
|
+
await knex.schema.alterTable('events', (table) => {
|
|
8
|
+
table.dropIndex('domain', 'events_domain_index');
|
|
9
|
+
});
|
|
10
|
+
await knex.schema.alterTable('items', (table) => {
|
|
11
|
+
table.dropIndex('code', 'items_code_index');
|
|
12
|
+
});
|
|
13
|
+
await knex.schema.alterTable('players', (table) => {
|
|
14
|
+
table.dropIndex('domain', 'players_domain_index');
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
// Add indexes
|
|
18
|
+
await knex.schema.alterTable('commands', (table) => {
|
|
19
|
+
table.index('moduleId');
|
|
20
|
+
});
|
|
21
|
+
await knex.schema.alterTable('events', (table) => {
|
|
22
|
+
table.index(['domain', 'createdAt']);
|
|
23
|
+
});
|
|
24
|
+
await knex.schema.alterTable('functions', (table) => {
|
|
25
|
+
table.index('moduleId');
|
|
26
|
+
});
|
|
27
|
+
await knex.schema.alterTable('playerOnGameServer', (table) => {
|
|
28
|
+
table.index(['gameServerId', 'domain']);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export async function down(knex: Knex): Promise<void> {
|
|
33
|
+
// Re-add removed indexes (if needed)
|
|
34
|
+
await knex.schema.alterTable('events', (table) => {
|
|
35
|
+
table.index('domain', 'events_domain_index');
|
|
36
|
+
});
|
|
37
|
+
await knex.schema.alterTable('items', (table) => {
|
|
38
|
+
table.index('code', 'items_code_index');
|
|
39
|
+
});
|
|
40
|
+
await knex.schema.alterTable('players', (table) => {
|
|
41
|
+
table.index('domain', 'players_domain_index');
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// Drop added indexes
|
|
45
|
+
await knex.schema.alterTable('commands', (table) => {
|
|
46
|
+
table.dropIndex('moduleId');
|
|
47
|
+
});
|
|
48
|
+
await knex.schema.alterTable('events', (table) => {
|
|
49
|
+
table.dropIndex(['domain', 'createdAt']);
|
|
50
|
+
});
|
|
51
|
+
await knex.schema.alterTable('functions', (table) => {
|
|
52
|
+
table.dropIndex('moduleId');
|
|
53
|
+
});
|
|
54
|
+
await knex.schema.alterTable('playerOnGameServer', (table) => {
|
|
55
|
+
table.dropIndex(['gameServerId', 'domain']);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Knex } from 'knex';
|
|
2
|
+
|
|
3
|
+
export async function up(knex: Knex): Promise<void> {
|
|
4
|
+
// Set all listings w/o name to 'Unnamed'
|
|
5
|
+
await knex('shopListing').whereNull('name').update({ name: 'Unnamed' });
|
|
6
|
+
|
|
7
|
+
await knex.schema.alterTable('shopListing', (table) => {
|
|
8
|
+
table.string('name').notNullable().alter();
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export async function down(knex: Knex): Promise<void> {
|
|
13
|
+
await knex.schema.alterTable('shopListing', (table) => {
|
|
14
|
+
table.string('name').nullable().alter();
|
|
15
|
+
});
|
|
16
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Knex } from 'knex';
|
|
2
|
+
|
|
3
|
+
export async function up(knex: Knex): Promise<void> {
|
|
4
|
+
// When player, module, gameserver or userId is deleted, keep the event
|
|
5
|
+
await knex.schema.alterTable('events', (table) => {
|
|
6
|
+
table.dropForeign(['actingUserId']);
|
|
7
|
+
table.dropForeign(['actingModuleId']);
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export async function down(knex: Knex): Promise<void> {
|
|
12
|
+
await knex.schema.alterTable('events', (table) => {
|
|
13
|
+
table.foreign('actingUserId').references('id').inTable('users').onDelete('CASCADE');
|
|
14
|
+
table.foreign('actingModuleId').references('id').inTable('modules').onDelete('CASCADE');
|
|
15
|
+
});
|
|
16
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Knex } from 'knex';
|
|
2
|
+
|
|
3
|
+
export async function up(knex: Knex): Promise<void> {
|
|
4
|
+
await knex.schema.alterTable('permissionOnRole', (table) => {
|
|
5
|
+
table.index(['roleId']);
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
await knex.schema.alterTable('playerOnGameServer', (table) => {
|
|
9
|
+
table.index(['domain', 'playerId']);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
await knex.schema.alterTable('playerInventory', (table) => {
|
|
13
|
+
table.dropIndex(['playerId', 'domain']);
|
|
14
|
+
table.index(['playerId', 'domain', 'itemId']);
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export async function down(knex: Knex): Promise<void> {
|
|
19
|
+
await knex.schema.alterTable('permissionOnRole', (table) => {
|
|
20
|
+
table.dropIndex(['roleId']);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
await knex.schema.alterTable('playerOnGameServer', (table) => {
|
|
24
|
+
table.dropIndex(['domain', 'playerId']);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
await knex.schema.alterTable('playerInventory', (table) => {
|
|
28
|
+
table.dropIndex(['playerId', 'domain', 'itemId']);
|
|
29
|
+
table.index(['playerId', 'domain']);
|
|
30
|
+
});
|
|
31
|
+
}
|