models.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /**
  2. * Default model settings
  3. * (sails.config.models)
  4. *
  5. * Your default, project-wide model settings. Can also be overridden on a
  6. * per-model basis by setting a top-level properties in the model definition.
  7. *
  8. * For details about all available model settings, see:
  9. * https://sailsjs.com/config/models
  10. *
  11. * For more general background on Sails model settings, and how to configure
  12. * them on a project-wide or per-model basis, see:
  13. * https://sailsjs.com/docs/concepts/models-and-orm/model-settings
  14. */
  15. module.exports.models = {
  16. /***************************************************************************
  17. * *
  18. * Whether the `.create()` and `.update()` model methods should ignore *
  19. * (and refuse to persist) unrecognized data-- i.e. properties other than *
  20. * those explicitly defined by attributes in the model definition. *
  21. * *
  22. * To ease future maintenance of your code base, it is usually a good idea *
  23. * to set this to `true`. *
  24. * *
  25. * > Note that `schema: false` is not supported by every database. *
  26. * > For example, if you are using a SQL database, then relevant models *
  27. * > are always effectively `schema: true`. And if no `schema` setting is *
  28. * > provided whatsoever, the behavior is left up to the database adapter. *
  29. * > *
  30. * > For more info, see: *
  31. * > https://sailsjs.com/docs/concepts/orm/model-settings#?schema *
  32. * *
  33. ***************************************************************************/
  34. schema: true,
  35. /***************************************************************************
  36. * *
  37. * How and whether Sails will attempt to automatically rebuild the *
  38. * tables/collections/etc. in your schema. *
  39. * *
  40. * > Note that, when running in a production environment, this will be *
  41. * > automatically set to `migrate: 'safe'`, no matter what you configure *
  42. * > here. This is a failsafe to prevent Sails from accidentally running *
  43. * > auto-migrations on your production database. *
  44. * > *
  45. * > For more info, see: *
  46. * > https://sailsjs.com/docs/concepts/orm/model-settings#?migrate *
  47. * *
  48. ***************************************************************************/
  49. migrate: 'alter',
  50. /***************************************************************************
  51. * *
  52. * Base attributes that are included in all of your models by default. *
  53. * By convention, this is your primary key attribute (`id`), as well as two *
  54. * other timestamp attributes for tracking when records were last created *
  55. * or updated. *
  56. * *
  57. * > For more info, see: *
  58. * > https://sailsjs.com/docs/concepts/orm/model-settings#?attributes *
  59. * *
  60. ***************************************************************************/
  61. attributes: {
  62. createdAt: { type: 'number', autoCreatedAt: true, },
  63. updatedAt: { type: 'number', autoUpdatedAt: true, },
  64. id: { type: 'number', autoIncrement: true, },
  65. //--------------------------------------------------------------------------
  66. // /\ Using MongoDB?
  67. // || Replace `id` above with this instead:
  68. //
  69. // ```
  70. // id: { type: 'string', columnName: '_id' },
  71. // ```
  72. //--------------------------------------------------------------------------
  73. },
  74. /******************************************************************************
  75. * *
  76. * The set of DEKs (data encryption keys) for at-rest encryption. *
  77. * i.e. when encrypting/decrypting data for attributes with `encrypt: true`. *
  78. * *
  79. * > The `default` DEK is used for all new encryptions, but multiple DEKs *
  80. * > can be configured to allow for key rotation. In production, be sure to *
  81. * > manage these keys like you would any other sensitive credential. *
  82. * *
  83. * > For more info, see: *
  84. * > https://sailsjs.com/docs/concepts/orm/model-settings#?dataEncryptionKeys *
  85. * *
  86. ******************************************************************************/
  87. dataEncryptionKeys: {
  88. default: 'km9orVnOMh5s1f0dIaiFJ+o6FrdEj3QJQxEDHNH3SqI='
  89. },
  90. /***************************************************************************
  91. * *
  92. * Whether or not implicit records for associations should be cleaned up *
  93. * automatically using the built-in polyfill. This is especially useful *
  94. * during development with sails-disk. *
  95. * *
  96. * Depending on which databases you're using, you may want to disable this *
  97. * polyfill in your production environment. *
  98. * *
  99. * (For production configuration, see `config/env/production.js`.) *
  100. * *
  101. ***************************************************************************/
  102. cascadeOnDestroy: true
  103. };