mirror of
https://github.com/plankanban/planka.git
synced 2025-07-19 05:09:43 +02:00
parent
f9d3e73651
commit
4049b4c396
6 changed files with 165 additions and 13 deletions
32
server/db/migrations/20250523131647_add_comments_counter.js
Normal file
32
server/db/migrations/20250523131647_add_comments_counter.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
exports.up = async (knex) => {
|
||||
await knex.schema.alterTable('card', (table) => {
|
||||
/* Columns */
|
||||
|
||||
table.integer('comments_total').notNullable().defaultTo(0);
|
||||
});
|
||||
|
||||
await knex.raw(`
|
||||
UPDATE card
|
||||
SET comments_total = comments_total_by_card_id.comments_total
|
||||
FROM (
|
||||
SELECT card_id, COUNT(*) as comments_total
|
||||
FROM comment
|
||||
GROUP BY card_id
|
||||
) AS comments_total_by_card_id
|
||||
WHERE card.id = comments_total_by_card_id.card_id
|
||||
`);
|
||||
|
||||
return knex.schema.alterTable('card', (table) => {
|
||||
table.integer('comments_total').notNullable().alter();
|
||||
});
|
||||
};
|
||||
|
||||
exports.down = (knex) =>
|
||||
knex.schema.table('card', (table) => {
|
||||
table.dropColumn('comments_total');
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue