Browse Source

已成功创建迁移文件 server/migrations/015_addRoleAndValidUntilToUsers.ts,为users表添加了role和valid_until字段。文件格式已统一使用项目标准的MigrationLiveDefinition接口。

yourname 6 months ago
parent
commit
fb919aaa3a
1 changed files with 24 additions and 0 deletions
  1. 24 0
      server/migrations/015_addRoleAndValidUntilToUsers.ts

+ 24 - 0
server/migrations/015_addRoleAndValidUntilToUsers.ts

@@ -0,0 +1,24 @@
+import type { MigrationLiveDefinition } from '@d8d-appcontainer/types'
+
+const addRoleAndValidUntilToUsers: MigrationLiveDefinition = {
+  name: "add_role_and_valid_until_to_users",
+  up: async (api) => {
+    await api.schema.alterTable('users', (table) => {
+      // 用户角色: teacher(教师)/admin(管理员)/student(学生)/fan(粉丝)
+      table.enum('role', ['teacher', 'admin', 'student', 'fan'])
+        .notNullable()
+        .defaultTo('student');
+        
+      // 账户有效期,为空表示永久有效
+      table.timestamp('valid_until').nullable();
+    });
+  },
+  down: async (api) => {
+    await api.schema.alterTable('users', (table) => {
+      table.dropColumn('role');
+      table.dropColumn('valid_until');
+    });
+  }
+}
+
+export default addRoleAndValidUntilToUsers;