1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-03 01:39:37 +02:00

Use a migration script for comments count

This commit is contained in:
Chocobozzz 2025-05-20 10:36:54 +02:00
parent feb178e171
commit b19754f259
No known key found for this signature in database
GPG key ID: 583A612D890159BE
2 changed files with 20 additions and 5 deletions

View file

@ -14,11 +14,6 @@ async function up (utils: {
allowNull: false allowNull: false
}, { transaction }) }, { transaction })
} }
{
const query = 'UPDATE "video" SET "comments" = (SELECT COUNT(*) FROM "videoComment" WHERE "videoComment"."videoId" = "video"."id")'
await utils.sequelize.query(query, { transaction })
}
} }
function down (options) { function down (options) {

View file

@ -0,0 +1,20 @@
import { initDatabaseModels, sequelizeTypescript } from '@server/initializers/database.js'
run()
.then(() => process.exit(0))
.catch(err => {
console.error(err)
process.exit(-1)
})
async function run () {
await initDatabaseModels(true)
console.log('Running SQL request to update comments count...')
{
const query = 'UPDATE "video" SET "comments" = (SELECT COUNT(*) FROM "videoComment" WHERE "videoComment"."videoId" = "video"."id")'
await sequelizeTypescript.query(query)
}
console.log('Done!')
}