'use strict'; /** * 下属公司表:组织架构 → 下属公司。 * * 每条记录归属于一个主体(principal_id,即顶部下拉选中的集团主体), * 仅用于维护集团下的公司档案,不参与业务数据(商品/订单)归属。 */ module.exports = { async up(queryInterface, Sequelize) { await queryInterface.createTable( 'principal_subsidiaries', { id: { type: Sequelize.BIGINT.UNSIGNED, allowNull: false, autoIncrement: true, primaryKey: true, }, principal_id: { type: Sequelize.BIGINT.UNSIGNED, allowNull: false, comment: '所属主体(集团)ID', references: { model: 'principals', key: 'id' }, }, name: { type: Sequelize.STRING(100), allowNull: false, comment: '公司名称' }, credit_code: { type: Sequelize.STRING(50), allowNull: true, comment: '统一社会信用代码' }, contact_name: { type: Sequelize.STRING(50), allowNull: true, comment: '联系人' }, contact_phone: { type: Sequelize.STRING(20), allowNull: true, comment: '联系电话' }, address: { type: Sequelize.STRING(255), allowNull: true, comment: '公司地址' }, status: { type: Sequelize.TINYINT, allowNull: false, defaultValue: 1, comment: '状态:1启用 0禁用' }, remark: { type: Sequelize.STRING(255), allowNull: true, comment: '备注' }, 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'), }, }, { charset: 'utf8mb4', collate: 'utf8mb4_unicode_ci', comment: '下属公司表' } ); await queryInterface.addIndex('principal_subsidiaries', { fields: [ 'principal_id', 'name' ], unique: true, name: 'uk_principal_subsidiaries_principal_name', }); }, async down(queryInterface) { await queryInterface.dropTable('principal_subsidiaries'); }, };