Files
competition-website/database/migrations/002-create-admins.js
WorkBuddy a303cf2d53 chore: 后端首次基线提交
运行必须源码:app/(controller/model/service/middleware/lib/utils/validate/router)、config/、database/(migrations/seeders/sql)、启动脚本、app/public/templates 模板。
已忽略运行非必须:node_modules/、logs/、run/、app/public 运行时上传数据、.env*、构建/缓存产物。
2026-08-17 12:25:42 +08:00

61 lines
1.4 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
'use strict';
/**
* 迁移文件:创建管理员表(admins)
* 存储后台管理员账号信息
*/
module.exports = {
/**
* 执行迁移:创建 admins 表
* @param {import('sequelize').QueryInterface} queryInterface
* @param {import('sequelize').Sequelize} Sequelize
*/
up: async (queryInterface, Sequelize) => {
const { INTEGER, STRING, DATE } = Sequelize;
await queryInterface.createTable('admins', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
allowNull: false,
comment: '管理员唯一标识',
},
username: {
type: STRING(50),
allowNull: false,
unique: true,
comment: '管理员用户名',
},
password: {
type: STRING(100),
allowNull: false,
comment: '管理员密码',
},
created_at: {
type: DATE,
allowNull: false,
comment: '创建时间',
},
updated_at: {
type: DATE,
allowNull: false,
comment: '更新时间',
},
});
await queryInterface.addIndex('admins', ['username'], {
unique: true,
name: 'idx_admins_username',
});
},
/**
* 回滚迁移:删除 admins 表
* @param {import('sequelize').QueryInterface} queryInterface
*/
down: async (queryInterface) => {
await queryInterface.dropTable('admins');
},
};