diff --git a/.env b/.env index c65541e..46d2c7c 100644 --- a/.env +++ b/.env @@ -1,4 +1,5 @@ -BLOG_ENDPOINT=https://raw.githubusercontent.com/lumither/blog-posts/master -BACKEND_PORT=3001 +BLOG_ENDPOINT=git@github.com:Lumither/blog-posts.git +GIT_WORK_DIR=./blog_posts_git +BACKEND_PORT=3001 DB_CONNECTION=postgresql://localhost:5432/blog diff --git a/.gitignore b/.gitignore index bd9b839..a995bcd 100644 --- a/.gitignore +++ b/.gitignore @@ -40,3 +40,6 @@ bun.lockb # ide related .idea + +# tmp git working dir +/blog_posts_git/ diff --git a/backend/post.sql b/backend/post.sql index 8c7cf26..5b874d1 100644 --- a/backend/post.sql +++ b/backend/post.sql @@ -1,4 +1,4 @@ -CREATE TABLE Post +CREATE TABLE IF NOT EXISTS Post ( post_id UUID PRIMARY KEY, title VARCHAR(255) NOT NULL, diff --git a/backend/tag.sql b/backend/tag.sql index 3611b09..6c84b76 100644 --- a/backend/tag.sql +++ b/backend/tag.sql @@ -1,4 +1,4 @@ -CREATE TABLE Tag +CREATE TABLE IF NOT EXISTS Tag ( post_id UUID NOT NULL, tag VARCHAR(255) NOT NULL diff --git a/refresh.sh b/refresh.sh new file mode 100755 index 0000000..a09e231 --- /dev/null +++ b/refresh.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +source .env + +if [ -z "$BLOG_ENDPOINT" ]; then + echo "BLOG_ENDPOINT is not set in the .env file" + exit 1 +fi + +if [ -z "$GIT_WORK_DIR" ]; then + echo "GIT_WORK_DIR is not set in the .env file" + exit 1 +fi + +check_for_updates() { + cd "$GIT_WORK_DIR" || exit + res=$(git pull) + if echo "$res" | grep -q "Already up to date"; then + echo "Repo is up to date." + else + echo "Repo has updated" + fi + } + +if [ -d "$GIT_WORK_DIR" ]; then + check_for_updates +else + git clone "$BLOG_ENDPOINT" "$GIT_WORK_DIR" + if [ $? -eq 0 ]; then + check_for_updates + else + echo "Failed to clone the repo" + fi +fi