Adding 'Executing the migrations' subsection into README.md. Adding log messages on deploy.yml.
All checks were successful
Deploy Greenlight API / deploy (push) Successful in 55s

This commit is contained in:
Maxime Delporte
2025-10-31 12:05:53 +01:00
parent 80800b214c
commit 10ea699625
2 changed files with 26 additions and 1 deletions

View File

@@ -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 & \
"
"
echo "App deployed 🎆"

View File

@@ -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