p5.js-web-editor/server/migrations/truncate.js
Cassie Tarakajian 8054a532d7
Update to webpack 4 ()
* remove some of the react errors, start to fix webpack HMR errors

* start upgrade to webpack 4

* more stuff to update webpack

* update webpack configs to work with webpack 4

* remove linting from truncate script
2019-08-28 16:08:40 -04:00

36 lines
No EOL
958 B
JavaScript

/* eslint-disable */
import mongoose from 'mongoose';
import slugify from 'slugify';
const dotenv = require('dotenv');
dotenv.config();
import Project from '../models/project';
// Connect to MongoDB
mongoose.Promise = global.Promise;
mongoose.connect(process.env.MONGO_URL, {
useMongoClient: true
});
mongoose.connection.on('error', () => {
console.error('MongoDB Connection Error. Please make sure that MongoDB is running.');
process.exit(1);
});
Project.find({}, {}, {
timeout: true
}).cursor().eachAsync((project) => {
console.log(project.name);
if (project.name.length < 256) {
console.log('Project name is okay.');
return Promise.resolve();
}
project.name = project.name.substr(0, 255);
project.slug = slugify(project.name, '_');
return project.save().then(() => {
console.log('Updated sketch slug to: ' + project.slug);
});
}).then(() => {
console.log('Done iterating over every sketch.');
process.exit(0);
});