Skip to content

Commit 3676960

Browse files
EnovotnyEric Novotny
andauthored
Feature/add database schema 25 07 01 (#1215)
- adding data schema update 25-07-01 to develop database build action. - removed sections of update script that I felt were not relevant. --------- Co-authored-by: Eric Novotny <nov00002@umn.edu>
1 parent 2c19ffc commit 3676960

2 files changed

Lines changed: 297 additions & 0 deletions

File tree

.github/actions/database-migration-image/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ COPY entry.sh /
66
COPY create-queues.sql /after.install.d/
77
COPY cda-user.sql /after.install.d/
88
COPY aaaa-updates.sql /after.install.d/
9+
COPY update_24_12_4_to_25_7_1.sql /after.install.d/
910

1011
ENV RDS_MODE="true"
1112
ENV BUILDUSER=DBAdmin
Lines changed: 296 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,296 @@
1+
-------------------
2+
-- general setup --
3+
-------------------
4+
--whenever sqlerror exit;
5+
set define on
6+
--set verify off
7+
--set pages 100
8+
--set serveroutput on
9+
define cwms_schema = 'CWMS_20'
10+
--define cwms_dba_schema = 'CWMS_DBA'
11+
define cwms_dba_schema = 'DBAdmin'
12+
alter session set current_schema = &cwms_schema;
13+
set echo on;
14+
------------------------------------------------------------
15+
-- spool to file that identifies the database in the name --
16+
------------------------------------------------------------
17+
--var db_name varchar2(61)
18+
--begin
19+
-- select nvl(primary_db_unique_name, db_unique_name) into :db_name from v$database;
20+
--end;
21+
--/
22+
--whenever sqlerror continue;
23+
--declare
24+
-- l_count pls_integer;
25+
-- l_name varchar2(30);
26+
--begin
27+
-- select count(*) into l_count from all_objects where object_name = 'CDB_PDBS';
28+
-- if l_count > 0 then
29+
-- select name
30+
-- into l_name
31+
-- from v$database;
32+
-- :db_name := l_name;
33+
-- begin
34+
-- select pdb_name
35+
-- into l_name
36+
-- from cdb_pdbs;
37+
-- exception
38+
-- when no_data_found then
39+
-- l_name := null;
40+
-- end;
41+
-- if l_name is not null then
42+
-- :db_name := :db_name||'-'||l_name;
43+
-- end if;
44+
-- end if;
45+
--end;
46+
--/
47+
--whenever sqlerror exit;
48+
--column db_name new_value db_name
49+
--select :db_name as db_name from dual;
50+
--define logfile=update_&db_name._24_5_24_to_24_12_4.log
51+
--PROMPT log file = &logfile
52+
--spool &logfile append;
53+
-------------------
54+
-- do the update --
55+
-------------------
56+
--PROMPT ################################################################################
57+
--PROMPT VERIFYING EXPECTED VERSION
58+
--select systimestamp from dual;
59+
--@@./25_07_01/verify_db_version
60+
61+
--PROMPT ################################################################################
62+
--PROMPT SAVING PRE-UPDATE PRIVILEGES
63+
--select systimestamp from dual;
64+
--@@./util/preupdate_privs.sql;
65+
66+
PROMPT ################################################################################
67+
PROMPT ALTERING TABLES
68+
alter table at_api_keys modify userid varchar2(128);
69+
alter table at_log_message modify session_username varchar2(128);
70+
alter table at_log_message modify session_osuser varchar2(128);
71+
alter table at_prj_lck_revoker_rights modify user_id varchar2(128);
72+
alter table at_project_lock modify session_user varchar2(128);
73+
alter table at_project_lock modify os_user varchar2(128);
74+
alter table at_sec_cwms_users modify userid varchar2(128);
75+
alter table at_sec_cwms_users modify createdby varchar2(128);
76+
-- at_sec_cwms_users.principle_name takes more work since it's used in a virtual column
77+
alter table at_sec_cwms_users drop column edipi;
78+
alter table at_sec_cwms_users modify principle_name varchar2(512);
79+
alter table at_sec_cwms_users add (edipi number(*,0) generated always as (case when length(principle_name)>10 then case when regexp_like (substr(principle_name,1,10),'^[[:digit:]]+$') then to_number(substr(principle_name,1,10)) else null end else null end) virtual);alter table at_sec_locked_users modify username varchar2(128);
80+
alter table at_sec_locked_users modify username varchar2(128);
81+
alter table at_sec_service_user modify userid varchar2(128);
82+
alter table at_sec_session modify userid varchar2(128);
83+
alter table at_sec_users modify username varchar2(128);
84+
alter table at_sec_user_office modify username varchar2(128);
85+
alter table at_user_preferences modify username varchar2(128);
86+
alter table temp_collection_api_fire_tbl modify user_id_fired varchar2(128);
87+
alter table UPLOADED_XLS_FILES_T modify USER_ID_UPLOADED varchar2(128);
88+
alter table UPLOADED_XLS_FILE_ROWS_T modify USER_ID_UPLOADED varchar2(128);
89+
alter table UPLOADED_XLS_FILE_ROWS_T modify USER_ID_LAST_UPDATED varchar2(128);
90+
91+
PROMPT ################################################################################
92+
PROMPT ALTERING VIEWS
93+
@/cwmsdb/schema/src/cwms/views/av_cwms_ts_id.sql
94+
@/cwmsdb/schema/src/cwms/views/av_location_level.sql
95+
96+
PROMPT ################################################################################
97+
PROMPT adding Data acquisition groups
98+
@/schema/src/updateScripts/25_07_01/data_acquisition
99+
100+
PROMPT ################################################################################
101+
PROMPT CREATING AND ALTERING TYPE SPECIFICATIONS
102+
select systimestamp from dual;
103+
104+
drop type ztsv_type force;
105+
@/cwmsdb/schema/src/cwms/types/ztsv_type
106+
@/cwmsdb/schema/src/cwms/types/ztsv_entry_type
107+
@/cwmsdb/schema/src/cwms/types/ztsv_entry_array
108+
create or replace public synonym cwms_t_ztsv_entry for ztsv_entry_type;
109+
110+
PROMPT ################################################################################
111+
PROMPT CREATING AND ALTERING TYPE BODIES
112+
select systimestamp from dual;
113+
114+
@/cwmsdb/schema/src/cwms/types/loc_lvl_indicator_cond_t-body
115+
@/cwmsdb/schema/src/cwms/types/rating_t-body
116+
@/cwmsdb/schema/src/cwms/types/streamflow_meas_t-body
117+
@/cwmsdb/schema/src/cwms/types/streamflow_meas2_t-body
118+
119+
PROMPT ################################################################################
120+
PROMPT UPDATING PACKAGE SPECIFICATIONS
121+
122+
@/cwmsdb/schema/src/cwms/cwms_cache_pkg
123+
@/cwmsdb/schema/src/cwms/cwms_sec_pkg
124+
@/cwmsdb/schema/src/cwms/cwms_ts_pkg
125+
@/cwmsdb/schema/src/cwms/cwms_util_pkg
126+
127+
PROMPT ################################################################################
128+
PROMPT UPDATING PACKAGE BODIES
129+
select systimestamp from dual;
130+
131+
define builduser = BUILDUSER
132+
133+
@/cwmsdb/schema/src/cwms/cwms_cache_pkg_body
134+
@/cwmsdb/schema/src/cwms/cwms_display_pkg_body
135+
@/cwmsdb/schema/src/cwms/cwms_env_pkg_body
136+
@/cwmsdb/schema/src/cwms/cwms_lock_pkg_body
137+
@/cwmsdb/schema/src/cwms/cwms_msg_pkg_body
138+
@/cwmsdb/schema/src/cwms/cwms_priv_pkg_body
139+
@/cwmsdb/schema/src/cwms/cwms_project_pkg_body
140+
@/cwmsdb/schema/src/cwms/cwms_sec_pkg_body
141+
@/cwmsdb/schema/src/cwms/cwms_rating_pkg_body
142+
@/cwmsdb/schema/src/cwms/cwms_shef_pkg_body
143+
@/cwmsdb/schema/src/cwms/cwms_ts_pkg_body
144+
@/cwmsdb/schema/src/cwms/cwms_util_pkg_body
145+
146+
PROMPT ################################################################################
147+
PROMPT UPDATING TRIGGERS
148+
select systimestamp from dual;
149+
150+
create or replace function get_source(p_type varchar2, p_name varchar2) return clob
151+
is
152+
l_clob clob;
153+
begin
154+
dbms_lob.createtemporary(l_clob, true);
155+
dbms_lob.open(l_clob, dbms_lob.lob_readwrite);
156+
l_clob := '';
157+
for rec in (select text from user_source where type=upper(p_type) and name=upper(p_name) order by line) loop
158+
l_clob := l_clob || rec.text;
159+
end loop;
160+
return l_clob;
161+
end;
162+
/
163+
164+
declare
165+
l_sql clob;
166+
begin
167+
for rec in (select object_name
168+
from all_objects
169+
where owner = 'CWMS_20'
170+
and object_type = 'TRIGGER'
171+
and object_name like 'ST\_%' escape '\' order by 1)
172+
loop
173+
begin
174+
l_sql := 'CREATE OR REPLACE '
175+
||replace(get_source('TRIGGER', rec.object_name),
176+
'user NOT IN (''SYS'', ''CWMS_20'')',
177+
'user NOT IN (''SYS'', ''CWMS_20'', upper(''builduser''))');
178+
l_sql := replace(l_sql,
179+
'USER NOT IN (''SYS'', ''CWMS_20'')',
180+
'USER NOT IN (''SYS'', ''CWMS_20'', upper(''builduser''))');
181+
execute immediate l_sql;
182+
end;
183+
end loop;
184+
end;
185+
/
186+
drop function get_source;
187+
188+
PROMPT ################################################################################
189+
PROMPT GRANT SELECT ON TABLES TO USERS
190+
select systimestamp from dual;
191+
192+
begin
193+
for rec in (select object_name
194+
from all_objects
195+
where owner = 'CWMS_20'
196+
and object_type = 'TABLE'
197+
and (object_name like 'AT\_%' escape '\' or object_name like 'CWMS\_%' escape '\')
198+
and object_name not like 'AT_SEC_%'
199+
and object_name != 'AT_API_KEYS'
200+
)
201+
loop
202+
dbms_output.put_line(rec.object_name);
203+
execute immediate 'grant select on '||rec.object_name||' to cwms_user';
204+
end loop;
205+
end;
206+
/
207+
208+
--PROMPT ################################################################################
209+
--PROMPT FINAL HOUSEKEEPING
210+
--select systimestamp from dual;
211+
212+
--declare
213+
-- cmd varchar2(128);
214+
--begin
215+
-- execute immediate 'grant CWMS_USER to CWMS_DBA';
216+
-- for rec in (select object_name,
217+
-- object_type
218+
-- from dba_objects
219+
-- where owner = '&cwms_schema'
220+
-- and object_type in ('PACKAGE BODY', 'TYPE', 'VIEW')
221+
-- and object_name not like '%AQ$%'
222+
-- )
223+
-- loop
224+
-- cmd := 'grant '
225+
-- ||case when rec.object_type = 'VIEW' then 'select' else 'execute' end
226+
-- ||' on &cwms_schema..'
227+
-- ||rec.object_name
228+
-- ||' to CWMS_USER';
229+
-- dbms_output.put(cmd||' [');
230+
-- begin
231+
-- execute immediate cmd;
232+
-- dbms_output.put_line('SUCCEEDED]');
233+
-- exception
234+
-- when others then dbms_output.put_line('FAILED]');
235+
-- end;
236+
-- end loop;
237+
--end;
238+
--/
239+
--PROMPT ################################################################################
240+
--PROMPT RESTORING PRE-UPDATE PRIVILEGES
241+
--@@./util/restore_privs
242+
243+
PROMPT ################################################################################
244+
PROMPT RECOMPILING SCHEMA
245+
select systimestamp from dual;
246+
@/cwmsdb/schema/src/updateScripts/util/compile_objects
247+
248+
--promp ################################################################################
249+
--PROMPT REMAINING INVALID OBJECTS...
250+
--select systimestamp from dual;
251+
--select owner||'.'||substr(object_name, 1, 30) as invalid_object,
252+
-- object_type
253+
-- from all_objects
254+
-- where status = 'INVALID'
255+
-- and owner in ('&cwms_schema', '&cwms_dba_schema')
256+
-- order by 1, 2;
257+
--select owner||'.'||substr(name, 1, 30) as name,
258+
-- type,
259+
-- substr(line||':'||position, 1, 12) as location,
260+
-- substr(text, 1, 132) as error
261+
-- from all_errors
262+
-- where attribute = 'ERROR'
263+
-- and owner in ('&cwms_schema', '&cwms_dba_schema')
264+
-- order by owner, type, name, sequence;
265+
--/
266+
267+
--whenever sqlerror exit;
268+
269+
PROMPT ################################################################################
270+
PROMPT UPDATING DB_CHANGE_LOG
271+
select systimestamp from dual;
272+
@/cwmsdb/schema/src/updateScripts/25_07_01/update_db_change_log
273+
--select substr(version, 1, 10) as version,
274+
-- to_char(version_date, 'yyyy-mm-dd hh24:mi') as version_date,
275+
-- to_char(apply_date, 'yyyy-mm-dd hh24:mi') as apply_date
276+
-- from av_db_change_log
277+
-- where application = 'CWMS'
278+
-- order by version_date;
279+
--declare
280+
-- l_count pls_integer;
281+
--begin
282+
-- select count(*)
283+
-- into l_count
284+
-- from all_objects
285+
-- where status = 'INVALID'
286+
-- and owner in ('&cwms_schema', '&cwms_dba_schema');
287+
288+
-- if l_count > 0 then
289+
-- raise_application_error(-20999, chr(10)||'==>'||chr(10)||'==> SOME OBJECTS ARE STILL INVALID'||chr(10)||'==>');
290+
-- end if;
291+
--end;
292+
--/
293+
--PROMPT ################################################################################
294+
--PROMPT UPDATE COMPLETE
295+
--select systimestamp from dual;
296+
--exit

0 commit comments

Comments
 (0)