oms/backend/database/migrations/20260909000101-create-principals.js

43 lines
1.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
/** 2. 主体表:独立经营/组织主体,业务数据(商品、订单等)均挂在主体下 */
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.createTable(
'principals',
{
id: {
type: Sequelize.BIGINT.UNSIGNED,
allowNull: false,
autoIncrement: true,
primaryKey: true,
},
code: { type: Sequelize.STRING(50), allowNull: false, comment: '主体编码' },
name: { type: Sequelize.STRING(100), allowNull: false, comment: '主体名称' },
type: { type: Sequelize.TINYINT, allowNull: false, defaultValue: 1, comment: '主体类型:1自营 2加盟 3外部' },
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禁用' },
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('principals', { fields: [ 'code' ], unique: true, name: 'uk_principals_code' });
},
async down(queryInterface) {
await queryInterface.dropTable('principals');
},
};