'use strict'; /** 9. 店铺表:归属于具体主体,一个主体可有多个平台店铺 */ module.exports = { async up(queryInterface, Sequelize) { await queryInterface.createTable( 'shops', { 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' }, }, code: { type: Sequelize.STRING(50), allowNull: false, comment: '店铺编码(平台店铺ID或自定义编码)' }, name: { type: Sequelize.STRING(100), allowNull: false, comment: '店铺名称' }, platform: { type: Sequelize.STRING(50), allowNull: true, comment: '所属平台:taobao/pdd/douyin/jd/other' }, contact_name: { type: Sequelize.STRING(50), allowNull: true, comment: '联系人' }, contact_phone: { type: Sequelize.STRING(20), allowNull: true, comment: '联系电话' }, status: { type: Sequelize.TINYINT, allowNull: false, defaultValue: 1, comment: '状态:1启用 0禁用' }, extra: { type: Sequelize.JSON, allowNull: true, comment: '扩展配置 JSON:授权信息、接口参数等' }, 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('shops', { fields: [ 'principal_id', 'code' ], unique: true, name: 'uk_shops_principal_code', }); await queryInterface.addIndex('shops', { fields: [ 'principal_id' ], name: 'idx_shops_principal' }); await queryInterface.addIndex('shops', { fields: [ 'platform' ], name: 'idx_shops_platform' }); }, async down(queryInterface) { await queryInterface.dropTable('shops'); }, };