]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Update scripts with postgresql
authorChocobozzz <florian.bigard@gmail.com>
Sun, 25 Dec 2016 08:44:13 +0000 (09:44 +0100)
committerChocobozzz <florian.bigard@gmail.com>
Sun, 25 Dec 2016 08:44:13 +0000 (09:44 +0100)
scripts/danger/clean/cleaner.js
scripts/danger/clean/dev.sh
scripts/danger/clean/prod.sh
scripts/update-host.js

index 10e91e7000d1965996b0dc4edcde861c2a58dff2..d1e2181452d23bae25e515446a38a7c83f95d941 100644 (file)
@@ -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)
+      })
+    })
   })
 })
index 5f09565cf0071b8506d90df2cf0d34f2d6fb7828..f4a5d1e8a7b6f5ec0fdf2bae71356b5606d1714c 100755 (executable)
@@ -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"
index e6c92671de60130de74decadae19ae5b7338bd90..7ee13ba8372f918c0812cc503659d9b8a80cdf03 100755 (executable)
@@ -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"
index 8a17f24023f7e644f7e17fb86ffe93914a0f0738..91051e68b400d85e843bce8fe340a8ebb7da516e 100755 (executable)
@@ -5,31 +5,24 @@
 // TODO: document this script
 
 const fs = require('fs')
-const mongoose = require('mongoose')
 const parseTorrent = require('parse-torrent')
 
 const constants = require('../server/initializers/constants')
-const database = require('../server/initializers/database')
-
-database.connect()
+const db = require('../server/initializers/database')
 
 const friends = require('../server/lib/friends')
-const Video = mongoose.model('Video')
-
-friends.hasFriends(function (err, hasFriends) {
-  if (err) throw err
 
-  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) {
+db.init(true, function () {
+  friends.hasFriends(function (err, hasFriends) {
     if (err) throw err
 
+    if (hasFriends === true) {
+      console.log('Cannot update host because you have friends!')
+      process.exit(-1)
+    }
+
     console.log('Updating torrent files.')
-    Video.find().lean().exec(function (err, videos) {
+    db.Video.list(function (err, videos) {
       if (err) throw err
 
       videos.forEach(function (video) {