migrate.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /**
  2. * Configuration file for migrate-mongo
  3. * @see https://github.com/seppevs/migrate-mongo
  4. *
  5. * @author Yuki Takei <yuki@weseek.co.jp>
  6. */
  7. require('module-alias/register');
  8. const models = require('@server/models');
  9. // generate mock crowi object
  10. const crowi = {
  11. event: () => {
  12. return { on: () => {} };
  13. },
  14. };
  15. // initialize models
  16. // access each model with mongoose.models('ModelName')
  17. Object.keys(models).forEach((key) => {
  18. models[key](crowi);
  19. });
  20. function getMongoUri(env) {
  21. return env.MONGOLAB_URI // for B.C.
  22. || env.MONGODB_URI // MONGOLAB changes their env name
  23. || env.MONGOHQ_URL
  24. || env.MONGO_URI
  25. || ((env.NODE_ENV === 'test') ? 'mongodb://localhost/growi_test' : 'mongodb://localhost/growi');
  26. }
  27. const mongoUri = getMongoUri(process.env);
  28. const match = mongoUri.match(/^(.+)\/([^/]+)$/);
  29. module.exports = {
  30. mongoUri,
  31. mongodb: {
  32. url: match[0],
  33. databaseName: match[2],
  34. options: {
  35. useNewUrlParser: true, // removes a deprecation warning when connecting
  36. },
  37. },
  38. migrationsDir: 'src/migrations/',
  39. changelogCollectionName: 'migrations',
  40. };