diff --git a/Makefile b/Makefile index 1579294dbfdec142f9606ba30aed5caf9900d352..c6ec458c08fa07bbabc476780adc5caeb7ac3aee 100644 --- a/Makefile +++ b/Makefile @@ -40,8 +40,12 @@ logs-minio: .PHONY: init-regions init-regions: - ./webapp/backend/scripts/init_regions.sh + bash ./webapp/backend/scripts/init_regions.sh + +.PHONY: init-sporttype +init-sporttype: + bash ./webapp/backend/scripts/init_sporttype.sh .PHONY: init-image-bucket init-image-bucket: - ./webapp/backend/scripts/init_image_bucket.sh + bash ./webapp/backend/scripts/init_image_bucket.sh diff --git a/webapp/backend/scripts/init_sporttype.sh b/webapp/backend/scripts/init_sporttype.sh new file mode 100644 index 0000000000000000000000000000000000000000..2493beedb24b851ea3a5f73f3ba46e51e616ab14 --- /dev/null +++ b/webapp/backend/scripts/init_sporttype.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +DB_CONTAINER_NAME="crewup-mysql-1" +DB_USER="admin" +DB_PASSWORD="localadmin" +DB_NAME="crewup" +SQL_FILE="$(dirname "$0")/init_sporttype.sql" + +echo "Checking if the Docker container '${DB_CONTAINER_NAME}' is running..." +if ! docker ps --filter "name=${DB_CONTAINER_NAME}" --format "{{.Names}}" | grep -w "${DB_CONTAINER_NAME}" > /dev/null; then + echo "Error: Docker container '${DB_CONTAINER_NAME}' is not running." + exit 1 +fi + +if [ ! -f "${SQL_FILE}" ]; then + echo "Error: SQL file '${SQL_FILE}' not found." + exit 1 +fi + +echo "Copying SQL file to Docker container..." +docker cp "${SQL_FILE}" "${DB_CONTAINER_NAME}:/tmp/$(basename "${SQL_FILE}")" +echo "Applying SQL file to the database '${DB_NAME}'..." +docker exec -i "${DB_CONTAINER_NAME}" sh -c "mysql --default-character-set=utf8 -u${DB_USER} -p${DB_PASSWORD} ${DB_NAME} < /tmp/$(basename "${SQL_FILE}")" + +if [ $? -eq 0 ]; then + echo "SQL file successfully applied to the database '${DB_NAME}'." +else + echo "Error: Failed to apply SQL file to the database '${DB_NAME}'." +fi + +echo "Cleaning up SQL file from the Docker container..." +docker exec -i "${DB_CONTAINER_NAME}" sh -c "rm -f /tmp/$(basename "${SQL_FILE}")" + +echo "Done." diff --git a/webapp/backend/scripts/init_sporttype.sql b/webapp/backend/scripts/init_sporttype.sql new file mode 100644 index 0000000000000000000000000000000000000000..577a009d58871131073dfa578ba990549824e10e --- /dev/null +++ b/webapp/backend/scripts/init_sporttype.sql @@ -0,0 +1,12 @@ +INSERT IGNORE INTO `SportType` (`sportTypeId`, `sportName`, `metadata`) +VALUES +(1, '러닝', '{ + "distance": ["3~4km", "5~6km", "7~8km", "9km 이상"], + "pace": ["4:00~4:30", "4:30~5:00", "5:00~5:30", "5:30~6:00", "6:00~6:30", "6:30 이상"] +}'), +(2, '헬스', '{ + "experience": ["초보자 (0~1년)", "중급자 (2~3년)", "상급자 (3년 이상)"] +}'), +(3, '클라이밍', '{ + "difficulty": ["상관 없음", "V1", "V2", "V3", "V4", "V5", "V6", "V7", "V8+"] +}'); \ No newline at end of file