From 2c34b7647dcb51435751139b0a000af2cca526e6 Mon Sep 17 00:00:00 2001 From: YuJin <you5463@ajou.ac.kr> Date: Fri, 6 Dec 2024 14:43:32 +0900 Subject: [PATCH] feat: Add SportType SQL insert statements for initial data --- Makefile | 8 ++++-- webapp/backend/scripts/init_sporttype.sh | 34 +++++++++++++++++++++++ webapp/backend/scripts/init_sporttype.sql | 12 ++++++++ 3 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 webapp/backend/scripts/init_sporttype.sh create mode 100644 webapp/backend/scripts/init_sporttype.sql diff --git a/Makefile b/Makefile index 1579294..c6ec458 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 0000000..2493bee --- /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 0000000..577a009 --- /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 -- GitLab