/** * @param { import("knex").Knex } knex * @returns { Promise } */ export const up = async knex => { return knex.schema.createTable("users", function (table) { table.increments("id").primary() // 自增主键 table.string("username", 100).notNullable().unique().comment("用户名") // 字符串字段(最大长度100) table.string("nickname", 100).comment("昵称") // 字符串字段(最大长度100) table.string("bio").comment("个人简介") table.string("avatar", 500).comment("头像") // 字符串字段(最大长度100) table.string("email", 100).unique().comment("邮箱") // 唯一邮箱 table.string("password", 100).notNullable().comment("密码") // 密码 table.string("role", 100).notNullable().defaultTo("user").comment("角色 user, admin") // 角色 user, admin table.string("phone", 100).comment("电话号码") table.string("status", 20).defaultTo("inactive").comment("用户状态 inactive, active") // 用户状态 inactive, active table.integer("age").unsigned().comment("年龄") // 无符号整数 table.timestamp("created_at").defaultTo(knex.fn.now()).comment("创建时间") // 创建时间 table.timestamp("updated_at").defaultTo(knex.fn.now()).comment("更新时间") // 更新时间 }) } /** * @param { import("knex").Knex } knex * @returns { Promise } */ export const down = async knex => { return knex.schema.dropTable("users") // 回滚时删除表 }