From dd6019932efd6ae3b790bf024bc0cd74162e4517 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Sun, 25 Dec 2016 09:44:13 +0100 Subject: Update scripts with postgresql --- scripts/danger/clean/cleaner.js | 29 ++++++++++++++--------------- scripts/danger/clean/dev.sh | 3 ++- scripts/danger/clean/prod.sh | 3 ++- 3 files changed, 18 insertions(+), 17 deletions(-) (limited to 'scripts/danger') diff --git a/scripts/danger/clean/cleaner.js b/scripts/danger/clean/cleaner.js index 10e91e700..d1e218145 100644 --- a/scripts/danger/clean/cleaner.js +++ b/scripts/danger/clean/cleaner.js @@ -1,24 +1,23 @@ const rimraf = require('rimraf') -const mongoose = require('mongoose') -mongoose.Promise = global.Promise const constants = require('../../../server/initializers/constants') +const db = require('../../../server/initializers/database') -const mongodbUrl = 'mongodb://' + constants.CONFIG.DATABASE.HOSTNAME + ':' + constants.CONFIG.DATABASE.PORT + '/' + constants.CONFIG.DATABASE.DBNAME -mongoose.connect(mongodbUrl, function () { - console.info('Deleting MongoDB %s database.', constants.CONFIG.DATABASE.DBNAME) - mongoose.connection.dropDatabase(function () { - mongoose.connection.close() - }) -}) +db.init(true, function () { + db.sequelize.drop().asCallback(function (err) { + if (err) throw err -const STORAGE = constants.CONFIG.STORAGE -Object.keys(STORAGE).forEach(function (storage) { - const storageDir = STORAGE[storage] + console.info('Tables of %s deleted.', db.sequelize.config.database) - rimraf(storageDir, function (err) { - if (err) throw err + const STORAGE = constants.CONFIG.STORAGE + Object.keys(STORAGE).forEach(function (storage) { + const storageDir = STORAGE[storage] + + rimraf(storageDir, function (err) { + if (err) throw err - console.info('Deleting %s.', storageDir) + console.info('Deleting %s.', storageDir) + }) + }) }) }) diff --git a/scripts/danger/clean/dev.sh b/scripts/danger/clean/dev.sh index 5f09565cf..f4a5d1e8a 100755 --- a/scripts/danger/clean/dev.sh +++ b/scripts/danger/clean/dev.sh @@ -1,6 +1,7 @@ #!/bin/bash -read -p "This will remove all directories and Mongo database. Are you sure? " -n 1 -r +read -p "This will remove all directories and SQL tables. Are you sure? (y/*) " -n 1 -r +echo if [[ "$REPLY" =~ ^[Yy]$ ]]; then NODE_ENV=test node "./scripts/danger/clean/cleaner" diff --git a/scripts/danger/clean/prod.sh b/scripts/danger/clean/prod.sh index e6c92671d..7ee13ba83 100755 --- a/scripts/danger/clean/prod.sh +++ b/scripts/danger/clean/prod.sh @@ -1,6 +1,7 @@ #!/bin/bash -read -p "This will remove all directories and Mongo database. Are you sure? " -n 1 -r +read -p "This will remove all directories and SQL tables. Are you sure? (y/*) " -n 1 -r +echo if [[ "$REPLY" =~ ^[Yy]$ ]]; then NODE_ENV=production node "./scripts/danger/clean/cleaner" -- cgit v1.2.3 From 00d6a41e46e4c4948b0d5b4cf21433150a57c067 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 27 Dec 2016 18:33:38 +0100 Subject: Add script to migrate from mongodb to postgresql Usage: NODE_ENV=production ./scripts/mongo-to-postgre.js --mongo-database peertube-prod --- scripts/danger/clean/cleaner.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'scripts/danger') diff --git a/scripts/danger/clean/cleaner.js b/scripts/danger/clean/cleaner.js index d1e218145..1a1e3dee7 100644 --- a/scripts/danger/clean/cleaner.js +++ b/scripts/danger/clean/cleaner.js @@ -1,3 +1,4 @@ +const eachSeries = require('async/eachSeries') const rimraf = require('rimraf') const constants = require('../../../server/initializers/constants') @@ -10,14 +11,15 @@ db.init(true, function () { console.info('Tables of %s deleted.', db.sequelize.config.database) const STORAGE = constants.CONFIG.STORAGE - Object.keys(STORAGE).forEach(function (storage) { + eachSeries(Object.keys(STORAGE), function (storage, callbackEach) { const storageDir = STORAGE[storage] rimraf(storageDir, function (err) { - if (err) throw err - - console.info('Deleting %s.', storageDir) + console.info('%s deleted.', storageDir) + return callbackEach(err) }) + }, function () { + process.exit(0) }) }) }) -- cgit v1.2.3