]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/initializers/migrator.ts
Fix CPU usage on PostgreSQL
[github/Chocobozzz/PeerTube.git] / server / initializers / migrator.ts
index 539e2bc8fbaeb17a6ba52af3334db7296086fb6e..1cb0116b7bfc145633e6baf1b2bb3fac294dc503 100644 (file)
@@ -1,8 +1,9 @@
 import * as path from 'path'
-import { readdirPromise } from '../helpers/core-utils'
 import { logger } from '../helpers/logger'
 import { LAST_MIGRATION_VERSION } from './constants'
 import { sequelizeTypescript } from './database'
+import { readdir } from 'fs-extra'
+import { QueryTypes } from 'sequelize'
 
 async function migrate () {
   const tables = await sequelizeTypescript.getQueryInterface().showAllTables()
@@ -13,7 +14,12 @@ async function migrate () {
 
   let actualVersion: number | null = null
 
-  const [ rows ] = await sequelizeTypescript.query('SELECT "migrationVersion" FROM "application"')
+  const query = 'SELECT "migrationVersion" FROM "application"'
+  const options = {
+    type: QueryTypes.SELECT as QueryTypes.SELECT
+  }
+
+  const rows = await sequelizeTypescript.query<{ migrationVersion: number }>(query, options)
   if (rows && rows[0] && rows[0].migrationVersion) {
     actualVersion = rows[0].migrationVersion
   }
@@ -52,7 +58,7 @@ export {
 // ---------------------------------------------------------------------------
 
 async function getMigrationScripts () {
-  const files = await readdirPromise(path.join(__dirname, 'migrations'))
+  const files = await readdir(path.join(__dirname, 'migrations'))
   const filesToMigrate: {
     version: string,
     script: string