-
Notifications
You must be signed in to change notification settings - Fork 1
/
GrantPermissionsOnTables.R
45 lines (39 loc) · 1.26 KB
/
GrantPermissionsOnTables.R
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
# Optional scripts to set permissions and to analyze tables ------------------
source("scriptsForStudyCoordinator/SetConnectionDetails.R")
connection <- DatabaseConnector::connect(
connectionDetails = resultsConnectionDetails
)
# Grant read only permissions to all tables
sql <- "GRANT USAGE ON SCHEMA @schema TO @results_user;
GRANT SELECT ON ALL TABLES IN SCHEMA @schema TO @results_user;
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA @schema TO @results_user;"
message("Setting permissions for results schema")
sql <- SqlRender::render(
sql = sql,
schema = resultsDatabaseSchema,
results_user = 'shinyproxy'
)
DatabaseConnector::executeSql(
connection = connection,
sql = sql,
progressBar = FALSE,
reportOverallTime = FALSE
)
# Analyze all tables in the results schema
message("Analyzing all tables in results schema")
sql <- "ANALYZE @schema.@table_name;"
tableList <- DatabaseConnector::getTableNames(
connection = connection,
databaseSchema = resultsDatabaseSchema
)
for (i in 1:length(tableList)) {
DatabaseConnector::renderTranslateExecuteSql(
connection = connection,
sql = sql,
schema = resultsDatabaseSchema,
table_name = tableList[i],
progressBar = FALSE,
reportOverallTime = FALSE
)
}
DatabaseConnector::disconnect(connection)