85 lines
2.7 KiB
JavaScript
85 lines
2.7 KiB
JavaScript
'use strict';
|
||
|
||
/**
|
||
* 用户须知改为副表版本管理(2026-09-23):
|
||
* 1. 移除 wms_wechat_app.user_agreement 字段(富文本改为副表存储);
|
||
* 2. 新增副表 wms_wechat_agreement_version:appid + 数字版本号 + 富文本,
|
||
* 提交一次自动新增版本,拉取只取最新版本;
|
||
* 3. wms_user_oauth 增加 agreement_version_id(协议版本id),loginByCode 时自动更新到最新。
|
||
*/
|
||
|
||
const APP_TABLE = 'wms_wechat_app';
|
||
const VERSION_TABLE = 'wms_wechat_agreement_version';
|
||
const OAUTH_TABLE = 'wms_user_oauth';
|
||
|
||
module.exports = {
|
||
async up(queryInterface, Sequelize) {
|
||
await queryInterface.removeColumn(APP_TABLE, 'user_agreement');
|
||
|
||
await queryInterface.createTable(VERSION_TABLE, {
|
||
id: {
|
||
type: Sequelize.BIGINT(20).UNSIGNED,
|
||
primaryKey: true,
|
||
autoIncrement: true,
|
||
allowNull: false,
|
||
comment: '主键',
|
||
},
|
||
appid: {
|
||
type: Sequelize.STRING(64),
|
||
allowNull: false,
|
||
comment: '小程序AppID(关联 wms_wechat_app.appid)',
|
||
},
|
||
version: {
|
||
type: Sequelize.INTEGER,
|
||
allowNull: false,
|
||
comment: '协议版本号(数字,同一 appid 内自动+1)',
|
||
},
|
||
content: {
|
||
type: Sequelize.TEXT('long'),
|
||
allowNull: true,
|
||
defaultValue: null,
|
||
comment: '用户须知富文本内容',
|
||
},
|
||
created_at: {
|
||
type: Sequelize.DATE,
|
||
allowNull: false,
|
||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
|
||
comment: '创建时间',
|
||
},
|
||
updated_at: {
|
||
type: Sequelize.DATE,
|
||
allowNull: false,
|
||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
|
||
comment: '更新时间',
|
||
},
|
||
}, {
|
||
comment: '微信用户须知版本表(副表,提交一次新增一个版本)',
|
||
});
|
||
await queryInterface.addIndex(VERSION_TABLE, [ 'appid', 'version' ], {
|
||
unique: true,
|
||
name: 'uk_appid_version',
|
||
});
|
||
await queryInterface.addIndex(VERSION_TABLE, [ 'appid' ], {
|
||
name: 'idx_appid',
|
||
});
|
||
|
||
await queryInterface.addColumn(OAUTH_TABLE, 'agreement_version_id', {
|
||
type: Sequelize.BIGINT(20).UNSIGNED,
|
||
allowNull: true,
|
||
defaultValue: null,
|
||
comment: '协议版本ID(关联 wms_wechat_agreement_version.id,loginByCode 时自动更新到最新)',
|
||
});
|
||
},
|
||
|
||
async down(queryInterface, Sequelize) {
|
||
await queryInterface.removeColumn(OAUTH_TABLE, 'agreement_version_id');
|
||
await queryInterface.dropTable(VERSION_TABLE);
|
||
await queryInterface.addColumn(APP_TABLE, 'user_agreement', {
|
||
type: Sequelize.TEXT('long'),
|
||
allowNull: true,
|
||
defaultValue: null,
|
||
comment: '用户须知(富文本 longText)',
|
||
});
|
||
},
|
||
};
|