'use strict'; /** * 创建微信开放平台授权小程序表 wms_wechat_app。 * * 用途:仓库(主体)在微信开放平台将自己主体下的小程序授权给本系统提供服务, * 记录小程序授权信息(appid/名称/授权令牌)与仓库的绑定关系(warehouse_id)。 * 小程序归属仓库主体,1 个仓库可授权多个小程序。 * * 令牌说明: * - authorizer_refresh_token:授权方刷新令牌,长期有效,用于刷新接口调用凭证。 * - authorizer_access_token:授权方接口调用凭证,约 2 小时有效,过期后用 * refresh_token 刷新并回写本表。 * * 索引: * - uk_appid:appid 唯一(同一小程序只允许授权一次)。 * - idx_warehouse_id:按仓库查询其已授权小程序列表。 */ const TABLE_NAME = 'wms_wechat_app'; module.exports = { // eslint-disable-next-line no-unused-vars async up(queryInterface, Sequelize) { const { BIGINT, STRING, INTEGER, TINYINT, DATE } = Sequelize; await queryInterface.createTable(TABLE_NAME, { id: { type: BIGINT(20).UNSIGNED, primaryKey: true, autoIncrement: true, allowNull: false, comment: '主键', }, warehouse_id: { type: BIGINT(20).UNSIGNED, allowNull: false, comment: '仓库ID(小程序归属主体,绑定关系)', }, appid: { type: STRING(64), allowNull: false, comment: '小程序AppID', }, nickname: { type: STRING(100), allowNull: true, comment: '小程序名称', }, user_name: { type: STRING(100), allowNull: true, comment: '小程序原始ID(gh_xxx)', }, head_img: { type: STRING(500), allowNull: true, comment: '小程序头像URL', }, app_secret: { type: STRING(64), allowNull: true, comment: '小程序密钥(按需配置)', }, authorizer_refresh_token: { type: STRING(255), allowNull: true, comment: '授权方刷新令牌(长期有效)', }, authorizer_access_token: { type: STRING(512), allowNull: true, comment: '授权方接口调用凭证(约2小时有效)', }, access_token_expire_time: { type: INTEGER(11), allowNull: true, comment: '接口调用凭证过期时间(unix秒级时间戳)', }, auth_time: { type: INTEGER(11), allowNull: true, comment: '授权时间(unix秒级时间戳)', }, is_enabled: { type: TINYINT(1), allowNull: false, defaultValue: 1, comment: '是否启用:1=启用,0=停用', }, created_at: { type: DATE, allowNull: false, comment: '创建时间' }, updated_at: { type: DATE, allowNull: false, comment: '更新时间' }, }); await queryInterface.addIndex(TABLE_NAME, [ 'appid' ], { unique: true, name: 'uk_appid', }); await queryInterface.addIndex(TABLE_NAME, [ 'warehouse_id' ], { name: 'idx_warehouse_id', }); }, // eslint-disable-next-line no-unused-vars async down(queryInterface, Sequelize) { await queryInterface.dropTable(TABLE_NAME); }, };