更新密码管理
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
-- ============================================================
|
||||
-- 密码存储:单账号结构 -> 一个平台挂载多个账号(accounts JSON)
|
||||
--
|
||||
-- 使用说明:
|
||||
-- 1. 先备份:
|
||||
-- mysqldump -u用户 -p 库名 yz_platform_password_store yz_backend_password_store > pwd_backup.sql
|
||||
-- 2. 按顺序执行下面的「第 1 步」「第 2 步」「第 3 步」。
|
||||
-- 3. 如果某条 ALTER 报 "Duplicate column name 'accounts'",说明该列已存在,
|
||||
-- 忽略该条错误继续往下执行即可。
|
||||
-- 4. 「第 4 步」删除旧列不可逆,确认页面数据显示正常后再手动执行。
|
||||
-- ============================================================
|
||||
|
||||
|
||||
-- ---------- 第 1 步:新增 accounts 列 ----------
|
||||
-- 报 Duplicate column name 表示已加过,忽略即可。
|
||||
|
||||
ALTER TABLE `yz_platform_password_store`
|
||||
ADD COLUMN `accounts` longtext NULL
|
||||
COMMENT '账号列表JSON: [{"username":"","password":"","registration_info":"","remark":""}]'
|
||||
AFTER `url`;
|
||||
|
||||
ALTER TABLE `yz_backend_password_store`
|
||||
ADD COLUMN `accounts` longtext NULL
|
||||
COMMENT '账号列表JSON: [{"username":"","password":"","registration_info":"","remark":""}]'
|
||||
AFTER `url`;
|
||||
|
||||
-- 旧表可能没有 delete_time 列,模型里有该字段,一并补上。
|
||||
-- 报 Duplicate column name 同样忽略。
|
||||
ALTER TABLE `yz_platform_password_store` ADD COLUMN `delete_time` datetime NULL;
|
||||
ALTER TABLE `yz_backend_password_store` ADD COLUMN `delete_time` datetime NULL;
|
||||
|
||||
|
||||
-- ---------- 第 2 步:把旧的单账号数据搬进 accounts ----------
|
||||
-- 只处理 accounts 仍为空、且旧列确实有内容的行,包装成只含一条账号的 JSON 数组。
|
||||
-- 如果报 Unknown column 'username',说明旧列已经删掉了,无需迁移,跳过这两条。
|
||||
|
||||
UPDATE `yz_platform_password_store`
|
||||
SET `accounts` = JSON_ARRAY(JSON_OBJECT(
|
||||
'username', IFNULL(`username`, ''),
|
||||
'password', IFNULL(`password`, ''),
|
||||
'registration_info', IFNULL(`registration_info`, ''),
|
||||
'remark', ''
|
||||
))
|
||||
WHERE (`accounts` IS NULL OR `accounts` = '' OR `accounts` = '[]')
|
||||
AND (IFNULL(`username`, '') <> ''
|
||||
OR IFNULL(`password`, '') <> ''
|
||||
OR IFNULL(`registration_info`, '') <> '');
|
||||
|
||||
UPDATE `yz_backend_password_store`
|
||||
SET `accounts` = JSON_ARRAY(JSON_OBJECT(
|
||||
'username', IFNULL(`username`, ''),
|
||||
'password', IFNULL(`password`, ''),
|
||||
'registration_info', IFNULL(`registration_info`, ''),
|
||||
'remark', ''
|
||||
))
|
||||
WHERE (`accounts` IS NULL OR `accounts` = '' OR `accounts` = '[]')
|
||||
AND (IFNULL(`username`, '') <> ''
|
||||
OR IFNULL(`password`, '') <> ''
|
||||
OR IFNULL(`registration_info`, '') <> '');
|
||||
|
||||
|
||||
-- ---------- 第 3 步:accounts 为空的行统一补成空数组 ----------
|
||||
|
||||
UPDATE `yz_platform_password_store` SET `accounts` = '[]'
|
||||
WHERE `accounts` IS NULL OR `accounts` = '';
|
||||
|
||||
UPDATE `yz_backend_password_store` SET `accounts` = '[]'
|
||||
WHERE `accounts` IS NULL OR `accounts` = '';
|
||||
|
||||
|
||||
-- ---------- 第 4 步(可选,不可逆):删除旧的单账号列 ----------
|
||||
-- 先在页面上确认历史数据都能正常显示,再手动执行下面两条。
|
||||
-- 旧表这三列是 NOT NULL DEFAULT '',不删也不影响新代码运行。
|
||||
|
||||
-- ALTER TABLE `yz_platform_password_store`
|
||||
-- DROP COLUMN `username`, DROP COLUMN `password`, DROP COLUMN `registration_info`;
|
||||
-- ALTER TABLE `yz_backend_password_store`
|
||||
-- DROP COLUMN `username`, DROP COLUMN `password`, DROP COLUMN `registration_info`;
|
||||
@@ -0,0 +1,37 @@
|
||||
-- 平台端和租户后台密码存储表。支持一个平台下挂载多个账号(每个账号包含账号、密码、注册信息、备注)。
|
||||
CREATE TABLE IF NOT EXISTS `yz_platform_password_store` (
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
|
||||
`platform` varchar(100) NOT NULL DEFAULT '' COMMENT '平台名称',
|
||||
`url` varchar(500) NOT NULL DEFAULT '' COMMENT '平台网址/登录地址',
|
||||
`accounts` longtext COMMENT '账号列表JSON: [{"username":"","password":"","registration_info":"","remark":""}]',
|
||||
`remark` text COMMENT '平台备注',
|
||||
`user_id` bigint unsigned NOT NULL COMMENT '所属用户ID',
|
||||
`is_deleted` tinyint NOT NULL DEFAULT 0,
|
||||
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`update_time` datetime DEFAULT NULL,
|
||||
`delete_time` datetime DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_platform_user` (`platform`,`user_id`),
|
||||
KEY `idx_user_deleted` (`user_id`,`is_deleted`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='平台密码存储';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `yz_backend_password_store` (
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
|
||||
`tid` bigint NOT NULL COMMENT '租户ID',
|
||||
`platform` varchar(100) NOT NULL DEFAULT '' COMMENT '平台名称',
|
||||
`url` varchar(500) NOT NULL DEFAULT '' COMMENT '平台网址/登录地址',
|
||||
`accounts` longtext COMMENT '账号列表JSON: [{"username":"","password":"","registration_info":"","remark":""}]',
|
||||
`remark` text COMMENT '平台备注',
|
||||
`user_id` bigint unsigned NOT NULL COMMENT '所属用户ID',
|
||||
`is_deleted` tinyint NOT NULL DEFAULT 0,
|
||||
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`update_time` datetime DEFAULT NULL,
|
||||
`delete_time` datetime DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_tid_user` (`tid`,`user_id`),
|
||||
KEY `idx_tid_platform` (`tid`,`platform`),
|
||||
KEY `idx_tid_deleted` (`tid`,`is_deleted`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='租户密码存储';
|
||||
|
||||
-- 已经按旧的「单账号」结构建过表的库,请执行
|
||||
-- sql/alter_password_store_to_multi_accounts.sql 完成升级与数据迁移。
|
||||
Reference in New Issue
Block a user