Skip to content

Commit 9420ec9

Browse files
committed
Fix the postgresdb Make command when ruining on Linux #1080
Signed-off-by: tdruez <tdruez@nexb.com>
1 parent 56de573 commit 9420ec9

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

Makefile

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ SCANCODEIO_DB_PASSWORD=scancodeio
3737
POSTGRES_INITDB_ARGS=--encoding=UTF-8 --lc-collate=en_US.UTF-8 --lc-ctype=en_US.UTF-8
3838
DATE=$(shell date +"%Y-%m-%d_%H%M")
3939

40+
# Use sudo for postgres, only on Linux
41+
UNAME := $(shell uname)
42+
ifeq ($(UNAME), Linux)
43+
SUDO_POSTGRES=sudo -u postgres
44+
else
45+
SUDO_POSTGRES=
46+
endif
47+
4048
virtualenv:
4149
@echo "-> Bootstrap the virtualenv with PYTHON_EXE=${PYTHON_EXE}"
4250
@${PYTHON_EXE} ${VIRTUALENV_PYZ} --never-download --no-periodic-update .
@@ -99,12 +107,12 @@ migrate:
99107
postgresdb:
100108
@echo "-> Configure PostgreSQL database"
101109
@echo "-> Create database user ${SCANCODEIO_DB_NAME}"
102-
@createuser --no-createrole --no-superuser --login --inherit --createdb '${SCANCODEIO_DB_USER}' || true
103-
@psql -c "alter user ${SCANCODEIO_DB_USER} with encrypted password '${SCANCODEIO_DB_PASSWORD}';" || true
110+
@${SUDO_POSTGRES} createuser --no-createrole --no-superuser --login --inherit --createdb '${SCANCODEIO_DB_USER}' || true
111+
@${SUDO_POSTGRES} psql -c "alter user ${SCANCODEIO_DB_USER} with encrypted password '${SCANCODEIO_DB_PASSWORD}';" || true
104112
@echo "-> Drop ${SCANCODEIO_DB_NAME} database"
105-
@dropdb ${SCANCODEIO_DB_NAME} || true
113+
@${SUDO_POSTGRES} dropdb ${SCANCODEIO_DB_NAME} || true
106114
@echo "-> Create ${SCANCODEIO_DB_NAME} database"
107-
@createdb --owner=${SCANCODEIO_DB_USER} ${POSTGRES_INITDB_ARGS} ${SCANCODEIO_DB_NAME}
115+
@${SUDO_POSTGRES} createdb --owner=${SCANCODEIO_DB_USER} ${POSTGRES_INITDB_ARGS} ${SCANCODEIO_DB_NAME}
108116
@$(MAKE) migrate
109117

110118
backupdb:

0 commit comments

Comments
 (0)