1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- // 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');
- }
- };
|