I want to create a database user for my setup fabric script but createuser has interactive password entering and seams not to like fabric.
You can now run commands as the PostgreSQL superuser.To create a user, type the following command: createuser --interactive --pwprompt At the Enter name of role to add: prompt, type the user's name. At the Enter password for new role: prompt, type a password for the user.
It seems PostgreSQL does not allow to create a database table named 'user'. But MySQL will allow to create such a table.
To extend the answer with a Fabric example...
# In fabfile.py
def create_database():
"""Creates role and database"""
db_user = get_user() # define these
db_pass = get_pass()
db_name = get_db_name()
sudo('psql -c "CREATE USER %s WITH NOCREATEDB NOCREATEUSER " \
"ENCRYPTED PASSWORD E\'%s\'"' % (db_user, db_pass), user='postgres')
sudo('psql -c "CREATE DATABASE %s WITH OWNER %s"' % (
db_name, db_user), user='postgres')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With