From d3afdf3afd589852d5500cf98f7e01314c530cde Mon Sep 17 00:00:00 2001 From: cubic Date: Wed, 9 Feb 2022 14:58:36 +0800 Subject: [PATCH] feat(Install Script): add script for remove unit test data --- .../installation/install_from_scratch.md | 7 ++++ misc/install.sh | 1 + misc/remove_test_data.sh | 34 +++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 misc/remove_test_data.sh diff --git a/doc/zh-cn/installation/install_from_scratch.md b/doc/zh-cn/installation/install_from_scratch.md index ee5f1bd..53d2016 100644 --- a/doc/zh-cn/installation/install_from_scratch.md +++ b/doc/zh-cn/installation/install_from_scratch.md @@ -223,6 +223,13 @@ cd /data/www/codefever-community/misc sh ./create_db.sh ``` +如果你不需要对 CodeFever 进行代码上的修改, 或者将来不计划运行单元测试, 可以删除测试数据 + +```shell +cd /data/www/codefever-community/misc +sh ./remove_test_data.sh +``` + 为服务开启 `chkconfig` 以开机自动运行 ```shell diff --git a/misc/install.sh b/misc/install.sh index cb8151b..f401830 100644 --- a/misc/install.sh +++ b/misc/install.sh @@ -73,3 +73,4 @@ echo '1. You shuold edit file echo '2. You shuold edit file to finish cookie settings.' echo '3. You shuold edit file to finish git gateway security settings.' echo '4. Run sh ./create_db.sh after change env.yaml.' +echo '5. Run sh ./remove_test_data.sh if you DO NOT need to run unit test.' diff --git a/misc/remove_test_data.sh b/misc/remove_test_data.sh new file mode 100644 index 0000000..e050b7f --- /dev/null +++ b/misc/remove_test_data.sh @@ -0,0 +1,34 @@ +#!/bin/bash +if [ $UID -ne 0 ]; then + echo 'run as root please' + exit 1 +fi + +DB_HOST=`cat ../env.yaml | grep host: | awk -F: '{ print $2 }' | sed 's/^\s*//'` +DB_PORT=`cat ../env.yaml | grep port: | awk -F: '{ print $2 }' | sed 's/^\s*//'` +DB_USER=`cat ../env.yaml | grep username: | awk -F: '{ print $2 }' | sed 's/^\s*//'` +DB_PASS=`cat ../env.yaml | grep password: | awk -F: '{ print $2 }' | sed 's/^\s*//'` +DB_NAME=`cat ../env.yaml | grep db: | awk -F: '{ print $2 }' | sed 's/^\s*//'` + + +mysql -h"$DB_HOST" -P"$DB_PORT" -u"$DB_USER" -p"$DB_PASS" -D"$DB_NAME" -e"DELETE FROM cc_users WHERE u_key = '26c20714af8bc20aa85be657a5170e71';"; +mysql -h"$DB_HOST" -P"$DB_PORT" -u"$DB_USER" -p"$DB_PASS" -D"$DB_NAME" -e"DELETE FROM cc_users WHERE u_key = 'f4a9c54adef17599d4f709a1167f0fcd';"; + +mysql -h"$DB_HOST" -P"$DB_PORT" -u"$DB_USER" -p"$DB_PASS" -D"$DB_NAME" -e"DELETE FROM cc_ssh_keys WHERE u_key = 'f4a9c54adef17599d4f709a1167f0fcd';"; + +echo 'Test User Data Removed!' + +mysql -h"$DB_HOST" -P"$DB_PORT" -u"$DB_USER" -p"$DB_PASS" -D"$DB_NAME" -e"DELETE FROM cc_repositories WHERE r_key = '2f941aef39bc8a048da55dd28c678655';"; + +echo 'Test Repository Data Removed!' + +mysql -h"$DB_HOST" -P"$DB_PORT" -u"$DB_USER" -p"$DB_PASS" -D"$DB_NAME" -e"DELETE FROM cc_groups WHERE g_key = 'e6508c1a66e86f697c96bdffb30c1ae3';"; + +echo 'Test Group Data Removed!' + +rm -rf ../git-storage/7b56eed88bda864c6e5ae1540549f8ab + +echo 'Test Repository Removed' + +echo 'Done!' +echo 'All Test Data Removed !'