1725485641-create-users-table.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. import { Sequelize, DataTypes } from "sequelize";
  2. import { MigrationParams } from "umzug";
  3. export const up = async ({
  4. context: sequelize
  5. }: MigrationParams<Sequelize>) => {
  6. await sequelize.getQueryInterface().createTable("users", {
  7. _id: {
  8. // eslint-disable-next-line
  9. // @ts-ignore
  10. type: DataTypes.OBJECTID,
  11. autoNull: false,
  12. primaryKey: true
  13. },
  14. username: {
  15. type: DataTypes.STRING,
  16. allowNull: false
  17. },
  18. role: {
  19. type: DataTypes.ENUM("admin", "moderator", "user"),
  20. allowNull: false
  21. },
  22. emailVerified: {
  23. type: DataTypes.BOOLEAN,
  24. allowNull: true,
  25. defaultValue: false
  26. },
  27. emailVerificationToken: {
  28. type: DataTypes.STRING,
  29. allowNull: true
  30. },
  31. emailAddress: {
  32. type: DataTypes.STRING,
  33. allowNull: false
  34. },
  35. avatarType: {
  36. type: DataTypes.ENUM("gravatar", "initials"),
  37. allowNull: false
  38. },
  39. avatarUrl: {
  40. type: DataTypes.STRING,
  41. allowNull: true
  42. },
  43. avatarColor: {
  44. type: DataTypes.ENUM(
  45. "blue",
  46. "green",
  47. "orange",
  48. "purple",
  49. "red",
  50. "teal"
  51. ),
  52. allowNull: true
  53. },
  54. password: {
  55. type: DataTypes.STRING,
  56. allowNull: false
  57. },
  58. passwordResetCode: {
  59. type: DataTypes.STRING,
  60. allowNull: true
  61. },
  62. passwordResetExpiresAt: {
  63. type: DataTypes.DATE,
  64. allowNull: true
  65. },
  66. passwordSetCode: {
  67. type: DataTypes.STRING,
  68. allowNull: true
  69. },
  70. passwordSetExpiresAt: {
  71. type: DataTypes.DATE,
  72. allowNull: true
  73. },
  74. githubId: {
  75. type: DataTypes.BIGINT,
  76. allowNull: true
  77. },
  78. githubAccessToken: {
  79. type: DataTypes.STRING,
  80. allowNull: true
  81. },
  82. songsRequested: {
  83. type: DataTypes.BIGINT,
  84. allowNull: false,
  85. defaultValue: 0
  86. },
  87. name: {
  88. type: DataTypes.STRING,
  89. allowNull: false
  90. },
  91. location: {
  92. type: DataTypes.STRING,
  93. allowNull: true
  94. },
  95. bio: {
  96. type: DataTypes.STRING,
  97. allowNull: true
  98. },
  99. nightmode: {
  100. type: DataTypes.BOOLEAN,
  101. allowNull: false,
  102. defaultValue: false
  103. },
  104. autoSkipDisliked: {
  105. type: DataTypes.BOOLEAN,
  106. allowNull: false,
  107. defaultValue: true
  108. },
  109. activityLogPublic: {
  110. type: DataTypes.BOOLEAN,
  111. allowNull: false,
  112. defaultValue: false
  113. },
  114. anonymousSongRequests: {
  115. type: DataTypes.BOOLEAN,
  116. allowNull: false,
  117. defaultValue: false
  118. },
  119. activityWatch: {
  120. type: DataTypes.BOOLEAN,
  121. allowNull: false,
  122. defaultValue: false
  123. },
  124. createdAt: DataTypes.DATE,
  125. updatedAt: DataTypes.DATE
  126. });
  127. await sequelize.query(
  128. "ALTER TABLE users " +
  129. 'ADD COLUMN "hasPassword" ' +
  130. "BOOLEAN GENERATED ALWAYS AS " +
  131. '("password" IS NOT NULL) ' +
  132. "STORED"
  133. );
  134. };
  135. export const down = async ({
  136. context: sequelize
  137. }: MigrationParams<Sequelize>) => {
  138. await sequelize.getQueryInterface().dropTable("users");
  139. };