diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-12-25 09:44:13 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-12-25 09:44:13 +0100 |
commit | dd6019932efd6ae3b790bf024bc0cd74162e4517 (patch) | |
tree | c7250415dccea2fb8713edebf9b4625e70648bec | |
parent | 8c67719c80cef7319afecdf1078d5447149ad8e7 (diff) | |
download | PeerTube-dd6019932efd6ae3b790bf024bc0cd74162e4517.tar.gz PeerTube-dd6019932efd6ae3b790bf024bc0cd74162e4517.tar.zst PeerTube-dd6019932efd6ae3b790bf024bc0cd74162e4517.zip |
Update scripts with postgresql
-rw-r--r-- | scripts/danger/clean/cleaner.js | 29 | ||||
-rwxr-xr-x | scripts/danger/clean/dev.sh | 3 | ||||
-rwxr-xr-x | scripts/danger/clean/prod.sh | 3 | ||||
-rwxr-xr-x | scripts/update-host.js | 25 |
4 files changed, 27 insertions, 33 deletions
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 @@ | |||
1 | const rimraf = require('rimraf') | 1 | const rimraf = require('rimraf') |
2 | const mongoose = require('mongoose') | ||
3 | mongoose.Promise = global.Promise | ||
4 | 2 | ||
5 | const constants = require('../../../server/initializers/constants') | 3 | const constants = require('../../../server/initializers/constants') |
4 | const db = require('../../../server/initializers/database') | ||
6 | 5 | ||
7 | const mongodbUrl = 'mongodb://' + constants.CONFIG.DATABASE.HOSTNAME + ':' + constants.CONFIG.DATABASE.PORT + '/' + constants.CONFIG.DATABASE.DBNAME | 6 | db.init(true, function () { |
8 | mongoose.connect(mongodbUrl, function () { | 7 | db.sequelize.drop().asCallback(function (err) { |
9 | console.info('Deleting MongoDB %s database.', constants.CONFIG.DATABASE.DBNAME) | 8 | if (err) throw err |
10 | mongoose.connection.dropDatabase(function () { | ||
11 | mongoose.connection.close() | ||
12 | }) | ||
13 | }) | ||
14 | 9 | ||
15 | const STORAGE = constants.CONFIG.STORAGE | 10 | console.info('Tables of %s deleted.', db.sequelize.config.database) |
16 | Object.keys(STORAGE).forEach(function (storage) { | ||
17 | const storageDir = STORAGE[storage] | ||
18 | 11 | ||
19 | rimraf(storageDir, function (err) { | 12 | const STORAGE = constants.CONFIG.STORAGE |
20 | if (err) throw err | 13 | Object.keys(STORAGE).forEach(function (storage) { |
14 | const storageDir = STORAGE[storage] | ||
15 | |||
16 | rimraf(storageDir, function (err) { | ||
17 | if (err) throw err | ||
21 | 18 | ||
22 | console.info('Deleting %s.', storageDir) | 19 | console.info('Deleting %s.', storageDir) |
20 | }) | ||
21 | }) | ||
23 | }) | 22 | }) |
24 | }) | 23 | }) |
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 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | 2 | ||
3 | read -p "This will remove all directories and Mongo database. Are you sure? " -n 1 -r | 3 | read -p "This will remove all directories and SQL tables. Are you sure? (y/*) " -n 1 -r |
4 | echo | ||
4 | 5 | ||
5 | if [[ "$REPLY" =~ ^[Yy]$ ]]; then | 6 | if [[ "$REPLY" =~ ^[Yy]$ ]]; then |
6 | NODE_ENV=test node "./scripts/danger/clean/cleaner" | 7 | 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 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | 2 | ||
3 | read -p "This will remove all directories and Mongo database. Are you sure? " -n 1 -r | 3 | read -p "This will remove all directories and SQL tables. Are you sure? (y/*) " -n 1 -r |
4 | echo | ||
4 | 5 | ||
5 | if [[ "$REPLY" =~ ^[Yy]$ ]]; then | 6 | if [[ "$REPLY" =~ ^[Yy]$ ]]; then |
6 | NODE_ENV=production node "./scripts/danger/clean/cleaner" | 7 | NODE_ENV=production node "./scripts/danger/clean/cleaner" |
diff --git a/scripts/update-host.js b/scripts/update-host.js index 8a17f2402..91051e68b 100755 --- a/scripts/update-host.js +++ b/scripts/update-host.js | |||
@@ -5,31 +5,24 @@ | |||
5 | // TODO: document this script | 5 | // TODO: document this script |
6 | 6 | ||
7 | const fs = require('fs') | 7 | const fs = require('fs') |
8 | const mongoose = require('mongoose') | ||
9 | const parseTorrent = require('parse-torrent') | 8 | const parseTorrent = require('parse-torrent') |
10 | 9 | ||
11 | const constants = require('../server/initializers/constants') | 10 | const constants = require('../server/initializers/constants') |
12 | const database = require('../server/initializers/database') | 11 | const db = require('../server/initializers/database') |
13 | |||
14 | database.connect() | ||
15 | 12 | ||
16 | const friends = require('../server/lib/friends') | 13 | const friends = require('../server/lib/friends') |
17 | const Video = mongoose.model('Video') | ||
18 | |||
19 | friends.hasFriends(function (err, hasFriends) { | ||
20 | if (err) throw err | ||
21 | 14 | ||
22 | if (hasFriends === true) { | 15 | db.init(true, function () { |
23 | console.log('Cannot update host because you have friends!') | 16 | friends.hasFriends(function (err, hasFriends) { |
24 | process.exit(-1) | ||
25 | } | ||
26 | |||
27 | console.log('Updating videos host in database.') | ||
28 | Video.update({ }, { podHost: constants.CONFIG.WEBSERVER.HOST }, { multi: true }, function (err) { | ||
29 | if (err) throw err | 17 | if (err) throw err |
30 | 18 | ||
19 | if (hasFriends === true) { | ||
20 | console.log('Cannot update host because you have friends!') | ||
21 | process.exit(-1) | ||
22 | } | ||
23 | |||
31 | console.log('Updating torrent files.') | 24 | console.log('Updating torrent files.') |
32 | Video.find().lean().exec(function (err, videos) { | 25 | db.Video.list(function (err, videos) { |
33 | if (err) throw err | 26 | if (err) throw err |
34 | 27 | ||
35 | videos.forEach(function (video) { | 28 | videos.forEach(function (video) { |