|
|
|
@ -14,6 +14,7 @@ __all__ = ( |
|
|
|
|
"pgsql_exists", |
|
|
|
|
"pgsql_grant", |
|
|
|
|
"pgsql_load", |
|
|
|
|
"pgsql_sql", |
|
|
|
|
"pgsql_user", |
|
|
|
|
) |
|
|
|
|
|
|
|
|
@ -242,6 +243,17 @@ def pgsql_load(database, path, **kwargs): |
|
|
|
|
return pgsql("psql", **kwargs) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def pgsql_sql(statement, database="template1", **kwargs): |
|
|
|
|
kwargs.setdefault("comment", "run SQL statement") |
|
|
|
|
|
|
|
|
|
kwargs['dbname'] = database |
|
|
|
|
|
|
|
|
|
command = pgsql("psql", **kwargs) |
|
|
|
|
command.statement += ' -c "%s"' % statement |
|
|
|
|
|
|
|
|
|
return command |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def pgsql_user(name, admin_pass=None, admin_user="postgres", op="create", password=None, **kwargs): |
|
|
|
|
"""Work with a PostgreSQL user. |
|
|
|
|
|
|
|
|
@ -278,7 +290,7 @@ def pgsql_user(name, admin_pass=None, admin_user="postgres", op="create", passwo |
|
|
|
|
return pgsql("dropuser", name, password=admin_pass, user=admin_user, **kwargs) |
|
|
|
|
elif op == "exists": |
|
|
|
|
kwargs.setdefault("comment", "determine if %s postgres user exists" % name) |
|
|
|
|
kwargs.setdefault("register", "pgsql_use_exists") |
|
|
|
|
kwargs.setdefault("register", "pgsql_user_exists") |
|
|
|
|
|
|
|
|
|
command = pgsql("psql", password=admin_pass, user=admin_user, **kwargs) |
|
|
|
|
|
|
|
|
@ -297,6 +309,6 @@ PGSQL_MAPPINGS = { |
|
|
|
|
'pgsql.dump': pgsql_dump, |
|
|
|
|
'pgsql.exists': pgsql_exists, |
|
|
|
|
'pgsql.grant': pgsql_grant, |
|
|
|
|
# 'pgsql.sql': pgsql_exec, |
|
|
|
|
'pgsql.sql': pgsql_sql, |
|
|
|
|
'pgsql.user': pgsql_user, |
|
|
|
|
} |
|
|
|
|