feat: Refactored universe service tests and added some for the resour… #2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Database migration tests | |
on: | |
push: | |
paths: | |
- ".github/workflows/database-migration-tests.yml" | |
- "database/**" | |
jobs: | |
# https://github.com/dorny/paths-filter | |
detect-code-changes: | |
runs-on: ubuntu-latest | |
outputs: | |
ci: ${{ steps.filter.outputs.ci }} | |
galactic-sovereign-db: ${{ steps.filter.outputs.galactic-sovereign-db }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: dorny/paths-filter@v3 | |
id: filter | |
with: | |
base: ${{ github.ref_name }} | |
filters: | | |
ci: | |
- '.github/workflows/database-migration-tests.yml' | |
galactic-sovereign-db: | |
- 'database/galactic-sovereign/**' | |
validate-galactic-sovereign-db: | |
runs-on: ubuntu-latest | |
needs: [detect-code-changes] | |
if: ${{ needs.detect-code-changes.outputs.galactic-sovereign-db == 'true' || needs.detect-code-changes.outputs.ci == 'true' }} | |
defaults: | |
run: | |
working-directory: ./database | |
services: | |
postgres: | |
image: postgres:15 | |
env: | |
POSTGRES_USER: postgres | |
POSTGRES_PASSWORD: postgres | |
POSTGRES_DB: postgres | |
ports: | |
- 5432:5432 | |
options: >- | |
--health-cmd pg_isready | |
--health-interval 10s | |
--health-timeout 5s | |
--health-retries 5 | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: "1.23.2" | |
- name: Install migrate tool | |
run: go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest | |
- name: Create user | |
run: | | |
psql \ | |
-v admin_password=$ADMIN_PASSWORD \ | |
-v manager_password=$MANAGER_PASSWORD \ | |
-v user_password=$USER_PASSWORD \ | |
postgresql://postgres@localhost \ | |
-f galactic-sovereign/db_user_create.sql | |
env: | |
PGPASSWORD: postgres | |
ADMIN_PASSWORD: admin_password | |
MANAGER_PASSWORD: manager_password | |
USER_PASSWORD: user_password | |
- name: Create database | |
run: | | |
psql postgresql://postgres@localhost -f galactic-sovereign/db_create.sql | |
env: | |
PGPASSWORD: postgres | |
- name: Migrate schema up | |
run: | | |
migrate \ | |
-path galactic-sovereign/migrations \ | |
-database postgresql://galactic_sovereign_admin@localhost/db_galactic_sovereign?sslmode=disable \ | |
up | |
env: | |
PGPASSWORD: admin_password | |
- name: Migrate schema down | |
run: | | |
migrate \ | |
-path galactic-sovereign/migrations \ | |
-database postgresql://galactic_sovereign_admin@localhost/db_galactic_sovereign?sslmode=disable \ | |
down -all | |
env: | |
PGPASSWORD: admin_password |