SHARE
TWEET

Untitled

a guest Aug 12th, 2016 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. export PGPORT ?= 4488
  2. PG_PATH ?= $(shell if test -d /usr/lib/postgresql/9.1; then echo /usr/lib/postgresql/9.1; else echo /usr/lib/postgresql/8.4; fi)
  3. PG_DIR = ${PWD}/instance/var
  4. PG_DATA = ${PG_DIR}/data
  5. PG_RUN = ${PG_DIR}/run
  6. PG_LOG = ${PG_DIR}/log
  7. PG_SOCKET = ${PG_RUN}/.s.PGSQL.${PGPORT}
  8. PGPARAMS = -D ${PG_DATA} -o "-F -c unix_socket_directory=${PG_RUN} -c custom_variable_classes='busy' -c busy.active_user=0" -l ${PG_LOG}/pg.log
  9.  
  10.  
  11. ${PG_DATA}/postgresql.conf:
  12.     mkdir -p ${PG_DATA}
  13.     ${PG_PATH}/bin/initdb -D ${PG_DATA} -E UNICODE
  14.  
  15. ${PG_DATA}/initialized:
  16.     ${PG_PATH}/bin/createdb -E UTF8 test -h ${PG_RUN}
  17.     ${PG_PATH}/bin/createdb -E UTF8 development -h ${PG_RUN}
  18.     echo 1 > ${PG_DATA}/initialized
  19.  
  20. instance/done: ${PG_DATA}/postgresql.conf
  21.     $(MAKE) start_database
  22.     $(MAKE) ${PG_DATA}/initialized
  23.     $(MAKE) stop_database
  24.     echo 1 > ${PWD}/instance/done
  25.  
  26. ${PG_SOCKET}:
  27.     mkdir -p ${PG_RUN}
  28.     mkdir -p ${PG_LOG}
  29.     ${PG_PATH}/bin/pg_ctl $(PGPARAMS) start -w
  30.  
  31. .PHONY: testpsql
  32. testpsql:
  33.     psql -h ${PG_RUN}/ -d test
  34.  
  35. .PHONY: devpsql
  36. devpsql: ${PG_RUN}/.s.PGSQL.${PGPORT}
  37.     psql -h ${PG_RUN}/ -d development
  38.  
  39. .PHONY: reset_development
  40. reset_development: ${PG_SOCKET}
  41.     psql -h ${PG_RUN}/ -d development -c "drop schema public cascade"
  42.     psql -h ${PG_RUN}/ -d development -c "create schema public"
  43.  
  44. .PHONY: reset_test
  45. reset_test: ${PG_SOCKET}
  46.     psql -h ${PG_RUN}/ -d development -c "drop schema public cascade"
  47.     psql -h ${PG_RUN}/ -d development -c "create schema public"
  48.  
  49. .PHONY: start_database
  50. start_database: ${PG_DATA}/postgresql.conf ${PG_RUN}/.s.PGSQL.${PGPORT}
  51.  
  52. .PHONY: force_start_database
  53. force_start_database:
  54.     ${PG_PATH}/bin/pg_ctl $(PGPARAMS) start -w
  55.  
  56. .PHONY: database_status
  57. database_status:
  58.     ${PG_PATH}/bin/pg_ctl $(PGPARAMS) status
  59.  
  60. .PHONY: stop_database
  61. stop_database:
  62.     test -f ${PG_DATA}/postmaster.pid && ${PG_PATH}/bin/pg_ctl $(PGPARAMS) stop -m i || true
  63.  
  64. schema.sql:
  65.     ${PG_PATH}/bin/pg_dump --format=p -h ${PG_RUN}/ development -s -x -O > schema.sql
  66.  
  67. .PHONY: download_backup
  68. download_backup:
  69.     mkdir -p backup
  70.     scp server:/var/backup/example.com/dbdump ./backup/dbdump
  71.  
  72. .PHONY: import_backup
  73. import_backup: ${PG_SOCKET}
  74.     psql -h ${PG_RUN}/ -d development -c "drop schema public cascade"
  75.     ${PG_PATH}/bin/droplang plpgsql development -h ${PG_RUN}/ || true
  76.     psql -h ${PG_RUN}/ -d development -c "create schema public"
  77.     ${PG_PATH}/bin/pg_restore -d development -h ${PG_RUN} --no-owner < backup/dbdump || true
  78.     psql -h ${PG_RUN}/ -d development -c "update users set password = '\$$2a\$$04\$$DqEhufK/FNt46xIhKDQDO.OJNGKFMFAS5R4tOTV2JmjrmhPyuGHDS'"
  79.  
  80. .PHONY: dbdump
  81. dbdump: ${PG_SOCKET}
  82.     ${PG_PATH}/bin/pg_dump --format=c -h ${PG_RUN}/ development > dbdump
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top