test_db_config.sh 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/bin/bash
  2. if [ "$RNAME" == '' ]; then
  3. echo "ERROR: Env RNAME is missing!"
  4. exit 1
  5. fi
  6. if [ "$RDB" == '' ]; then
  7. echo "ERROR: Env RDB is missing!"
  8. exit 1
  9. fi
  10. export RAND=`perl -e 'print int(rand(999999999))'`
  11. DBNAME="$RNAME-$RAND"
  12. DBFILE=config/database.yml
  13. DB_PRODUCTION=$DBNAME"_production"
  14. DB_TEST=$DBNAME"_test"
  15. DB_DEVELOPMENT=$DBNAME"_development"
  16. echo "Creating $DBFILE for $RDB tests with $DBNAME"
  17. if [ "$RDB" == 'mysql' ]; then
  18. echo "production:" > $DBFILE
  19. echo " adapter: mysql2" >> $DBFILE
  20. echo " database: $DB_PRODUCTION" >> $DBFILE
  21. echo " pool: 50" >> $DBFILE
  22. echo " timeout: 5000" >> $DBFILE
  23. echo " encoding: utf8" >> $DBFILE
  24. echo " username: root" >> $DBFILE
  25. echo " password:" >> $DBFILE
  26. echo "test:" >> $DBFILE
  27. echo " adapter: mysql2" >> $DBFILE
  28. echo " database: $DB_TEST" >> $DBFILE
  29. echo " pool: 50" >> $DBFILE
  30. echo " timeout: 5000" >> $DBFILE
  31. echo " encoding: utf8" >> $DBFILE
  32. echo " username: root" >> $DBFILE
  33. echo " password:" >> $DBFILE
  34. echo "development:" >> $DBFILE
  35. echo " adapter: mysql2" >> $DBFILE
  36. echo " database: $DB_DEVELOPMENT" >> $DBFILE
  37. echo " pool: 50" >> $DBFILE
  38. echo " timeout: 5000" >> $DBFILE
  39. echo " encoding: utf8" >> $DBFILE
  40. echo " username: root" >> $DBFILE
  41. echo " password:" >> $DBFILE
  42. fi
  43. if [ "$RDB" == 'postgresql' ]; then
  44. echo "production:" > $DBFILE
  45. echo " adapter: postgresql" >> $DBFILE
  46. echo " database: $DB_PRODUCTION" >> $DBFILE
  47. echo " pool: 50" >> $DBFILE
  48. echo " timeout: 5000" >> $DBFILE
  49. echo " encoding: utf8" >> $DBFILE
  50. echo " username: root" >> $DBFILE
  51. echo " password: pass" >> $DBFILE
  52. echo "test:" >> $DBFILE
  53. echo " adapter: postgresql" >> $DBFILE
  54. echo " database: $DB_TEST" >> $DBFILE
  55. echo " pool: 50" >> $DBFILE
  56. echo " timeout: 5000" >> $DBFILE
  57. echo " encoding: utf8" >> $DBFILE
  58. echo " username: root" >> $DBFILE
  59. echo " password: pass" >> $DBFILE
  60. echo "development:" >> $DBFILE
  61. echo " adapter: postgresql" >> $DBFILE
  62. echo " database: $DB_DEVELOPMENT" >> $DBFILE
  63. echo " pool: 50" >> $DBFILE
  64. echo " timeout: 5000" >> $DBFILE
  65. echo " encoding: utf8" >> $DBFILE
  66. echo " username: root" >> $DBFILE
  67. echo " password: pass" >> $DBFILE
  68. fi