'use strict'; /** * 商品品牌字典表:product_brands * 定位:按主体隔离(principal_id),供商品选择「品牌」时落 brand_id + brand_name。 * 同一主体下品牌名称唯一(uk_product_brands_principal_name),名称即展示文本。 */ module.exports = { async up(queryInterface, Sequelize) { await queryInterface.createTable( 'product_brands', { id: { type: Sequelize.BIGINT.UNSIGNED, allowNull: false, autoIncrement: true, primaryKey: true }, principal_id: { type: Sequelize.BIGINT.UNSIGNED, allowNull: false, comment: '所属主体ID' }, name: { type: Sequelize.STRING(100), allowNull: false, comment: '品牌名称' }, code: { type: Sequelize.STRING(50), allowNull: true, comment: '品牌编码' }, status: { type: Sequelize.TINYINT, allowNull: false, defaultValue: 1, comment: '状态:1启用 0禁用' }, sort: { type: Sequelize.INTEGER, allowNull: false, defaultValue: 0, comment: '排序(下拉展示顺序,越小越靠前)' }, 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('product_brands', { fields: [ 'principal_id', 'name' ], unique: true, name: 'uk_product_brands_principal_name', }); await queryInterface.addIndex('product_brands', { fields: [ 'principal_id', 'status', 'sort' ], name: 'idx_product_brands_p_s_sort' }); }, async down(queryInterface) { await queryInterface.dropTable('product_brands'); }, };