-
Notifications
You must be signed in to change notification settings - Fork 0
pocketbase justfile (javascript)
Min Choro edited this page Dec 10, 2025
·
2 revisions
아래 justfile을 붙혀넣으면 pocketbase 세팅을 빠르게 할 수 있습니다
# 최신 pb 릴리즈를 가져옵니다
PB_VERSION := `curl -sI https://github.com/pocketbase/pocketbase/releases/latest \
| grep -i '^location:' \
| awk -F'/tag/v' '{print $2}' \
| tr -d '\r'`
# 또는 특정 버전을 지정 할 수 있습니다
# PB_VERSION := "0.34.0"
# just migrate 후 pb_migrations/.backup 디렉토리에 이전 마이그레이션 백업본을 저장할지 여부를 설정합니다
STORE_MIGRATIONS_BACKUP := "true"
PB_HOST := "https://github.com/pocketbase/pocketbase/releases/download"
# 크로스 플랫폼 OS 감지
OS := if os() == "windows" { "windows" } else { `uname -s | tr '[:upper:]' '[:lower:]'` }
# 크로스 플랫폼 아키텍처 감지
ARCH := if os() == "windows" {
if arch() == "x86_64" { "amd64" } else { arch() }
} else {
if `uname -m` == "x86_64" { "amd64" } else { `uname -m` }
}
PB_DOWNLOAD_URL := PB_HOST + "/v" + PB_VERSION + "/pocketbase_" + PB_VERSION + "_" + OS + "_" + ARCH + ".zip"
[private]
@default:
just --list
# 실행 환경에 맞는 pocketbase 서버를 다운로드합니다.
init:
@echo "PocketBase Version: {{PB_VERSION}}"
@echo "Downloading PocketBase from: {{PB_DOWNLOAD_URL}}"
@echo "Platform: {{OS}}_{{ARCH}}"
@curl -L "{{PB_DOWNLOAD_URL}}" -o ./pocketbase.zip
@unzip -o ./pocketbase.zip -d ./pocketbase_zip
@rm -f ./pocketbase.zip
@if [ "{{OS}}" = "windows" ]; then \
mv ./pocketbase_zip/pocketbase.exe ./pocketbase.exe; \
else \
mv ./pocketbase_zip/pocketbase ./pocketbase; \
chmod +x ./pocketbase; \
fi
@rm -rf ./pocketbase_zip
@echo "PocketBase {{PB_VERSION}} downloaded successfully!"
# pocketbase 서버를 실행합니다
serve *args:
@if [ "{{OS}}" = "windows" ]; then \
./pocketbase.exe serve --dev {{args}}; \
else \
./pocketbase serve --dev {{args}}; \
fi
# pocketbase database를 migrate하고 마지막 migration 파일을 제외한 모든 파일을 삭제합니다. 복구를 위해 local 환경에서 접근 할 수 있는 백업본은 pb_migrations/.backup 디렉토리에 저장합니다
migrate:
@echo "Running migration..."
@if [ "{{STORE_MIGRATIONS_BACKUP}}" = "true" ]; then \
echo "Storing backup of existing migrations..." && \
mkdir -p ./pb_migrations/.backup && \
cp -r ./pb_migrations/* ./pb_migrations/.backup/ 2>/dev/null || true; \
fi
@output=$(yes | ./pocketbase migrate collections) && \
echo "$output" && \
filepath=$(echo "$output" | grep -oE 'pb_migrations/[0-9]+_collections_snapshot\.js') && \
filename=$(basename "$filepath") && \
find ./pb_migrations -type f ! -name "$filename" ! -name "*_init.js" ! -path "./pb_migrations/.backup/*" -delete && \
echo "Cleaned up old migrations, keeping only $filename and *_init.js files (backup saved in ./pb_migrations/.backup)"PocketBase 최신 릴리즈를 찾아서 실행 가능한 바이너리를 다운로드 합니다.
PB_VERSION 변수를 직접 설정해서 특정 버전을 사용 할 수도 있습니다
pb 서버를 실행합니다. just serve --http=0.0.0.0:8091과 같이 옵션도 지정 가능합니다.
pocketbase migration을 실행해 snapshot 파일을 남기고 이전 파일을 삭제합니다.
이전 마이그레이션 파일은 pb_migrations/.backup 디렉토리로 이동되고, 만약 STORE_MIGRATIONS_BACKUP이 "true"가 아니라면 삭제됩니다