20250101000000-create-contact.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. 'use strict';
  2. module.exports = {
  3. up: async (queryInterface, Sequelize) => {
  4. await queryInterface.createTable('contacts', {
  5. id: {
  6. allowNull: false,
  7. autoIncrement: true,
  8. primaryKey: true,
  9. type: Sequelize.INTEGER
  10. },
  11. name: {
  12. type: Sequelize.STRING(100),
  13. allowNull: false,
  14. comment: '联系人姓名'
  15. },
  16. email: {
  17. type: Sequelize.STRING(255),
  18. allowNull: false,
  19. comment: '联系人邮箱'
  20. },
  21. phone: {
  22. type: Sequelize.STRING(20),
  23. allowNull: true,
  24. comment: '联系电话'
  25. },
  26. company: {
  27. type: Sequelize.STRING(200),
  28. allowNull: true,
  29. comment: '公司名称'
  30. },
  31. subject: {
  32. type: Sequelize.STRING(200),
  33. allowNull: false,
  34. comment: '留言主题'
  35. },
  36. message: {
  37. type: Sequelize.TEXT,
  38. allowNull: false,
  39. comment: '留言内容'
  40. },
  41. status: {
  42. type: Sequelize.INTEGER,
  43. defaultValue: 0,
  44. comment: '处理状态:0-未处理,1-已处理'
  45. },
  46. isEmailSent: {
  47. type: Sequelize.BOOLEAN,
  48. defaultValue: false,
  49. comment: '是否已发送邮件通知'
  50. },
  51. createdAt: {
  52. allowNull: false,
  53. type: Sequelize.DATE
  54. },
  55. updatedAt: {
  56. allowNull: false,
  57. type: Sequelize.DATE
  58. }
  59. });
  60. // 添加索引
  61. await queryInterface.addIndex('contacts', ['email']);
  62. await queryInterface.addIndex('contacts', ['status']);
  63. await queryInterface.addIndex('contacts', ['createdAt']);
  64. },
  65. down: async (queryInterface, Sequelize) => {
  66. await queryInterface.dropTable('contacts');
  67. }
  68. };