-
Notifications
You must be signed in to change notification settings - Fork 1
/
github_oracle_content.body.sql
159 lines (129 loc) · 4.48 KB
/
github_oracle_content.body.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
create or replace package body github_oracle_content
as
function get_object_path (
object_name in varchar2
, object_type in varchar2
, object_owner in varchar2 default user
)
return varchar2
as
suffix varchar2(50) := '.sql';
full_path varchar2(1000);
begin
if object_type = 'PACKAGE_SPEC' then
suffix := '.spec.sql';
return lower(object_owner || '/package/' || object_name || suffix);
elsif object_type = 'PACKAGE_BODY' then
suffix := '.body.sql';
return lower(object_owner || '/package/' || object_name || suffix);
else
return lower(object_owner || '/' || object_type || '/' || object_name || suffix);
end if;
end get_object_path;
procedure push_object (
object_name in varchar2
, object_type in varchar2
, object_owner in varchar2 default user
, object_content in clob default null
)
as
github_path varchar2(4000) := get_object_path(object_name, object_type, object_owner);
check_push_response github.call_result;
object_content_r clob;
github_content_val clob;
github_content_sha varchar2(4000);
begin
if object_content is null then
object_content_r := github.encode64_clob(dbms_metadata.get_ddl(upper(object_type), upper(object_name), object_owner));
else
object_content_r := github.encode64_clob(object_content);
end if;
check_push_response := github_repos_content.get_content(
git_account => github_oracle_session.gh_r_o
, repos_name => github_oracle_session.gh_r
, path => github_path
);
if github.github_call_status_code = 200 then
-- object path already exists
-- Update instead of create, but before we update check if it has changed
github_content_sha := check_push_response.result.get('sha').get_string;
github_content_val := check_push_response.result.get('content').get_string;
-- Cleanup content for comparison
github_content_val := replace(replace(github_content_val, chr(10)), chr(13));
if object_content_r != github_content_val then
-- New content do the update
github_repos_content.update_file (
git_account => github_oracle_session.gh_r_o
, repos_name => github_oracle_session.gh_r
, path => github_path
, message => github_oracle_session.gh_p_m
, content => object_content_r
, sha => github_content_sha
);
end if;
else
-- Object does not exist, create it
github_repos_content.create_file (
git_account => github_oracle_session.gh_r_o
, repos_name => github_oracle_session.gh_r
, path => github_path
, message => github_oracle_session.gh_p_m
, content => object_content_r
);
end if;
end push_object;
procedure push_schema_code(
split_packages in boolean default true
)
as
cursor get_plsql_objects is
select
object_name
, object_type
from
user_objects
where
object_type in ('PROCEDURE','FUNCTION','PACKAGE')
;
begin
for obj in get_plsql_objects loop
if obj.object_type = 'PACKAGE' and split_packages then
push_object(obj.object_name, 'PACKAGE_SPEC');
push_object(obj.object_name, 'PACKAGE_BODY');
else
push_object(obj.object_name, obj.object_type);
end if;
end loop;
end push_schema_code;
function compare_object (
object_name in varchar2
, object_type in varchar2
, object_owner in varchar2 default user
)
return varchar2
as
github_path varchar2(4000) := get_object_path(object_name, object_type, object_owner);
check_push_response github.call_result;
object_content clob;
github_content_val clob;
begin
object_content := github.encode64_clob(dbms_metadata.get_ddl(upper(object_type), upper(object_name), object_owner));
check_push_response := github_repos_content.get_content(
git_account => github_oracle_session.gh_r_o
, repos_name => github_oracle_session.gh_r
, path => github_path
);
if github.github_call_status_code = 200 then
github_content_val := check_push_response.result.get('content').get_string;
github_content_val := replace(replace(github_content_val, chr(10)), chr(13));
if object_content != github_content_val then
return 'Object ' || object_owner || '.' || object_name || ' is different from the repository version';
else
return 'Object ' || object_owner || '.' || object_name || ' is equal to repository version';
end if;
else
return 'Object ' || object_owner || '.' || object_name || ' not pushed to repository: ' || github_oracle_session.gh_r;
end if;
end compare_object;
end github_oracle_content;
/