Server: fix mongo to postgresql script
authorChocobozzz <florian.bigard@gmail.com>
Thu, 12 Jan 2017 16:01:10 +0000 (17:01 +0100)
committerChocobozzz <florian.bigard@gmail.com>
Thu, 12 Jan 2017 16:35:17 +0000 (17:35 +0100)
scripts/mongo-to-postgre.js

index 4a581b46a4fea20cf3c3af8f294ceb25dab140f4..6cd1ef3b4437fc8cdfc9b155b866055fbd62ae99 100755 (executable)
@@ -126,7 +126,8 @@ function migrateVideos (videoMongo, dbSequelize, finalCallback) {
 
           dbSequelize.Pod.findOrCreate(query).asCallback(function (err, result) {
             // [ instance, wasCreated ]
-            return callback(err, t, result[0])
+            const res = result ? result[0] : null
+            return callback(err, t, res)
           })
         },
 
@@ -148,7 +149,8 @@ function migrateVideos (videoMongo, dbSequelize, finalCallback) {
 
           dbSequelize.Author.findOrCreate(query).asCallback(function (err, result) {
             // [ instance, wasCreated ]
-            return callback(err, t, result[0])
+            const res = result ? result[0] : null
+            return callback(err, t, res)
           })
         },
 
@@ -235,9 +237,7 @@ function migrateVideos (videoMongo, dbSequelize, finalCallback) {
         }
 
         // Commit transaction
-        t.commit()
-
-        return callbackEach()
+        return t.commit().asCallback(callbackEach)
       })
     }, finalCallback)
   })