Skip to content

Commit

Permalink
feat: 透過 migration 處理要寫星數的問題
Browse files Browse the repository at this point in the history
  • Loading branch information
hanshinoai committed Sep 12, 2024
1 parent dae934b commit 9d96b54
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
15 changes: 12 additions & 3 deletions app/migrations/20240909065404_add_attribute_column_to_inventory.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,18 @@
* @returns { Promise<void> }
*/
exports.up = function (knex) {
return knex.schema.table("Inventory", table => {
table.json("attributes").after("itemAmount");
});
return knex.schema
.table("Inventory", table => {
table.json("attributes").after("itemAmount");
})
.then(() =>
knex.raw(`
UPDATE \`Inventory\` i
JOIN \`GachaPool\` g ON i.\`itemId\` = g.\`ID\`
SET i.\`attributes\` = JSON_SET(COALESCE(i.\`attributes\`, '[]'), '$[0]', JSON_OBJECT('key', 'star', 'value', CAST(g.\`Star\` AS UNSIGNED)))
WHERE g.\`Star\` IS NOT NULL;
`)
);
};

/**
Expand Down
4 changes: 3 additions & 1 deletion app/migrations/20240912090806_drop_gacha_signin_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ exports.up = function (knex) {
* @returns { Promise<void> }
*/
exports.down = function (knex) {
return;
return knex.schema.createTable("GachaSignin", table => {
table.increments("id").primary().comment("為了 rollback 用的");
});
};

0 comments on commit 9d96b54

Please sign in to comment.