20230712153348-init-users.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. 'use strict';
  2. /** @type {import('sequelize-cli').Migration} */
  3. module.exports = {
  4. async up(queryInterface, Sequelize) {
  5. /**
  6. * Add altering commands here.
  7. *
  8. * Example:
  9. * await queryInterface.createTable('users', { id: Sequelize.INTEGER });
  10. */
  11. const { INTEGER, DATE, STRING } = Sequelize;
  12. await queryInterface.createTable('users', {
  13. id: {
  14. type: INTEGER,
  15. primaryKey: true,
  16. autoIncrement: true,
  17. notNull: true,
  18. notEmpty: true,
  19. comment: '用户ID',
  20. },
  21. username: {
  22. type: STRING(30),
  23. notNull: true,
  24. notEmpty: true,
  25. comment: '用户名',
  26. },
  27. name: {
  28. type: STRING(30),
  29. notNull: true,
  30. notEmpty: true,
  31. comment: '用户名',
  32. },
  33. password: {
  34. type: STRING,
  35. notNull: true,
  36. notEmpty: true,
  37. defaultValue: '',
  38. comment: '用户密码',
  39. },
  40. salt: {
  41. type: STRING(6),
  42. notNull: true,
  43. notEmpty: true,
  44. defaultValue: '',
  45. comment: '用户密码盐',
  46. },
  47. state: {
  48. type: INTEGER,
  49. notNull: true,
  50. notEmpty: true,
  51. defaultValue: 0,
  52. comment: '用户状态: 二进制状态, 从右到左, 是否激活, 是否禁止登录, 是否禁用 0为正常状态',
  53. },
  54. last_login: {
  55. type: DATE,
  56. notNull: true,
  57. notEmpty: true,
  58. defaultValue: '1971-01-01 00:00',
  59. comment: '最后登录时间',
  60. },
  61. created_at: DATE,
  62. updated_at: DATE,
  63. }, {});
  64. },
  65. async down(queryInterface) {
  66. /**
  67. * Add reverting commands here.
  68. *
  69. * Example:
  70. * await queryInterface.dropTable('users');
  71. */
  72. await queryInterface.dropTable('users');
  73. },
  74. };