WMS_MAIN/database/migrations/20260522123000-add-auth-result-fields-to-wms-shops.js
liufumingren dc4894cb6d 1
2026-05-25 17:08:56 +08:00

103 lines
2.9 KiB
JavaScript

'use strict';
/**
* 为店铺表新增授权结果字段。
* @param {import('sequelize').QueryInterface} queryInterface 查询接口
* @param {import('sequelize')} Sequelize Sequelize 实例
* @return {Promise<void>} 无返回值
*/
module.exports = {
/**
* 执行迁移:新增授权结果字段(幂等)。
* @param {import('sequelize').QueryInterface} queryInterface 查询接口
* @param {import('sequelize')} Sequelize Sequelize 实例
* @return {Promise<void>} 无返回值
*/
async up(queryInterface, Sequelize) {
const tableName = 'wms_shops';
const columns = await queryInterface.describeTable(tableName);
if (!columns.owner_id) {
await queryInterface.addColumn(tableName, 'owner_id', {
type: Sequelize.STRING(64),
allowNull: true,
comment: '平台店铺/主体ID',
});
}
if (!columns.access_token) {
await queryInterface.addColumn(tableName, 'access_token', {
type: Sequelize.STRING(255),
allowNull: true,
comment: '访问令牌',
});
}
if (!columns.refresh_token) {
await queryInterface.addColumn(tableName, 'refresh_token', {
type: Sequelize.STRING(255),
allowNull: true,
comment: '刷新令牌',
});
}
if (!columns.token_expires_at) {
await queryInterface.addColumn(tableName, 'token_expires_at', {
type: Sequelize.DATE,
allowNull: true,
comment: '访问令牌过期时间',
});
}
if (!columns.refresh_token_expires_at) {
await queryInterface.addColumn(tableName, 'refresh_token_expires_at', {
type: Sequelize.DATE,
allowNull: true,
comment: '刷新令牌过期时间',
});
}
if (!columns.scope) {
await queryInterface.addColumn(tableName, 'scope', {
type: Sequelize.JSON,
allowNull: true,
comment: '授权范围',
});
}
},
/**
* 回滚迁移:删除授权结果字段(幂等)。
* @param {import('sequelize').QueryInterface} queryInterface 查询接口
* @return {Promise<void>} 无返回值
*/
async down(queryInterface) {
const tableName = 'wms_shops';
const columns = await queryInterface.describeTable(tableName);
if (columns.scope) {
await queryInterface.removeColumn(tableName, 'scope');
}
if (columns.refresh_token_expires_at) {
await queryInterface.removeColumn(tableName, 'refresh_token_expires_at');
}
if (columns.token_expires_at) {
await queryInterface.removeColumn(tableName, 'token_expires_at');
}
if (columns.refresh_token) {
await queryInterface.removeColumn(tableName, 'refresh_token');
}
if (columns.access_token) {
await queryInterface.removeColumn(tableName, 'access_token');
}
if (columns.owner_id) {
await queryInterface.removeColumn(tableName, 'owner_id');
}
},
};