database_settings.py
DatabaseSettings
¶
Source code in src/spyglass/utils/database_settings.py
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 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
|
__init__(user_name=None, host_name=None, debug=False, target_database=None, exec_user=None, exec_pass=None, test_mode=False)
¶
Class to manage common database settings
Roles: - dj_guest: select for all prefix - dj_collab: select for all prefix, all for user prefix - dj_user: select for all prefix, all for user prefix, all for shared - dj_admin: all for all prefix
Note: To add dj_user role to all those with common access, run: query = "SELECT user, host FROM mysql.db WHERE Db LIKE 'common%';" users = dj.conn().query(query).fetchall() for user in users: dj.conn().query(f"GRANT dj_user TO '{user[0][]}'@'%';")
Parameters:
Name | Type | Description | Default |
---|---|---|---|
user_name |
str
|
The name of the user to add to the database. Default from dj.config |
None
|
host_name |
str
|
The name of the host to add to the database. Default from dj.config |
None
|
debug |
bool
|
Default False. If True, pprint sql instead of running |
False
|
target_database |
str
|
Default is mysql. Can also be docker container id |
None
|
exec_user |
str
|
User for executing commands. If None, use dj.config |
None
|
exec_pass |
str
|
Password for executing commands. If None, use dj.config |
None
|
test_mode |
bool
|
Default False. If True, prepend sudo to commands for use in CI/CD Only true in github actions, not true in local testing. |
False
|
Source code in src/spyglass/utils/database_settings.py
add_guest(*args, **kwargs)
¶
add_collab(*args, **kwargs)
¶
Add collaborator user with full permissions to shared modules
add_user(check_exists=False, *args, **kwargs)
¶
Add user to database with permissions to shared modules
Source code in src/spyglass/utils/database_settings.py
add_admin(*args, **kwargs)
¶
add_module(module_name)
¶
Add module to database. Grant permissions to all users in group
Source code in src/spyglass/utils/database_settings.py
check_user_exists()
¶
Add user to database with permissions to shared modules
Source code in src/spyglass/utils/database_settings.py
add_user_by_role(role, check_exists=False)
¶
Add a user to the database with the specified role
Source code in src/spyglass/utils/database_settings.py
add_roles()
¶
write_temp_file(content)
¶
Write content to a temporary file and return the file object
Source code in src/spyglass/utils/database_settings.py
exec(file)
¶
Run commands saved to file in sql