From 10ea6996259375faaa71cbe931597612828e8407 Mon Sep 17 00:00:00 2001 From: Maxime Delporte Date: Fri, 31 Oct 2025 12:05:53 +0100 Subject: [PATCH] Adding 'Executing the migrations' subsection into README.md. Adding log messages on deploy.yml. --- .gitea/workflows/deploy.yml | 10 +++++++++- README.md | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index 16c43e2..36d9bc5 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -25,10 +25,12 @@ jobs: - name: Add host key to known_hosts run: | + echo "Creating access 🔐" mkdir -p ~/.ssh echo "${{ secrets.RUNNER_SSH_KEY }}" > ~/.ssh/id_rsa chmod 600 ~/.ssh/id_rsa ssh-keyscan -p ${{ secrets.SERVER_PORT }} -H ${{ secrets.SERVER_IP }} >> ~/.ssh/known_hosts + echo "Access created ✅" - name: Applying database migrations run: | @@ -51,17 +53,23 @@ jobs: - name: Build API run: | + echo "Building API ⚙️" go mod tidy go build -o ./bin/greenlight-api ./cmd/api + echo "Build created ✅" - name: Deploy to server run: | + echo "Deployment ongoing 🔥" ssh -p ${{ secrets.SERVER_PORT }} ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_IP }} "rm -rf /var/www/greenlight/*" rsync -avz --delete -e "ssh -p ${{ secrets.SERVER_PORT }}" bin/ ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_IP }}:/var/www/greenlight + echo "App deployed ✅" - name: Launch API run: | + echo "Launching API 🚀" ssh -p ${{ secrets.SERVER_PORT }} ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_IP }} "\ pkill greenlight-api || true; \ nohup /var/www/greenlight/greenlight-api > /var/www/greenlight/greenlight.log 2>&1 & \ - " \ No newline at end of file + " + echo "App deployed 🎆" \ No newline at end of file diff --git a/README.md b/README.md index 496f591..e9e359b 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,23 @@ In this command: - The **-dir** flag indicates that we want to store the migration files in the **./migrations** directory (which will be created automatically if it doesn't already exist). - The name **create_movies_table** is a descriptive label that we give the migration files to signify their contents. +### Executing the migrations + +```bash +migrate -path=./migrations -database=$GREENLIGHT_DB_DSN up +``` +Note: You may get the error: **error: pq: permission denied for schema public...** when running this command. It's because Postgres might revoke the **CREATE** permission from all users except a database ownser. + +To get around this, set the database owner to the **greenlight** user: +```sql +ALTER DATABASE greenlight OWNER TO greelight; +``` + +If that still doesn't work, try explicitly granting the **CREATE** privileges to the **greenlight** user: +```sql +GRANT CREATE ON DATABASE greenlight TO greelight; +``` + ## Additional Information ### How different Go Types are encoded