Update scripts with postgresql
This commit is contained in:
parent
8c67719c80
commit
dd6019932e
|
@ -1,24 +1,23 @@
|
||||||
const rimraf = require('rimraf')
|
const rimraf = require('rimraf')
|
||||||
const mongoose = require('mongoose')
|
|
||||||
mongoose.Promise = global.Promise
|
|
||||||
|
|
||||||
const constants = require('../../../server/initializers/constants')
|
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
|
db.init(true, function () {
|
||||||
mongoose.connect(mongodbUrl, function () {
|
db.sequelize.drop().asCallback(function (err) {
|
||||||
console.info('Deleting MongoDB %s database.', constants.CONFIG.DATABASE.DBNAME)
|
|
||||||
mongoose.connection.dropDatabase(function () {
|
|
||||||
mongoose.connection.close()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
const STORAGE = constants.CONFIG.STORAGE
|
|
||||||
Object.keys(STORAGE).forEach(function (storage) {
|
|
||||||
const storageDir = STORAGE[storage]
|
|
||||||
|
|
||||||
rimraf(storageDir, function (err) {
|
|
||||||
if (err) throw err
|
if (err) throw err
|
||||||
|
|
||||||
console.info('Deleting %s.', storageDir)
|
console.info('Tables of %s deleted.', db.sequelize.config.database)
|
||||||
|
|
||||||
|
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)
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#!/bin/bash
|
#!/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
|
if [[ "$REPLY" =~ ^[Yy]$ ]]; then
|
||||||
NODE_ENV=test node "./scripts/danger/clean/cleaner"
|
NODE_ENV=test node "./scripts/danger/clean/cleaner"
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#!/bin/bash
|
#!/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
|
if [[ "$REPLY" =~ ^[Yy]$ ]]; then
|
||||||
NODE_ENV=production node "./scripts/danger/clean/cleaner"
|
NODE_ENV=production node "./scripts/danger/clean/cleaner"
|
||||||
|
|
|
@ -5,31 +5,24 @@
|
||||||
// TODO: document this script
|
// TODO: document this script
|
||||||
|
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const mongoose = require('mongoose')
|
|
||||||
const parseTorrent = require('parse-torrent')
|
const parseTorrent = require('parse-torrent')
|
||||||
|
|
||||||
const constants = require('../server/initializers/constants')
|
const constants = require('../server/initializers/constants')
|
||||||
const database = require('../server/initializers/database')
|
const db = require('../server/initializers/database')
|
||||||
|
|
||||||
database.connect()
|
|
||||||
|
|
||||||
const friends = require('../server/lib/friends')
|
const friends = require('../server/lib/friends')
|
||||||
const Video = mongoose.model('Video')
|
|
||||||
|
|
||||||
friends.hasFriends(function (err, hasFriends) {
|
db.init(true, function () {
|
||||||
if (err) throw err
|
friends.hasFriends(function (err, hasFriends) {
|
||||||
|
|
||||||
if (hasFriends === true) {
|
|
||||||
console.log('Cannot update host because you have friends!')
|
|
||||||
process.exit(-1)
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('Updating videos host in database.')
|
|
||||||
Video.update({ }, { podHost: constants.CONFIG.WEBSERVER.HOST }, { multi: true }, function (err) {
|
|
||||||
if (err) throw err
|
if (err) throw err
|
||||||
|
|
||||||
|
if (hasFriends === true) {
|
||||||
|
console.log('Cannot update host because you have friends!')
|
||||||
|
process.exit(-1)
|
||||||
|
}
|
||||||
|
|
||||||
console.log('Updating torrent files.')
|
console.log('Updating torrent files.')
|
||||||
Video.find().lean().exec(function (err, videos) {
|
db.Video.list(function (err, videos) {
|
||||||
if (err) throw err
|
if (err) throw err
|
||||||
|
|
||||||
videos.forEach(function (video) {
|
videos.forEach(function (video) {
|
||||||
|
|
Loading…
Reference in New Issue