56 lines
2.0 KiB
JavaScript
56 lines
2.0 KiB
JavaScript
'use strict';
|
||
|
||
/** 5. 组合商品表:多个普通商品的组合(套餐),归属于具体主体 */
|
||
module.exports = {
|
||
async up(queryInterface, Sequelize) {
|
||
await queryInterface.createTable(
|
||
'combo_products',
|
||
{
|
||
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: '组合商品编码' },
|
||
name: { type: Sequelize.STRING(100), allowNull: false, comment: '组合商品名称' },
|
||
price: { type: Sequelize.DECIMAL(12, 2), allowNull: false, defaultValue: 0, comment: '组合商品售价' },
|
||
items: {
|
||
type: Sequelize.JSON,
|
||
allowNull: true,
|
||
comment: '组合明细:[{ "product_id": 1, "quantity": 2 }],关联 products.id',
|
||
},
|
||
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('combo_products', {
|
||
fields: [ 'principal_id', 'code' ],
|
||
unique: true,
|
||
name: 'uk_combo_products_principal_code',
|
||
});
|
||
},
|
||
|
||
async down(queryInterface) {
|
||
await queryInterface.dropTable('combo_products');
|
||
},
|
||
};
|