refactor: remove unused requirements/boost columns
authorxangelo <git@xangelo.ca>
Mon, 10 Jul 2023 19:13:46 +0000 (15:13 -0400)
committerxangelo <git@xangelo.ca>
Wed, 12 Jul 2023 10:21:55 +0000 (06:21 -0400)
When we migrated to json column types for boosts/requirements, we had to
leave the old columns in for a smooth migration (no data loss). This
migration removes that.

migrations/20230710191035_boost-cleanup.ts [new file with mode: 0644]
src/server/equipment.ts
src/server/shopItem.ts

diff --git a/migrations/20230710191035_boost-cleanup.ts b/migrations/20230710191035_boost-cleanup.ts
new file mode 100644 (file)
index 0000000..75d8fff
--- /dev/null
@@ -0,0 +1,27 @@
+import { Knex } from "knex";
+
+
+export async function up(knex: Knex): Promise<void> {
+  return knex.schema.alterTable('inventory', function(table) {
+    ['strength','dexterity','intelligence','constitution'].forEach(s => {
+      table.dropColumn(`boost_${s}`);
+      table.dropColumn(`requirement_${s}`);
+    });
+
+    table.dropColumn('boost_damage');
+    table.dropColumn('requirement_level');
+  }).alterTable('shop_items', function(table) {
+    ['strength','dexterity','intelligence','constitution'].forEach(s => {
+      table.dropColumn(`boost_${s}`);
+      table.dropColumn(`requirement_${s}`);
+    });
+
+    table.dropColumn('boost_damage');
+    table.dropColumn('requirement_level');
+  });
+}
+
+
+export async function down(knex: Knex): Promise<void> {
+}
+
index ad34640b05ee830264c48904b9750649434b23f9..9ebac7d80318be815dc91c6a212c51723c032247 100644 (file)
@@ -10,16 +10,9 @@ export async function getEquippedItems(playerId: string): Promise<EquippedItemDe
                 i.name,
                 i.cost,
                 i.count,
-                i.requirement_level,
-                i.requirement_strength,
-                i.requirement_constitution,
-                i.requirement_dexterity,
-                i.requirement_intelligence,
+                i.requirements,
                 i.profession,
-                i.boost_strength,
-                i.boost_constitution,
-                i.boost_dexterity,
-                i.boost_damage,
+                i.boosts,
                 i.maxAp,
                 i.currentAp,
                 e.equipment_slot,
index 65c2ead2e232cbf7d963ce47fd7a87be240af9a3..69c55e639c78f7937be2780f786495938ad32dbc 100644 (file)
@@ -4,9 +4,9 @@ import {ShopItem} from '../shared/inventory';
 export function listShopItems(where: Partial<ShopItem>): Promise<ShopItem[]> {
   return db.select('*').from<ShopItem>('shop_items')
         .where(where)
-        .orderBy('requirement_level')
         .orderBy('type')
-        .orderBy('equipment_slot');
+        .orderBy('equipment_slot')
+        .orderByRaw(`requirements->>'level' asc`);
 }
 
 export function getShopItem(id: number): Promise<ShopItem> {