import { Entity, Column, PrimaryGeneratedColumn, CreateDateColumn, UpdateDateColumn } from 'typeorm'; @Entity('users') // 对应数据库表名 export class Users { // id:bigint、主键、非空、唯一、自增 @PrimaryGeneratedColumn({ type: 'bigint', comment: '主键ID' }) id: bigint; // username:varchar(50)、非空、唯一 @Column({ type: 'varchar', length: 50, nullable: false, unique: true, comment: '唯一用户名/登录名' }) username: string; // email:varchar(100)、允许空、唯一 @Column({ type: 'varchar', length: 100, nullable: true, unique: true, comment: '邮箱(用于找回/通知)' }) email: string; // phone:varchar(30)、允许空、唯一 @Column({ type: 'varchar', length: 30, nullable: true, unique: true, comment: '全球电话号码(用于找回/通知)' }) phone: string; // password_hash:varchar(255)、允许空 @Column({ type: 'varchar', length: 255, nullable: true, comment: '密码哈希(OAuth登录为空)' }) password_hash: string; // nickname:varchar(50)、非空 @Column({ type: 'varchar', length: 50, nullable: false, comment: '显示昵称(头顶显示)' }) nickname: string; // github_id:varchar(100)、允许空、唯一 @Column({ type: 'varchar', length: 100, nullable: true, unique: true, comment: 'GitHub OpenID(第三方登录用)' }) github_id: string; // avatar_url:varchar(255)、允许空 @Column({ type: 'varchar', length: 255, nullable: true, comment: 'GitHub头像或自定义头像URL' }) avatar_url: string; // role:tinyint、非空、默认1 @Column({ type: 'tinyint', nullable: false, default: 1, comment: '角色:1-普通,9-管理员' }) role: number; // created_at:datetime、非空、默认当前时间 @CreateDateColumn({ type: 'datetime', nullable: false, default: () => 'CURRENT_TIMESTAMP', comment: '注册时间' }) created_at: Date; // updated_at:datetime、非空、默认当前时间 @UpdateDateColumn({ type: 'datetime', nullable: false, default: () => 'CURRENT_TIMESTAMP', onUpdate: 'CURRENT_TIMESTAMP', // 数据库更新时自动刷新时间 comment: '更新时间' }) updated_at: Date; }