Add script to migrate from mongodb to postgresql
[oweals/peertube.git] / scripts / danger / clean / cleaner.js
1 const eachSeries = require('async/eachSeries')
2 const rimraf = require('rimraf')
3
4 const constants = require('../../../server/initializers/constants')
5 const db = require('../../../server/initializers/database')
6
7 db.init(true, function () {
8   db.sequelize.drop().asCallback(function (err) {
9     if (err) throw err
10
11     console.info('Tables of %s deleted.', db.sequelize.config.database)
12
13     const STORAGE = constants.CONFIG.STORAGE
14     eachSeries(Object.keys(STORAGE), function (storage, callbackEach) {
15       const storageDir = STORAGE[storage]
16
17       rimraf(storageDir, function (err) {
18         console.info('%s deleted.', storageDir)
19         return callbackEach(err)
20       })
21     }, function () {
22       process.exit(0)
23     })
24   })
25 })