diff --git a/script/creadb.ps1 b/script/creadb.ps1 index f7db85d9..9e996242 100644 --- a/script/creadb.ps1 +++ b/script/creadb.ps1 @@ -7,8 +7,8 @@ if (-not (Test-Path $env:logDir)) { New-Item -ItemType Directory -Path $env:logDir | Out-Null } $sqlbase = Join-Path $env:workdir "sql" -$env:dbUser = "F701264" -$env:dbPassword = "contrsei" +$env:dbUser = "sa" +$env:dbPassword = "_p1sap1a" $env:dbHost = "DATABASE_PDC_LOCALE" $scriptName = $MyInvocation.MyCommand.Name $logFile = Join-Path $env:logDir "${scriptName}.log" # for debug @@ -16,9 +16,9 @@ $logFile = Join-Path $env:logDir "${scriptName}.log" # for debug # List of SQL files to execute in order $sqlFiles = @( - # "C6SC01_creadb.sql", - # "C6SC08_creauser.sql", - # "StampeCentralizzateBackupRidotto.sql", + "C6SC01_creadb.sql", + "C6SC08_creauser.sql", + "StampeCentralizzateBackupRidotto.sql", "dbo.LogN.sql", "" ) @@ -59,12 +59,12 @@ foreach ($fileName in $sqlFiles) { $(Get-Date -Format "yyyy-MM-dd_HH:mm:ss")+" $esitoComando" $(Get-Date -Format "yyyy-MM-dd_HH:mm:ss")+" ERROR per $fileSql, risultato in $fileLog " | Out-File -FilePath $logFile -Append $(Get-Date -Format "yyyy-MM-dd_HH:mm:ss")+" processo bloccato " | Out-File -FilePath $logFile -Append - if ($retryCount -lt $maxRetries - 1) { - $retryCount++ - Write-Host "Retry attempt $retryCount after 2 seconds..." - Start-Sleep -Seconds 2 - continue - } + # if ($retryCount -lt $maxRetries - 1) { + # $retryCount++ + # Write-Host "Retry attempt $retryCount after 2 seconds..." + # Start-Sleep -Seconds 2 + # continue + # } exit 1 } $success = $true diff --git a/sql/C6SC08_creauser.sql b/sql/C6SC08_creauser.sql index 6cea7c43..39e7c66f 100644 --- a/sql/C6SC08_creauser.sql +++ b/sql/C6SC08_creauser.sql @@ -1,12 +1,33 @@ +-- Creazione dell'utente F701264 con tutti i permessi +USE [master] +GO + +-- Crea il login se non esiste +IF NOT EXISTS (SELECT * FROM sys.server_principals WHERE name = 'F701264') +BEGIN + CREATE LOGIN [F701264] WITH PASSWORD = 'contrsei' +END +GO + +-- Assegna i ruoli server +ALTER SERVER ROLE [sysadmin] ADD MEMBER [F701264] +GO + +-- Per ogni database nel sistema, assegna i permessi necessari USE [C6StampeCentralizzate] GO --- Creare il login -CREATE LOGIN [F701264] WITH PASSWORD = 'contrsei' DEFAULT_SCHEMA=[dbo] +IF NOT EXISTS (SELECT * FROM sys.database_principals WHERE name = 'F701264') +BEGIN + CREATE USER [F701264] FOR LOGIN [F701264] +END + +-- Assegna il ruolo db_owner +ALTER ROLE [db_owner] ADD MEMBER [F701264] GO --- Creare l'utente associato al login -CREATE USER [F701264] FOR LOGIN [F701264] WITH DEFAULT_SCHEMA=[dbo] --- Assegnare ruolo db_owner per controllo completo sul database -ALTER ROLE [db_owner] ADD MEMBER [F701264] -GO \ No newline at end of file +-- Concedi permessi specifici +GRANT CONTROL TO [F701264] +GRANT VIEW DEFINITION TO [F701264] +GRANT SHOWPLAN TO [F701264] +GO