umzug-helper.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. "use strict";
  2. var _path = _interopRequireDefault(require("path"));
  3. var _lodash = _interopRequireDefault(require("lodash"));
  4. var _index = _interopRequireDefault(require("./index"));
  5. var _process = _interopRequireDefault(require("process"));
  6. function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
  7. const storage = {
  8. migration: 'sequelize',
  9. seeder: 'none'
  10. };
  11. const storageTableName = {
  12. migration: 'SequelizeMeta',
  13. seeder: 'SequelizeData'
  14. };
  15. const storageJsonName = {
  16. migration: 'sequelize-meta.json',
  17. seeder: 'sequelize-data.json'
  18. };
  19. let timestampsDefault = false;
  20. module.exports = {
  21. getStorageOption(property, fallback) {
  22. return _index.default.config.readConfig()[property] || fallback;
  23. },
  24. getStorage(type) {
  25. return this.getStorageOption(type + 'Storage', storage[type]);
  26. },
  27. getStoragePath(type) {
  28. const fallbackPath = _path.default.join(_process.default.cwd(), storageJsonName[type]);
  29. return this.getStorageOption(type + 'StoragePath', fallbackPath);
  30. },
  31. getTableName(type) {
  32. return this.getStorageOption(type + 'StorageTableName', storageTableName[type]);
  33. },
  34. getSchema(type) {
  35. return this.getStorageOption(type + 'StorageTableSchema', undefined);
  36. },
  37. enableTimestamps() {
  38. timestampsDefault = true;
  39. },
  40. getTimestamps(type) {
  41. return this.getStorageOption(type + 'Timestamps', timestampsDefault);
  42. },
  43. getStorageOptions(type, extraOptions) {
  44. const options = {};
  45. if (this.getStorage(type) === 'json') {
  46. options.path = this.getStoragePath(type);
  47. } else if (this.getStorage(type) === 'sequelize') {
  48. options.tableName = this.getTableName(type);
  49. options.schema = this.getSchema(type);
  50. options.timestamps = this.getTimestamps(type);
  51. }
  52. _lodash.default.assign(options, extraOptions);
  53. return options;
  54. }
  55. };