tracim-create-database-and-user.sh.deprecated 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/bin/bash
  2. TRACIM_DB_USER='tracim_user'
  3. TRACIM_DB_USER_PASSWORD='tracim_user_password'
  4. TRACIM_DB_NAME='tracim'
  5. # DB_HOST='127.0.0.1'
  6. # DB_PORT='5432'
  7. BUILD_DB_SQL="
  8. CREATE USER ${TRACIM_DB_USER} WITH PASSWORD '${TRACIM_DB_USER_PASSWORD}';
  9. CREATE DATABASE ${TRACIM_DB_NAME};
  10. GRANT ALL PRIVILEGES ON DATABASE ${TRACIM_DB_NAME} TO ${TRACIM_DB_USER};
  11. "
  12. if [ `whoami` != 'postgres' ]; then
  13. echo "This script is intended to be executed as postgres user."
  14. exit 1
  15. fi
  16. echo "About to create a new database and user:"
  17. echo "- database: ${TRACIM_DB_NAME}"
  18. echo "- user: ${TRACIM_DB_USER}"
  19. echo "- password: xxxxxx"
  20. echo
  21. echo "Sleeping 10 seconds."
  22. echo "- stop process by CTRL+C if in doubt."
  23. echo "..."
  24. sleep 10
  25. echo ${BUILD_DB_SQL} | psql
  26. #  -h ${DB_HOST} -p ${DB_PORT}
  27. # IF AN ERROR OCCURS, YOU CAN SIMPLY RESET YOUR POSTGRES SERVER
  28. # WITH THE FOLLOWING SQL COMMANDS (EXECUTED AS postgres USER):
  29. #
  30. # DROP DATABASE tracim
  31. # DROP OWNED BY tracim_master;
  32. # DROP USER tracim_master;
  33. #
  34. # or more faster:
  35. #
  36. # psql -c "DROP DATABASE tracim;"
  37. # psql -c "DROP OWNED BY tracim_master;"
  38. # psql -c "DROP USER tracim_master;"
  39. echo
  40. echo "You can now init schema and data by running the following command:"
  41. echo
  42. echo "psql -h 127.0.0.1 -U ${TRACIM_DB_USER} -W ${TRACIM_DB_NAME} < tracim-init-database.new.sql"
  43. echo
  44. echo "note that you'll be asked for the password"