mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[enh] Add dropdb helper.
This commit is contained in:
parent
f4af627a88
commit
6828953dc9
3 changed files with 42 additions and 0 deletions
|
@ -495,6 +495,21 @@ app:
|
|||
full: --sql
|
||||
help: Initial SQL file
|
||||
|
||||
### app_dropdb()
|
||||
dropdb:
|
||||
action_help: Drop database
|
||||
# api: POST /tools/dropdb
|
||||
arguments:
|
||||
db:
|
||||
help: Name of the database
|
||||
-k:
|
||||
full: --keep-user
|
||||
help: Do not drop corresponding user
|
||||
action: store_true
|
||||
-u:
|
||||
full: --user
|
||||
help: DB user name (db unless set)
|
||||
|
||||
### app_makedefault()
|
||||
makedefault:
|
||||
action_help: Redirect domain root to an app
|
||||
|
|
|
@ -863,6 +863,29 @@ def app_initdb(user, password=None, db=None, sql=None):
|
|||
msignals.display(m18n.n('mysql_db_initialized'), 'success')
|
||||
|
||||
|
||||
def app_dropdb(db, keep_user=False, user=None):
|
||||
"""
|
||||
Drop database
|
||||
|
||||
Keyword argument:
|
||||
db -- DB name
|
||||
|
||||
"""
|
||||
mysql_root_pwd = open('/etc/yunohost/mysql').read().rstrip()
|
||||
mysql_command = 'mysql -u root -p%s -e "DROP DATABASE %s ;"' % (mysql_root_pwd, db)
|
||||
if os.system(mysql_command) != 0:
|
||||
raise MoulinetteError(errno.EIO, m18n.n('mysql_db_drop_failed'))
|
||||
if not keep_user:
|
||||
if user is None:
|
||||
user=db
|
||||
mysql_command = 'mysql -u root -p%s -e "DROP USER \'%s\'@localhost ;"' % (mysql_root_pwd, user)
|
||||
if os.system(mysql_command) != 0:
|
||||
raise MoulinetteError(errno.EIO, m18n.n('mysql_dbuser_drop_failed'))
|
||||
msignals.display(m18n.n('mysql_dbuser_dropped'), 'success')
|
||||
|
||||
msignals.display(m18n.n('mysql_db_dropped'), 'success')
|
||||
|
||||
|
||||
def app_ssowatconf(auth):
|
||||
"""
|
||||
Regenerate SSOwat configuration file
|
||||
|
|
|
@ -35,6 +35,10 @@
|
|||
"mysql_db_creation_failed" : "MySQL database creation failed",
|
||||
"mysql_db_init_failed" : "MySQL database init failed",
|
||||
"mysql_db_initialized" : "MySQL database successfully initialized",
|
||||
"mysql_db_drop_failed" : "MySQL drop database failed",
|
||||
"mysql_db_dropped" : "MySQL drop database successfully",
|
||||
"mysql_dbuser_drop_failed" : "MySQL drop user failed",
|
||||
"mysql_dbuser_dropped" : "MySQL drop user successfully",
|
||||
"extracting" : "Extracting...",
|
||||
"downloading" : "Downloading...",
|
||||
"executing_script": "Executing script...",
|
||||
|
|
Loading…
Add table
Reference in a new issue