'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
  async up (queryInterface, Sequelize) {
    // 检查并添加缺失的字段到Articles表
    const tableDescription = await queryInterface.describeTable('Articles');
    
    if (!tableDescription.author) {
      await queryInterface.addColumn('Articles', 'author', {
        type: Sequelize.TEXT,
        allowNull: true,
      });
    }

    if (!tableDescription.category) {
      await queryInterface.addColumn('Articles', 'category', {
        type: Sequelize.INTEGER,
        allowNull: true,
      });
    }

    if (!tableDescription.crop) {
      await queryInterface.addColumn('Articles', 'crop', {
        type: Sequelize.INTEGER,
        allowNull: true,
      });
    }

    if (!tableDescription.seoKeyword) {
      await queryInterface.addColumn('Articles', 'seoKeyword', {
        type: Sequelize.TEXT,
        allowNull: true,
      });
    }

    if (!tableDescription.seoDescription) {
      await queryInterface.addColumn('Articles', 'seoDescription', {
        type: Sequelize.TEXT,
        allowNull: true,
      });
    }
  },

  async down (queryInterface, Sequelize) {
    // 删除添加的字段
    await queryInterface.removeColumn('Articles', 'author');
    await queryInterface.removeColumn('Articles', 'category');
    await queryInterface.removeColumn('Articles', 'crop');
    await queryInterface.removeColumn('Articles', 'seoKeyword');
    await queryInterface.removeColumn('Articles', 'seoDescription');
  }
};
