015_addRoleAndValidUntilToUsers.ts 791 B

123456789101112131415161718192021222324
  1. import type { MigrationLiveDefinition } from '@d8d-appcontainer/types'
  2. const addRoleAndValidUntilToUsers: MigrationLiveDefinition = {
  3. name: "add_role_and_valid_until_to_users",
  4. up: async (api) => {
  5. await api.schema.alterTable('users', (table) => {
  6. // 用户角色: teacher(教师)/admin(管理员)/student(学生)/fan(粉丝)
  7. table.enum('role', ['teacher', 'admin', 'student', 'fan'])
  8. .notNullable()
  9. .defaultTo('student');
  10. // 账户有效期,为空表示永久有效
  11. table.timestamp('valid_until').nullable();
  12. });
  13. },
  14. down: async (api) => {
  15. await api.schema.alterTable('users', (table) => {
  16. table.dropColumn('role');
  17. table.dropColumn('valid_until');
  18. });
  19. }
  20. }
  21. export default addRoleAndValidUntilToUsers;