37 lines
1.5 KiB
PowerShell
37 lines
1.5 KiB
PowerShell
# Finish slim for sys_role_permission with dedupe.
|
|
$ErrorActionPreference = "Continue"
|
|
$mysql = "C:\yutongda\tools\mysql-8.0.39-winx64\bin\mysql.exe"
|
|
$envFile = "E:\wwwroot\.env"
|
|
$hostn = "10.206.0.15"; $user = "inquiry_robot"; $pass = $null; $db = "inquiry_robot"
|
|
Get-Content $envFile | ForEach-Object {
|
|
if ($_ -match '^MYSQL_HOST=(.+)$') { $hostn = $Matches[1].Trim() }
|
|
if ($_ -match '^MYSQL_USER=(.+)$') { $user = $Matches[1].Trim() }
|
|
if ($_ -match '^MYSQL_PASSWORD=(.+)$') { $pass = $Matches[1].Trim() }
|
|
if ($_ -match '^MYSQL_DB=(.+)$') { $db = $Matches[1].Trim() }
|
|
}
|
|
|
|
$sql = @"
|
|
SET FOREIGN_KEY_CHECKS=0;
|
|
DROP TABLE IF EXISTS sys_role_permission_new;
|
|
CREATE TABLE sys_role_permission_new (
|
|
id varchar(32) NOT NULL,
|
|
role_id varchar(32) NOT NULL,
|
|
permission_id varchar(32) NOT NULL,
|
|
PRIMARY KEY (id),
|
|
UNIQUE KEY uk_role_perm (role_id, permission_id)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='角色权限关联';
|
|
INSERT INTO sys_role_permission_new (id, role_id, permission_id)
|
|
SELECT MIN(id), role_id, permission_id
|
|
FROM sys_role_permission
|
|
GROUP BY role_id, permission_id;
|
|
DROP TABLE sys_role_permission;
|
|
RENAME TABLE sys_role_permission_new TO sys_role_permission;
|
|
SET FOREIGN_KEY_CHECKS=1;
|
|
SHOW COLUMNS FROM sys_role_permission;
|
|
"@
|
|
$sqlFile = "E:\wwwroot\ops\sql\_slim_role_perm.sql"
|
|
[System.IO.File]::WriteAllText($sqlFile, $sql)
|
|
& $mysql -h $hostn -P 3306 -u $user "-p$pass" $db -e "source $($sqlFile -replace '\\','/')" 2>&1 |
|
|
Where-Object { $_ -notmatch "Warning|password" }
|
|
Write-Output "ROLE_PERM_SLIM_OK"
|