feat: 修改数据库迁移脚本和模型,创建用户表并定义User模型

This commit is contained in:
zyh 2024-10-22 01:59:01 +00:00
parent 052bc6e0aa
commit fd34ac25ce
3 changed files with 7 additions and 8 deletions

View File

@ -1,4 +1,4 @@
exports.up = function(knex) {
export function up(knex) {
return knex.schema.createTable('users', function(table) {
table.increments('_id').primary().comment('主键ID');
table.string('username', 255).notNullable().unique().comment('用户名');
@ -13,8 +13,8 @@ exports.up = function(knex) {
table.timestamp('_create').defaultTo(knex.fn.now()).comment('创建时间');
table.timestamp('_update').defaultTo(knex.fn.now()).comment('更新时间');
});
};
}
exports.down = function(knex) {
export function down(knex) {
return knex.schema.dropTable('users');
};
}

View File

@ -1,6 +1,6 @@
const { Model } = require('objection');
import { Model } from 'objection';
class User extends Model {
export class User extends Model {
static get tableName() {
return 'users';
}
@ -26,4 +26,3 @@ class User extends Model {
}
}
module.exports = User;

View File

@ -1,5 +1,5 @@
// knexfile.js
module.exports = {
export default {
development: {
client: 'mysql2',
connection: {