Skip to content

Commit

Permalink
IDEMPIERE-3821 Adapt RUN_ImportIdempiere.sh to allow amazon postgresq…
Browse files Browse the repository at this point in the history
…l RDS
  • Loading branch information
CarlosRuiz-globalqss committed Nov 16, 2018
1 parent 15b9588 commit 28171cd
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 5 deletions.
37 changes: 34 additions & 3 deletions org.adempiere.server-feature/utils.unix/postgresql/DBRestore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ if [ "$IDEMPIERE_HOME" = "" -o "$ADEMPIERE_DB_NAME" = "" -o "$ADEMPIERE_DB_SERV
exit 1
fi

ISAMAZONRDS=N
if echo "$ADEMPIERE_DB_SERVER" | grep 'rds.amazonaws.com$' > /dev/null
then
ISAMAZONRDS=Y
fi

PGPASSWORD=$4
export PGPASSWORD
if [ "x$4" = "x^TryLocalConnection^" ]
then
LOCALPG=true # Allow to run this command with user postgres (just useful running configure as root)
else
LOCALPG=false
fi

PGPASSWORD=$4
export PGPASSWORD
Expand All @@ -33,15 +47,33 @@ fi
echo -------------------------------------
echo Recreate user and database
echo -------------------------------------
ADEMPIERE_CREATE_ROLE_SQL="CREATE ROLE $2 SUPERUSER LOGIN PASSWORD '$3'"
if [ $ISAMAZONRDS = Y ]
then
# modified for amazon RDS - doesn't allow SUPERUSER
ROOT_ROLE="CREATEDB IN ROLE rds_superuser, adempiere"
else
ROOT_ROLE="SUPERUSER"
fi
ADEMPIERE_CREATE_ROLE_SQL="CREATE ROLE $2 $ROOT_ROLE LOGIN PASSWORD '$3'"
if [ $LOCALPG = "true" ]
then
# Assuming that adempiere role already exists (it was created out there)
PGPASSWORD=$3
export PGPASSWORD
dropdb -h $ADEMPIERE_DB_SERVER -p $ADEMPIERE_DB_PORT -U $2 $ADEMPIERE_DB_NAME
else
dropdb -h $ADEMPIERE_DB_SERVER -p $ADEMPIERE_DB_PORT -U postgres $ADEMPIERE_DB_NAME
if [ "x$2" != xadempiere ]
then
psql -h $ADEMPIERE_DB_SERVER -p $ADEMPIERE_DB_PORT -U postgres -c "CREATE ROLE adempiere"
fi
if [ $ISAMAZONRDS = Y ]
then
PGPASSWORD=$3
dropdb -h $ADEMPIERE_DB_SERVER -p $ADEMPIERE_DB_PORT -U $2 $ADEMPIERE_DB_NAME
PGPASSWORD=$4
else
dropdb -h $ADEMPIERE_DB_SERVER -p $ADEMPIERE_DB_PORT -U postgres $ADEMPIERE_DB_NAME
fi
dropuser -h $ADEMPIERE_DB_SERVER -p $ADEMPIERE_DB_PORT -U postgres $2
psql -h $ADEMPIERE_DB_SERVER -p $ADEMPIERE_DB_PORT -U postgres -c "$ADEMPIERE_CREATE_ROLE_SQL"
fi
Expand All @@ -54,7 +86,6 @@ createdb -h $ADEMPIERE_DB_SERVER -p $ADEMPIERE_DB_PORT -E UNICODE -T template0 -
echo -------------------------------------
echo Import Adempiere_pg.dmp
echo -------------------------------------
psql -h $ADEMPIERE_DB_SERVER -p $ADEMPIERE_DB_PORT -d $ADEMPIERE_DB_NAME -U $2 -c "drop schema sqlj cascade"
ADEMPIERE_ALTER_ROLE_SQL="ALTER ROLE $2 SET search_path TO adempiere, pg_catalog"
psql -h $ADEMPIERE_DB_SERVER -p $ADEMPIERE_DB_PORT -d $ADEMPIERE_DB_NAME -U $2 -c "$ADEMPIERE_ALTER_ROLE_SQL"
psql -h $ADEMPIERE_DB_SERVER -p $ADEMPIERE_DB_PORT -d $ADEMPIERE_DB_NAME -U $2 -f $IDEMPIERE_HOME/data/ExpDat.dmp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ if [ "$IDEMPIERE_HOME" = "" -o "$ADEMPIERE_DB_NAME" = "" -o "$ADEMPIERE_DB_SERV
exit 1
fi

ISAMAZONRDS=N
if echo "$ADEMPIERE_DB_SERVER" | grep 'rds.amazonaws.com$' > /dev/null
then
ISAMAZONRDS=Y
fi

PGPASSWORD=$4
export PGPASSWORD
if [ "x$4" = "x^TryLocalConnection^" ]
Expand All @@ -32,15 +38,33 @@ fi
echo -------------------------------------
echo Recreate user and database
echo -------------------------------------
ADEMPIERE_CREATE_ROLE_SQL="CREATE ROLE $2 SUPERUSER LOGIN PASSWORD '$3'"
if [ $ISAMAZONRDS = Y ]
then
# modified for amazon RDS - doesn't allow SUPERUSER
ROOT_ROLE="CREATEDB IN ROLE rds_superuser, adempiere"
else
ROOT_ROLE="SUPERUSER"
fi
ADEMPIERE_CREATE_ROLE_SQL="CREATE ROLE $2 $ROOT_ROLE LOGIN PASSWORD '$3'"
if [ $LOCALPG = "true" ]
then
# Assuming that adempiere role already exists (it was created out there)
PGPASSWORD=$3
export PGPASSWORD
dropdb -h $ADEMPIERE_DB_SERVER -p $ADEMPIERE_DB_PORT -U $2 $ADEMPIERE_DB_NAME
else
dropdb -h $ADEMPIERE_DB_SERVER -p $ADEMPIERE_DB_PORT -U postgres $ADEMPIERE_DB_NAME
if [ "x$2" != xadempiere ]
then
psql -h $ADEMPIERE_DB_SERVER -p $ADEMPIERE_DB_PORT -U postgres -c "CREATE ROLE adempiere"
fi
if [ $ISAMAZONRDS = Y ]
then
PGPASSWORD=$3
dropdb -h $ADEMPIERE_DB_SERVER -p $ADEMPIERE_DB_PORT -U $2 $ADEMPIERE_DB_NAME
PGPASSWORD=$4
else
dropdb -h $ADEMPIERE_DB_SERVER -p $ADEMPIERE_DB_PORT -U postgres $ADEMPIERE_DB_NAME
fi
dropuser -h $ADEMPIERE_DB_SERVER -p $ADEMPIERE_DB_PORT -U postgres $2
psql -h $ADEMPIERE_DB_SERVER -p $ADEMPIERE_DB_PORT -U postgres -c "$ADEMPIERE_CREATE_ROLE_SQL"
fi
Expand Down

0 comments on commit 28171cd

Please sign in to comment.