-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Remove dbmigration and add dbimport/dbexport
- Loading branch information
Marco Ris
committed
May 27, 2021
1 parent
6346189
commit 17204b8
Showing
3 changed files
with
75 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/bin/bash | ||
if [ "$1" = "local" ] | ||
then | ||
# Locally | ||
docker exec -it $(docker ps -aqf "name=gulpwordpress_db_1") mysqldump -uroot -ptoor --opt --add-drop-table wordpress > ./sql/local.sql | ||
sed -i '1d' ./sql/local.sql | ||
elif [ "$1" = "prod" ] || [ "$1" = "stage" ] | ||
then | ||
# Remotely | ||
SSH_USER=$(grep SSH_USER .env | xargs) | ||
IFS='=' read -ra SSH_USER <<< "$SSH_USER" | ||
SSH_USER=${SSH_USER[1]} | ||
|
||
# Get ssh host | ||
SSH_HOST=$(grep SSH_HOST .env | xargs) | ||
IFS='=' read -ra SSH_HOST <<< "$SSH_HOST" | ||
SSH_HOST=${SSH_HOST[1]} | ||
|
||
# Get ssh key | ||
SSH_KEY=$SSH_USER | ||
IFS='.' read -ra SSH_KEY <<< "$SSH_KEY" | ||
SSH_KEY=${SSH_KEY[0]} | ||
|
||
# Set public directory | ||
PUBLICPATH="public_html" | ||
|
||
if [[ "$1" == "stage" ]] | ||
then | ||
# Set public directory | ||
PUBLICPATH+="/stage" | ||
fi | ||
|
||
ssh -i ~/.ssh/$SSH_KEY $SSH_USER@$SSH_HOST "cd ~/$PUBLICPATH && wp db export sql/$1.sql" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,42 @@ | ||
#!/bin/bash | ||
cat ./sql/local.sql | docker exec -i gulpwordpress_db_1 mysql -uwordpress -pwordpress wordpress | ||
rm -f ./sql/local.sql | ||
rm -f ./sql/prod.sql | ||
rm -f ./sql/stage.sql | ||
if [ "$1" = "local" ] | ||
then | ||
# Clear local wordpress database | ||
docker exec -it $(docker ps -aqf "name=gulpwordpress_db_1") mysql -uroot -ptoor -e "DROP DATABASE wordpress; CREATE DATABASE wordpress;" | ||
# Import local.sql | ||
cat ./sql/local.sql | docker exec -i gulpwordpress_db_1 mysql -uwordpress -pwordpress wordpress | ||
rm -f ./sql/local.sql | ||
elif [ "$1" = "prod" ] || [ "$1" = "stage" ] | ||
then | ||
# Remotely | ||
SSH_USER=$(grep SSH_USER .env | xargs) | ||
IFS='=' read -ra SSH_USER <<< "$SSH_USER" | ||
SSH_USER=${SSH_USER[1]} | ||
|
||
# Get ssh host | ||
SSH_HOST=$(grep SSH_HOST .env | xargs) | ||
IFS='=' read -ra SSH_HOST <<< "$SSH_HOST" | ||
SSH_HOST=${SSH_HOST[1]} | ||
|
||
# Get ssh key | ||
SSH_KEY=$SSH_USER | ||
IFS='.' read -ra SSH_KEY <<< "$SSH_KEY" | ||
SSH_KEY=${SSH_KEY[0]} | ||
|
||
# Set public directory | ||
PUBLICPATH="public_html" | ||
|
||
if [[ "$1" == "stage" ]] | ||
then | ||
# Set public directory | ||
PUBLICPATH+="/stage" | ||
fi | ||
|
||
# Connect to host, clear remote wordpress database, import sql dump, remove sql dump file | ||
ssh -i ~/.ssh/$SSH_KEY $SSH_USER@$SSH_HOST "cd ~/$PUBLICPATH && wp db clean --yes && wp db import sql/$1.sql; rm -f sql/$1.sql" | ||
else | ||
echo "Wrong parameter!" | ||
echo "npm run dbimport local" | ||
echo "npm run dbimport stage" | ||
echo "npm run dbimport prod" | ||
fi |
This file was deleted.
Oops, something went wrong.