UserGeneration.js 733 B

1234567891011121314151617181920212223242526272829303132333435
  1. const mongoose = require('mongoose');
  2. const { getNowChinaTimeString } = require('../utils/date');
  3. const userGenerationSchema = new mongoose.Schema({
  4. username: {
  5. type: String,
  6. required: true,
  7. unique: true,
  8. index: true
  9. },
  10. lastGenerationTime: {
  11. type: String,
  12. default() {
  13. return getNowChinaTimeString();
  14. }
  15. },
  16. generationCount: {
  17. type: Number,
  18. default: 0
  19. },
  20. isDisabled: {
  21. type: Boolean,
  22. default: false
  23. },
  24. }, {
  25. timestamps: true // 添加 createdAt 和 updatedAt 字段
  26. });
  27. // 创建索引以优化查询性能
  28. userGenerationSchema.index({ username: 1 });
  29. const UserGeneration = mongoose.model('UserGeneration', userGenerationSchema);
  30. module.exports = UserGeneration;