-- Oracle CDB/PDB Setup for Weather Connect
-- Run this as SYSTEM or SYSDBA user

-- 1. Check the current environment
COLUMN is_cdb FORMAT A10
COLUMN con_name FORMAT A20
SELECT DECODE(cdb, 'YES', 'CDB', 'Regular') as is_cdb FROM v$database;
SHOW CON_NAME;

-- 2. Show available PDBs (if in CDB)
SELECT name, open_mode FROM v$pdbs;

-- 3. Connect to the SHED PDB (assuming SHED is your PDB name)
-- If SHED is the PDB name, connect to it:
ALTER SESSION SET CONTAINER = SHDPDB1;
SHOW CON_NAME;

-- 4. Now create the regular user in the PDB
CREATE USER weather IDENTIFIED BY weather123
DEFAULT TABLESPACE USERS
TEMPORARY TABLESPACE TEMP
QUOTA UNLIMITED ON USERS;

-- 5. Grant necessary privileges
GRANT CONNECT TO weather;
GRANT RESOURCE TO weather;
GRANT CREATE SESSION TO weather;
GRANT CREATE TABLE TO weather;
GRANT CREATE SEQUENCE TO weather;
GRANT CREATE VIEW TO weather;
-- Note: CREATE INDEX privilege is included in RESOURCE role
-- GRANT CREATE INDEX TO weather;  -- This is redundant with RESOURCE

-- Optional: Grant additional privileges if needed
-- GRANT CREATE PROCEDURE TO weather;
-- GRANT CREATE TRIGGER TO weather;

COMMIT;

-- 6. Verify user creation
SELECT username, default_tablespace, temporary_tablespace, account_status
FROM dba_users 
WHERE username = 'WEATHER';

-- 7. Display granted privileges
SELECT grantee, privilege 
FROM dba_sys_privs 
WHERE grantee = 'WEATHER'
ORDER BY privilege;

-- 8. Test connection as weather user
-- CONNECT weather/weather123@pve-ora19c-1:1521/SHDPDB1;