// migrations/20250225000000-create-categories-table.js 'use strict'; module.exports = { async up(queryInterface, Sequelize) { await queryInterface.createTable('categories', { id: { type: Sequelize.INTEGER, primaryKey: true, autoIncrement: true }, name: { type: Sequelize.STRING, allowNull: false }, level: { type: Sequelize.INTEGER, defaultValue: 1 }, description: { type: Sequelize.TEXT, allowNull: true }, parentId: { type: Sequelize.INTEGER, allowNull: true, references: { model: 'categories', key: 'id' }, onDelete: 'CASCADE' }, order: { type: Sequelize.INTEGER, defaultValue: 0 }, isActive: { type: Sequelize.BOOLEAN, defaultValue: true }, createdAt: { type: Sequelize.DATE, allowNull: false }, updatedAt: { type: Sequelize.DATE, allowNull: false } }); // 添加索引 await queryInterface.addIndex('categories', ['parentId']); await queryInterface.addIndex('categories', ['name']); }, async down(queryInterface, Sequelize) { await queryInterface.dropTable('categories'); } };