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:
parent
feb178e171
commit
b19754f259
2 changed files with 20 additions and 5 deletions
|
@ -14,11 +14,6 @@ async function up (utils: {
|
|||
allowNull: false
|
||||
}, { 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) {
|
||||
|
|
20
server/scripts/migrations/peertube-7.2.ts
Normal file
20
server/scripts/migrations/peertube-7.2.ts
Normal 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!')
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue