Add script()
and set_user_password()
to postgresql fablib
This commit is contained in:
parent
46ac996d96
commit
bc7357e042
|
@ -58,6 +58,13 @@ def sql(sql, database=''):
|
|||
return sudo('sudo -u postgres psql --tuples-only --no-align --command="{0}" {1}'.format(sql, database), shell=False)
|
||||
|
||||
|
||||
def script(path, database=''):
|
||||
"""
|
||||
Execute a SQL script as the 'postgres' user
|
||||
"""
|
||||
return sudo('sudo -u postgres psql --file={} {}'.format(path, database), shell=False)
|
||||
|
||||
|
||||
def user_exists(name):
|
||||
"""
|
||||
Determine if a given PostgreSQL user exists.
|
||||
|
@ -75,8 +82,15 @@ def create_user(name, password=None, checkfirst=True, createdb=False):
|
|||
sudo('sudo -u postgres createuser {createdb} --no-createrole --no-superuser {name}'.format(
|
||||
createdb=createdb, name=name))
|
||||
if password:
|
||||
set_user_password(name, password)
|
||||
|
||||
|
||||
def set_user_password(name, password):
|
||||
"""
|
||||
Set the password for a PostgreSQL user account
|
||||
"""
|
||||
with hide('running'):
|
||||
sql("ALTER USER \\\"{0}\\\" PASSWORD '{1}';".format(name, password))
|
||||
sql("ALTER USER \\\"{}\\\" PASSWORD '{}';".format(name, password))
|
||||
|
||||
|
||||
def db_exists(name):
|
||||
|
|
Loading…
Reference in a new issue