diff --git a/.github/workflows/docker-compose-test.yml b/.github/workflows/docker-compose-test.yml index 89af4f7..facddab 100644 --- a/.github/workflows/docker-compose-test.yml +++ b/.github/workflows/docker-compose-test.yml @@ -24,7 +24,7 @@ jobs: sudo chmod 0755 -R /usr/share/zsh/ # Work around a weird bug where zsh on ubuntu actions gives that diretory 0777 which makes zsh refuse to start sudo hostname ghaction-runner-hostname # Set a consistent hostname so we can run tests that depend on it docker compose -f backend/server/docker-compose.yml build - docker compose -f backend/server/docker-compose.yml up -d + HISHTORY_COMPOSE_TEST=1 docker compose -f backend/server/docker-compose.yml up -d export HISHTORY_SERVER=http://localhost go build ./hishtory install @@ -48,8 +48,12 @@ jobs: ! (./hishtory export | grep "ls -Slah /") # Assert that the entry is syncing properly ./hishtory status -v | grep 'Sync Status: Synced' + # And that we are properly using the self-hosted server + ./hishtory status -v | grep 'Sync Server: http://localhost' + # Show the full status output for debugging + ./hishtory status -v # - name: Setup tmate session - # if: ${{ failure() }} + # # if: ${{ failure() }} # uses: mxschmitt/action-tmate@v3 # with: # limit-access-to-actor: true \ No newline at end of file diff --git a/backend/server/docker-compose.yml b/backend/server/docker-compose.yml index de40343..4a9733a 100644 --- a/backend/server/docker-compose.yml +++ b/backend/server/docker-compose.yml @@ -41,6 +41,7 @@ services: delay: 3s environment: HISHTORY_POSTGRES_DB: postgresql://postgres:TODO_YOUR_POSTGRES_PASSWORD_HERE@postgres:5432/hishtory?sslmode=disable + HISHTORY_COMPOSE_TEST: $HISHTORY_COMPOSE_TEST ports: - 80:8080 volumes: diff --git a/backend/server/server.go b/backend/server/server.go index a2cee93..39d28b6 100644 --- a/backend/server/server.go +++ b/backend/server/server.go @@ -97,7 +97,19 @@ func OpenDB() (*database.DB, error) { } err = db.CreateIndices() if err != nil { - return nil, err + return nil, fmt.Errorf("failed to create indices: %w", err) + } + } + if os.Getenv("HISHTORY_COMPOSE_TEST") != "" { + // Run an extra round of migrations to test the migration code path to prevent issues like #241 + fmt.Println("AutoMigrating DB tables a second time for test coverage") + err := db.AddDatabaseTables() + if err != nil { + return nil, fmt.Errorf("failed to create underlying DB tables: %w", err) + } + err = db.CreateIndices() + if err != nil { + return nil, fmt.Errorf("failed to create indices: %w", err) } } return db, nil