migrate.js 837 B

123456789101112131415161718192021222324252627282930313233343536
  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 { URL } = require('url');
  9. const { getMongoUri } = require('@commons/util/mongoose-utils');
  10. const mongoUri = getMongoUri();
  11. // parse url
  12. const url = new URL(mongoUri);
  13. const authStr = (url.username.length > 0 && url.password.length > 0)
  14. ? `${url.username}:${url.password}@`
  15. : '';
  16. const mongodb = {
  17. url: `${url.protocol}//${authStr}${url.host}${url.search}`,
  18. databaseName: url.pathname.substring(1), // omit heading slash
  19. options: {
  20. useNewUrlParser: true, // removes a deprecation warning when connecting
  21. },
  22. };
  23. module.exports = {
  24. mongoUri,
  25. mongodb,
  26. migrationsDir: 'src/migrations/',
  27. changelogCollectionName: 'migrations',
  28. };