From 33a3581823c75ef0c85db1f43280a0ac91949ecd Mon Sep 17 00:00:00 2001 From: Marius Date: Wed, 28 Jan 2026 17:13:06 +0200 Subject: [PATCH] Add ROA uninstall/cleanup script for testing iterations - sql/uninstall-roa.sql: Removes all ROA objects in correct order - Drops company users (dynamically detected by ROA tablespace) - Drops CONTAFIN_ORACLE user CASCADE - Drops public synonyms pointing to CONTAFIN_ORACLE - Drops SYS custom objects (AUTH_PACK, AUTH_SERII, INFO, etc.) - Drops application context SESIUNE - Drops tablespace ROA including datafiles - scripts/99-uninstall-roa.ps1: PowerShell wrapper with confirmation - Updated README with uninstall documentation Co-Authored-By: Claude Opus 4.5 --- .../lxc108-oracle/roa-windows-setup/README.md | 44 ++- .../scripts/99-uninstall-roa.ps1 | 136 ++++++++ .../roa-windows-setup/sql/uninstall-roa.sql | 291 ++++++++++++++++++ 3 files changed, 469 insertions(+), 2 deletions(-) create mode 100644 proxmox/lxc108-oracle/roa-windows-setup/scripts/99-uninstall-roa.ps1 create mode 100644 proxmox/lxc108-oracle/roa-windows-setup/sql/uninstall-roa.sql diff --git a/proxmox/lxc108-oracle/roa-windows-setup/README.md b/proxmox/lxc108-oracle/roa-windows-setup/README.md index 95fa7c7..b5e7a6d 100644 --- a/proxmox/lxc108-oracle/roa-windows-setup/README.md +++ b/proxmox/lxc108-oracle/roa-windows-setup/README.md @@ -73,7 +73,8 @@ roa-windows-setup/ │ ├── 04-create-synonyms-grants.ps1 # Public synonyms and grants │ ├── 05-import-companies.ps1 # Batch import company schemas │ ├── 06-add-company.ps1 # Add new company to existing server -│ └── 07-verify-installation.ps1# Verify installation completeness +│ ├── 07-verify-installation.ps1# Verify installation completeness +│ └── 99-uninstall-roa.ps1 # Uninstall/cleanup script │ ├── config/ # Configuration templates │ └── sqlnet.ora # Compatibility for Instant Client 10/11 @@ -83,7 +84,15 @@ roa-windows-setup/ │ └── import-company.par # Company schema import template │ ├── sql/ # SQL scripts -│ └── (to be added) +│ ├── create-tablespace.sql # ROA tablespace creation +│ ├── create-user-contafin.sql # CONTAFIN_ORACLE user creation +│ ├── create-user-company.sql # Company user template +│ ├── configure-profile.sql # Profile settings +│ ├── sys-objects.sql # SYS custom objects (AUTH_PACK, etc.) +│ ├── synonyms-public.sql # Public synonyms for CONTAFIN_ORACLE +│ ├── grants-public.sql # Public grants +│ ├── verify-objects.sql # Verification queries +│ └── uninstall-roa.sql # Cleanup script (removes all ROA objects) │ └── test/ # Testing scripts └── clone-vm300.sh # Proxmox VM cloning for testing @@ -102,6 +111,7 @@ roa-windows-setup/ | `05-import-companies.ps1` | Batch import company schemas from DMP files | Yes | | `06-add-company.ps1` | Add new company to existing server | Optional | | `07-verify-installation.ps1` | Verify installation completeness (objects, grants, synonyms) | Yes | +| `99-uninstall-roa.ps1` | Remove all ROA objects (cleanup for re-testing) | Optional | --- @@ -238,6 +248,36 @@ exp system/password@ORCL file=C:\backup\COMPANY.dmp owner=COMPANY --- +## Uninstall / Cleanup + +To remove all ROA objects and start fresh (useful for testing): + +```powershell +# Interactive (with confirmation) +.\scripts\99-uninstall-roa.ps1 -SystemPassword "romfastsoft" + +# Force (no confirmation) +.\scripts\99-uninstall-roa.ps1 -SystemPassword "romfastsoft" -Force +``` + +Or run the SQL script directly: + +```sql +sqlplus sys/romfastsoft@localhost:1521/XEPDB1 as sysdba @sql/uninstall-roa.sql +``` + +**This removes:** +- All company user schemas (using ROA tablespace) +- CONTAFIN_ORACLE user and all objects +- Public synonyms pointing to CONTAFIN_ORACLE +- SYS custom objects (AUTH_PACK, AUTH_SERII, INFO, etc.) +- Application context SESIUNE +- Tablespace ROA (including datafile) + +> **Warning:** This permanently deletes all ROA data! Use only for testing or before reinstallation. + +--- + ## Troubleshooting ### ORA-28040: No matching authentication protocol diff --git a/proxmox/lxc108-oracle/roa-windows-setup/scripts/99-uninstall-roa.ps1 b/proxmox/lxc108-oracle/roa-windows-setup/scripts/99-uninstall-roa.ps1 new file mode 100644 index 0000000..c7864c4 --- /dev/null +++ b/proxmox/lxc108-oracle/roa-windows-setup/scripts/99-uninstall-roa.ps1 @@ -0,0 +1,136 @@ +# ============================================================================ +# ROA UNINSTALL SCRIPT +# ============================================================================ +# Removes all ROA application objects from Oracle database +# +# Usage: +# .\99-uninstall-roa.ps1 -SystemPassword "yourpassword" +# .\99-uninstall-roa.ps1 -SystemPassword "yourpassword" -Force +# +# Parameters: +# -SystemPassword : SYS password for database connection +# -Force : Skip confirmation prompt +# +# ============================================================================ + +param( + [Parameter(Mandatory=$false)] + [string]$SystemPassword, + + [Parameter(Mandatory=$false)] + [switch]$Force +) + +$ErrorActionPreference = "Stop" + +# ============================================================================ +# LOAD CONFIGURATION AND LIBRARIES +# ============================================================================ + +$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path +$RootDir = Split-Path -Parent $ScriptDir + +# Load config +$ConfigFile = Join-Path $RootDir "config.ps1" +if (Test-Path $ConfigFile) { + . $ConfigFile +} else { + Write-Host "ERROR: config.ps1 not found. Copy config.example.ps1 to config.ps1" -ForegroundColor Red + exit 1 +} + +# Load libraries +. (Join-Path $ScriptDir "lib\logging-functions.ps1") +. (Join-Path $ScriptDir "lib\oracle-functions.ps1") + +# ============================================================================ +# MAIN +# ============================================================================ + +Write-Host "" +Write-Host "============================================================" -ForegroundColor Cyan +Write-Host " ROA UNINSTALL - REMOVING ALL ROA OBJECTS" -ForegroundColor Cyan +Write-Host "============================================================" -ForegroundColor Cyan +Write-Host "" + +# Get password if not provided +if (-not $SystemPassword) { + $SecurePassword = Read-Host "Enter SYS password" -AsSecureString + $SystemPassword = [Runtime.InteropServices.Marshal]::PtrToStringAuto( + [Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecurePassword) + ) +} + +# Build connection string +$OracleService = if ($Config.OracleService) { $Config.OracleService } else { "XEPDB1" } +$OracleHost = if ($Config.OracleHost) { $Config.OracleHost } else { "localhost" } +$OraclePort = if ($Config.OraclePort) { $Config.OraclePort } else { 1521 } +$ConnString = "${OracleHost}:${OraclePort}/${OracleService}" + +Write-Host "Target database: $ConnString" -ForegroundColor Yellow +Write-Host "" + +# Confirmation +if (-not $Force) { + Write-Host "WARNING: This will PERMANENTLY DELETE all ROA data!" -ForegroundColor Red + Write-Host "" + Write-Host "Objects to be removed:" -ForegroundColor Yellow + Write-Host " - All company user schemas (using ROA tablespace)" + Write-Host " - CONTAFIN_ORACLE user and all objects" + Write-Host " - Public synonyms pointing to CONTAFIN_ORACLE" + Write-Host " - SYS custom objects (AUTH_PACK, AUTH_SERII, etc.)" + Write-Host " - Application context SESIUNE" + Write-Host " - Tablespace ROA (including datafile)" + Write-Host "" + + $confirm = Read-Host "Type 'YES' to confirm uninstall" + if ($confirm -ne "YES") { + Write-Host "Uninstall cancelled." -ForegroundColor Yellow + exit 0 + } +} + +Write-Host "" +Write-Host "Starting uninstall..." -ForegroundColor Cyan +Write-Host "" + +# Find sqlplus +$SqlPlus = Get-SqlPlusPath +if (-not $SqlPlus) { + Write-Host "ERROR: sqlplus.exe not found" -ForegroundColor Red + exit 1 +} + +# Run uninstall script +$SqlScript = Join-Path $RootDir "sql\uninstall-roa.sql" + +if (-not (Test-Path $SqlScript)) { + Write-Host "ERROR: uninstall-roa.sql not found at $SqlScript" -ForegroundColor Red + exit 1 +} + +Write-Host "Running uninstall script..." -ForegroundColor Cyan + +$SqlInput = @" +@"$SqlScript" +EXIT +"@ + +$process = Start-Process -FilePath $SqlPlus ` + -ArgumentList "sys/${SystemPassword}@${ConnString} as sysdba" ` + -NoNewWindow -Wait -PassThru ` + -RedirectStandardInput (New-TemporaryFile | ForEach-Object { + $SqlInput | Set-Content $_.FullName + $_.FullName + }) + +# Alternative: run directly +& $SqlPlus "sys/${SystemPassword}@${ConnString} as sysdba" "@$SqlScript" + +Write-Host "" +Write-Host "============================================================" -ForegroundColor Green +Write-Host " ROA UNINSTALL COMPLETE" -ForegroundColor Green +Write-Host "============================================================" -ForegroundColor Green +Write-Host "" +Write-Host "Database is now clean. You can re-run the setup scripts." -ForegroundColor Cyan +Write-Host "" diff --git a/proxmox/lxc108-oracle/roa-windows-setup/sql/uninstall-roa.sql b/proxmox/lxc108-oracle/roa-windows-setup/sql/uninstall-roa.sql new file mode 100644 index 0000000..a9eae96 --- /dev/null +++ b/proxmox/lxc108-oracle/roa-windows-setup/sql/uninstall-roa.sql @@ -0,0 +1,291 @@ +-- ============================================================================ +-- ROA UNINSTALL SCRIPT +-- ============================================================================ +-- Removes all ROA application objects from Oracle database: +-- - Company users (schemas starting with company patterns) +-- - CONTAFIN_ORACLE user and all objects +-- - Public synonyms pointing to CONTAFIN_ORACLE +-- - SYS custom objects (AUTH_PACK, AUTH_SERII, etc.) +-- - Application context SESIUNE +-- - Tablespace ROA +-- +-- Usage: +-- sqlplus sys/password@service as sysdba @uninstall-roa.sql +-- +-- WARNING: This script PERMANENTLY DELETES all ROA data! +-- ============================================================================ + +SET ECHO OFF +SET FEEDBACK ON +SET SERVEROUTPUT ON SIZE UNLIMITED +WHENEVER SQLERROR CONTINUE + +PROMPT +PROMPT ============================================================ +PROMPT ROA UNINSTALL - REMOVING ALL ROA OBJECTS +PROMPT ============================================================ +PROMPT +PROMPT WARNING: This will permanently delete all ROA data! +PROMPT Press Ctrl+C within 5 seconds to abort... +PROMPT +EXEC DBMS_SESSION.SLEEP(5); + +-- ============================================================================ +-- SECTION 1: DROP COMPANY USERS +-- ============================================================================ +PROMPT +PROMPT [1/6] Dropping company users... +PROMPT ============================================================ + +DECLARE + CURSOR c_users IS + SELECT username + FROM dba_users + WHERE username NOT IN ( + 'SYS', 'SYSTEM', 'OUTLN', 'DIP', 'ORACLE_OCM', 'DBSNMP', 'APPQOSSYS', + 'WMSYS', 'EXFSYS', 'CTXSYS', 'ANONYMOUS', 'XDB', 'ORDPLUGINS', + 'ORDSYS', 'SI_INFORMTN_SCHEMA', 'MDSYS', 'OLAPSYS', 'MDDATA', + 'SPATIAL_WFS_ADMIN_USR', 'SPATIAL_CSW_ADMIN_USR', 'SYSMAN', + 'MGMT_VIEW', 'APEX_PUBLIC_USER', 'APEX_040000', 'APEX_040200', + 'FLOWS_FILES', 'OWBSYS', 'OWBSYS_AUDIT', 'SCOTT', 'HR', 'OE', + 'SH', 'PM', 'IX', 'BI', 'XS$NULL', 'GSMADMIN_INTERNAL', + 'GSMUSER', 'GSMCATUSER', 'SYSBACKUP', 'SYSDG', 'SYSKM', + 'SYSRAC', 'SYS$UMF', 'DBSFWUSER', 'REMOTE_SCHEDULER_AGENT', + 'PDBADMIN', 'GGSHAREDCAP', 'LBACSYS', 'DVF', 'DVSYS', + 'AUDSYS', 'DGPDB_INT', 'GGSYS', 'CONTAFIN_ORACLE' + ) + AND username NOT LIKE 'APEX%' + AND username NOT LIKE 'FLOWS%' + AND username NOT LIKE 'OWB%' + AND default_tablespace = 'ROA' + ORDER BY username; + v_count NUMBER := 0; +BEGIN + FOR r IN c_users LOOP + BEGIN + EXECUTE IMMEDIATE 'DROP USER ' || r.username || ' CASCADE'; + DBMS_OUTPUT.PUT_LINE(' Dropped user: ' || r.username); + v_count := v_count + 1; + EXCEPTION + WHEN OTHERS THEN + DBMS_OUTPUT.PUT_LINE(' ERROR dropping ' || r.username || ': ' || SQLERRM); + END; + END LOOP; + DBMS_OUTPUT.PUT_LINE('Total company users dropped: ' || v_count); +END; +/ + +-- ============================================================================ +-- SECTION 2: DROP CONTAFIN_ORACLE USER +-- ============================================================================ +PROMPT +PROMPT [2/6] Dropping CONTAFIN_ORACLE user... +PROMPT ============================================================ + +DECLARE + v_count NUMBER; +BEGIN + SELECT COUNT(*) INTO v_count FROM dba_users WHERE username = 'CONTAFIN_ORACLE'; + IF v_count > 0 THEN + -- First drop the private synonym + BEGIN + EXECUTE IMMEDIATE 'DROP SYNONYM CONTAFIN_ORACLE.VDEF_PROGRAME_SERII'; + EXCEPTION WHEN OTHERS THEN NULL; + END; + + -- Now drop the user + EXECUTE IMMEDIATE 'DROP USER CONTAFIN_ORACLE CASCADE'; + DBMS_OUTPUT.PUT_LINE(' User CONTAFIN_ORACLE dropped successfully.'); + ELSE + DBMS_OUTPUT.PUT_LINE(' User CONTAFIN_ORACLE does not exist.'); + END IF; +END; +/ + +-- ============================================================================ +-- SECTION 3: DROP PUBLIC SYNONYMS +-- ============================================================================ +PROMPT +PROMPT [3/6] Dropping public synonyms... +PROMPT ============================================================ + +DECLARE + CURSOR c_synonyms IS + SELECT synonym_name + FROM dba_synonyms + WHERE owner = 'PUBLIC' + AND (table_owner = 'CONTAFIN_ORACLE' + OR synonym_name IN ( + 'STRINGAGG', 'CHAR_ROW', 'CHAR_TAB', 'NUM_ROW', 'NUM_TAB', + 'UW_SEL_ROW', 'UW_SEL_TAB', 'GETWORDCOUNT', 'GETWORDNUM', + 'CHARC2COLLECTION', 'CHARN2COLLECTION', 'VALOARETAG', + 'SAL_CONTRACT_M', 'CONTRACT_M', 'SAL_RED', 'SAL_CAMPURI_RED', + 'TABSTERS', 'SAL_TABELESTERS', 'PACK_UPDATE', 'PACK_UTILS', + 'PACK_UTILS_FILE', 'PACK_ROARTVAI', 'RTVAI_AGENTI', 'RTVAI_ISTORIC', + 'FF_SUME', 'FF_PERSINTRET', 'VANZARI_DETALII_TAB', 'PIVOT_TABLE', + 'PIVOT_ROW', 'TABINCHIDERETVA', 'TABELAVALORITAGURI', + 'RANDINCHIDERETVA', 'SERVER_INFO' + ) + OR synonym_name LIKE 'SYN_%'); + v_count NUMBER := 0; +BEGIN + FOR r IN c_synonyms LOOP + BEGIN + EXECUTE IMMEDIATE 'DROP PUBLIC SYNONYM ' || r.synonym_name; + v_count := v_count + 1; + EXCEPTION + WHEN OTHERS THEN NULL; -- Ignore if doesn't exist + END; + END LOOP; + DBMS_OUTPUT.PUT_LINE(' Dropped ' || v_count || ' public synonyms.'); +END; +/ + +-- ============================================================================ +-- SECTION 4: DROP APPLICATION CONTEXT +-- ============================================================================ +PROMPT +PROMPT [4/6] Dropping application context... +PROMPT ============================================================ + +BEGIN + EXECUTE IMMEDIATE 'DROP CONTEXT SESIUNE'; + DBMS_OUTPUT.PUT_LINE(' Context SESIUNE dropped.'); +EXCEPTION + WHEN OTHERS THEN + DBMS_OUTPUT.PUT_LINE(' Context SESIUNE not found or already dropped.'); +END; +/ + +-- ============================================================================ +-- SECTION 5: DROP SYS CUSTOM OBJECTS +-- ============================================================================ +PROMPT +PROMPT [5/6] Dropping SYS custom objects... +PROMPT ============================================================ + +-- Drop view first (depends on package) +BEGIN EXECUTE IMMEDIATE 'DROP VIEW SYS.VAUTH_SERII'; + DBMS_OUTPUT.PUT_LINE(' Dropped SYS.VAUTH_SERII'); +EXCEPTION WHEN OTHERS THEN NULL; END; +/ + +-- Drop procedures +BEGIN EXECUTE IMMEDIATE 'DROP PROCEDURE SYS.UPDATESQLPLUS'; + DBMS_OUTPUT.PUT_LINE(' Dropped SYS.UPDATESQLPLUS'); +EXCEPTION WHEN OTHERS THEN NULL; END; +/ +BEGIN EXECUTE IMMEDIATE 'DROP PROCEDURE SYS.NEWSCHEMAJOB'; + DBMS_OUTPUT.PUT_LINE(' Dropped SYS.NEWSCHEMAJOB'); +EXCEPTION WHEN OTHERS THEN NULL; END; +/ +BEGIN EXECUTE IMMEDIATE 'DROP PROCEDURE SYS.NEWSCHEMA'; + DBMS_OUTPUT.PUT_LINE(' Dropped SYS.NEWSCHEMA'); +EXCEPTION WHEN OTHERS THEN NULL; END; +/ +BEGIN EXECUTE IMMEDIATE 'DROP PROCEDURE SYS.EXECUTESCRIPTOS'; + DBMS_OUTPUT.PUT_LINE(' Dropped SYS.EXECUTESCRIPTOS'); +EXCEPTION WHEN OTHERS THEN NULL; END; +/ +BEGIN EXECUTE IMMEDIATE 'DROP PROCEDURE SYS.PINFO'; + DBMS_OUTPUT.PUT_LINE(' Dropped SYS.PINFO'); +EXCEPTION WHEN OTHERS THEN NULL; END; +/ + +-- Drop package +BEGIN EXECUTE IMMEDIATE 'DROP PACKAGE SYS.AUTH_PACK'; + DBMS_OUTPUT.PUT_LINE(' Dropped SYS.AUTH_PACK'); +EXCEPTION WHEN OTHERS THEN NULL; END; +/ + +-- Drop sequence +BEGIN EXECUTE IMMEDIATE 'DROP SEQUENCE SYS.SEQ_AUTH_SERII'; + DBMS_OUTPUT.PUT_LINE(' Dropped SYS.SEQ_AUTH_SERII'); +EXCEPTION WHEN OTHERS THEN NULL; END; +/ + +-- Drop tables +BEGIN EXECUTE IMMEDIATE 'DROP TABLE SYS.AUTH_SERII PURGE'; + DBMS_OUTPUT.PUT_LINE(' Dropped SYS.AUTH_SERII'); +EXCEPTION WHEN OTHERS THEN NULL; END; +/ +BEGIN EXECUTE IMMEDIATE 'DROP TABLE SYS.AUTH_DETALII PURGE'; + DBMS_OUTPUT.PUT_LINE(' Dropped SYS.AUTH_DETALII'); +EXCEPTION WHEN OTHERS THEN NULL; END; +/ +BEGIN EXECUTE IMMEDIATE 'DROP TABLE SYS.INFO PURGE'; + DBMS_OUTPUT.PUT_LINE(' Dropped SYS.INFO'); +EXCEPTION WHEN OTHERS THEN NULL; END; +/ + +-- ============================================================================ +-- SECTION 6: DROP TABLESPACE ROA +-- ============================================================================ +PROMPT +PROMPT [6/6] Dropping tablespace ROA... +PROMPT ============================================================ + +DECLARE + v_count NUMBER; +BEGIN + SELECT COUNT(*) INTO v_count FROM dba_tablespaces WHERE tablespace_name = 'ROA'; + IF v_count > 0 THEN + -- Check for any remaining objects + SELECT COUNT(*) INTO v_count + FROM dba_segments + WHERE tablespace_name = 'ROA'; + + IF v_count > 0 THEN + DBMS_OUTPUT.PUT_LINE(' WARNING: Tablespace ROA still has ' || v_count || ' segments.'); + DBMS_OUTPUT.PUT_LINE(' Dropping tablespace with INCLUDING CONTENTS...'); + END IF; + + EXECUTE IMMEDIATE 'DROP TABLESPACE ROA INCLUDING CONTENTS AND DATAFILES'; + DBMS_OUTPUT.PUT_LINE(' Tablespace ROA dropped successfully.'); + ELSE + DBMS_OUTPUT.PUT_LINE(' Tablespace ROA does not exist.'); + END IF; +END; +/ + +-- ============================================================================ +-- VERIFICATION +-- ============================================================================ +PROMPT +PROMPT ============================================================ +PROMPT VERIFICATION - Remaining ROA Objects (should be empty) +PROMPT ============================================================ +PROMPT + +PROMPT Users with default tablespace ROA: +SELECT username, default_tablespace FROM dba_users WHERE default_tablespace = 'ROA'; + +PROMPT +PROMPT SYS custom objects: +SELECT object_name, object_type, status +FROM dba_objects +WHERE owner = 'SYS' + AND object_name IN ( + 'AUTH_PACK', 'AUTH_DETALII', 'AUTH_SERII', 'VAUTH_SERII', + 'EXECUTESCRIPTOS', 'NEWSCHEMA', 'NEWSCHEMAJOB', 'UPDATESQLPLUS', + 'PINFO', 'INFO', 'SEQ_AUTH_SERII' + ); + +PROMPT +PROMPT Public synonyms pointing to CONTAFIN_ORACLE: +SELECT COUNT(*) AS remaining_synonyms +FROM dba_synonyms +WHERE owner = 'PUBLIC' + AND table_owner = 'CONTAFIN_ORACLE'; + +PROMPT +PROMPT Tablespace ROA: +SELECT tablespace_name, status FROM dba_tablespaces WHERE tablespace_name = 'ROA'; + +PROMPT +PROMPT ============================================================ +PROMPT ROA UNINSTALL COMPLETE +PROMPT ============================================================ +PROMPT +PROMPT Database is now clean. You can re-run the setup scripts. +PROMPT