added app:clear_init
This commit is contained in:
1 parent
61d20d8f14
commit
09f6a643d9
2 files changed
+44
-1
No files matched your search
@@ -35,6 +35,12 @@ services:
|
|||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
Possible Commands
|
||||||
|
-----------------
|
||||||
|
- **app:init**: (Default) Create database and user if not exist
|
||||||
|
- **app:clear_init**: Like `app:init` but remove all tables from database
|
||||||
|
|
||||||
|
|
||||||
Available Configuration Parameters
|
Available Configuration Parameters
|
||||||
----------------------------------
|
----------------------------------
|
||||||
|
|
||||||
|
|||||||
+38
-1
@@ -57,6 +57,16 @@ check_database_connection() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
postgresql_clear_init() {
|
||||||
|
result=`psql -h$DB_HOST -p $DB_PORT -U$DB_ROOT_USER -tc "SELECT datname FROM pg_catalog.pg_database WHERE datname like '$DB_DATABASE';"`
|
||||||
|
if [ $result ]; then
|
||||||
|
psql -h$DB_HOST -p $DB_PORT -U$DB_ROOT_USER -tc "drop database if exists $DB_DATABASE;" > /dev/null
|
||||||
|
echo "Removed database \"$DB_DATABASE\""
|
||||||
|
fi
|
||||||
|
|
||||||
|
postgresql_init
|
||||||
|
}
|
||||||
|
|
||||||
postgresql_init() {
|
postgresql_init() {
|
||||||
result=`psql -h$DB_HOST -p $DB_PORT -U$DB_ROOT_USER -tc "SELECT datname FROM pg_catalog.pg_database WHERE datname like '$DB_DATABASE';"`
|
result=`psql -h$DB_HOST -p $DB_PORT -U$DB_ROOT_USER -tc "SELECT datname FROM pg_catalog.pg_database WHERE datname like '$DB_DATABASE';"`
|
||||||
if [ ! $result ]; then
|
if [ ! $result ]; then
|
||||||
@@ -77,6 +87,17 @@ postgresql_init() {
|
|||||||
psql -h$DB_HOST -p $DB_PORT -U$DB_ROOT_USER -tc "GRANT ALL PRIVILEGES ON DATABASE $DB_DATABASE to $DB_USER;" > /dev/null
|
psql -h$DB_HOST -p $DB_PORT -U$DB_ROOT_USER -tc "GRANT ALL PRIVILEGES ON DATABASE $DB_DATABASE to $DB_USER;" > /dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
mysql_clear_init() {
|
||||||
|
result=`mysql -P $DB_PORT -u$DB_ROOT_USER -p$DB_ROOT_PASSWORD -h$DB_HOST -Bse "show databases like '$DB_DATABASE';"`
|
||||||
|
if [ $result ]; then
|
||||||
|
mysql -P $DB_PORT -u$DB_ROOT_USER -p$DB_ROOT_PASSWORD -h$DB_HOST -Bse "drop database if exists $DB_DATABASE;"
|
||||||
|
echo "Removed database \"$DB_DATABASE\""
|
||||||
|
fi
|
||||||
|
|
||||||
|
mysql_init
|
||||||
|
}
|
||||||
|
|
||||||
mysql_init() {
|
mysql_init() {
|
||||||
result=`mysql -P $DB_PORT -u$DB_ROOT_USER -p$DB_ROOT_PASSWORD -h$DB_HOST -Bse "show databases like '$DB_DATABASE';"`
|
result=`mysql -P $DB_PORT -u$DB_ROOT_USER -p$DB_ROOT_PASSWORD -h$DB_HOST -Bse "show databases like '$DB_DATABASE';"`
|
||||||
if [ ! $result ]; then
|
if [ ! $result ]; then
|
||||||
@@ -99,17 +120,33 @@ mysql_init() {
|
|||||||
|
|
||||||
|
|
||||||
case ${1} in
|
case ${1} in
|
||||||
app:init)
|
app:init|app:clear_init)
|
||||||
check_database_connection
|
check_database_connection
|
||||||
|
|
||||||
case ${DB_TYPE} in
|
case ${DB_TYPE} in
|
||||||
postgresql)
|
postgresql)
|
||||||
|
case ${1} in
|
||||||
|
app:init)
|
||||||
postgresql_init
|
postgresql_init
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
app:clear_init)
|
||||||
|
postgresql_clear_init
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
|
||||||
mysql)
|
mysql)
|
||||||
|
case ${1} in
|
||||||
|
app:init)
|
||||||
mysql_init
|
mysql_init
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
app:clear_init)
|
||||||
|
mysql_clear_init
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
|
|||||||
Reference in new issue
Block a user