'use strict';

module.exports = {
  async up(queryInterface, Sequelize) {
    await queryInterface.createTable('welding_visual_inspection_report_detail', {
      id: { type: Sequelize.INTEGER, primaryKey: true, autoIncrement: true, allowNull: false },
      wvir_id: { type: Sequelize.INTEGER, allowNull: false },
      line_no: { type: Sequelize.INTEGER, allowNull: false },
      sub_part_code: { type: Sequelize.STRING(120), allowNull: true },
      sub_part_name: { type: Sequelize.STRING(250), allowNull: true },
      qty: { type: Sequelize.DECIMAL(18, 3), allowNull: true, defaultValue: 0 },
      sample_1: { type: Sequelize.STRING(20), allowNull: true },
      sample_2: { type: Sequelize.STRING(20), allowNull: true },
      sample_3: { type: Sequelize.STRING(20), allowNull: true },
      sample_4: { type: Sequelize.STRING(20), allowNull: true },
      sample_5: { type: Sequelize.STRING(20), allowNull: true },
      sample_6: { type: Sequelize.STRING(20), allowNull: true },
      sample_7: { type: Sequelize.STRING(20), allowNull: true },
      sample_8: { type: Sequelize.STRING(20), allowNull: true },
      sample_9: { type: Sequelize.STRING(20), allowNull: true },
      sample_10: { type: Sequelize.STRING(20), allowNull: true },
      remark: { type: Sequelize.STRING(255), allowNull: true },
      line_status: { type: Sequelize.STRING(30), allowNull: true },
      created_at: { type: Sequelize.DATE, allowNull: false, defaultValue: Sequelize.literal('CURRENT_TIMESTAMP') },
      updated_at: {
        type: Sequelize.DATE,
        allowNull: false,
        defaultValue: Sequelize.literal('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP')
      }
    });
    await queryInterface.addIndex('welding_visual_inspection_report_detail', ['wvir_id']);
    await queryInterface.addIndex('welding_visual_inspection_report_detail', ['wvir_id', 'line_no'], {
      unique: true,
      name: 'uk_wvir_detail_line'
    });
  },

  async down(queryInterface) {
    await queryInterface.dropTable('welding_visual_inspection_report_detail');
  }
};

