postgresql-action icon indicating copy to clipboard operation
postgresql-action copied to clipboard

Howto connect

Open ovaris opened this issue 5 years ago • 6 comments

Hi, I was just wondering what hostname should I use to connect postgresql db in github envirnoment?

ovaris avatar Dec 18 '19 08:12 ovaris

+1

elpapi42 avatar Dec 22 '19 18:12 elpapi42

it uses default port 5432 on localhost. You can change database by using keys below with:

          postgresql db: "bs_test"

shirshak55 avatar Jan 06 '20 03:01 shirshak55

I have below job syntax:

name: Ruby

on: [push]

jobs:
  unit_tests:
    name: 'Run unit tests'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Set up Ruby 2.6
        uses: actions/setup-ruby@v1
        with:
          ruby-version: 2.6.x
      - uses: harmon758/postgresql-action@v1
        with:
          postgresql version: '11'
          postgresql db: 'surveymaster_test'
      - name: Build and test with Rake
        if: success()
        working-directory: backend/ruby
        run: |
          gem install bundler
          bundle install --jobs 4 --retry 3
          bundle exec rspec ./spec

But it seems the postgresql connection is not found and my test fails.

An error occurred while loading ./spec/controllers/admin/sessions_controller_spec.rb.
Failure/Error: ActiveRecord::Migration.maintain_test_schema!

PG::ConnectionBad:
  could not connect to server: No such file or directory
  	Is the server running locally and accepting
  	connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
# ./spec/rails_helper.rb:29:in `<top (required)>'
# ./spec/controllers/admin/sessions_controller_spec.rb:3:in `require'
# ./spec/controllers/admin/sessions_controller_spec.rb:3:in `<top (required)>'

aruprakshit avatar Mar 10 '20 10:03 aruprakshit

@aruprakshit What does your connection string look like? I found I had to explicitly set a username/password in the job config when using a URL string:

database.yml

test:
  <<: *default
  url: postgres://test:password@localhost/test

my_action.yml

name: Run rspec tests

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Set up Ruby 2.6
      uses: actions/setup-ruby@v1
      with:
        ruby-version: 2.6.x
    - name: Set up PostgreSQL
      uses: Harmon758/[email protected]
      with:
        postgresql user: test
        postgresql password: password
    - name: Set up Redis
      uses: zhulik/[email protected]
    - name: Build app
      run: |
        gem install bundler
        bundle install --jobs 4 --retry 3
        bundle exec rails db:setup RAILS_ENV=test
    - name: Run specs
      run: |
        bundle exec rspec

jay-snee avatar Mar 10 '20 21:03 jay-snee

I'm using both user and password, and got this error:

error: password authentication failed for user "runner"
    at Connection.parseE (/home/runner/work/todo-app/todo-app/node_modules/pg/lib/connection.js:581:48)
    at Connection.parseMessage (/home/runner/work/todo-app/todo-app/node_modules/pg/lib/connection.js:380:19)
    at Socket.<anonymous> (/home/runner/work/todo-app/todo-app/node_modules/pg/lib/connection.js:116:22)
    at Socket.emit (events.js:196:13)
    at Socket.EventEmitter.emit (domain.js:471:20)
    at addChunk (_stream_readable.js:290:12)
    at readableAddChunk (_stream_readable.js:271:11)
    at Socket.Readable.push (_stream_readable.js:226:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:166:17) {
  name: 'error',
  length: 102,
  severity: 'FATAL',
  code: '28P01',
  detail: undefined,
  hint: undefined,
  position: undefined,
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  schema: undefined,
  table: undefined,
  column: undefined,
  dataType: undefined,
  constraint: undefined,
  file: 'auth.c',
  line: '336',
  routine: 'auth_failed'
}

Where is this runner user coming from? This is my workflow:

name: Development(Server)

on: 
  push:
    paths:
      - 'packages/server/**'
      - '.github/workflows/server-development.yml'
    branches-ignore:
      - master
      
jobs:
  build:
    name: Test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - uses: actions/setup-node@v1
        with:
          node-version: '12.0.0'
      - uses: harmon758/postgresql-action@v1
        with:
          postgresql version: '12.2'
          postgresql db: todo-test
          postgresql user: typeorm
          postgresql password: password
      - run: yarn install
      - run: yarn lint:server
      - run: yarn test:server

It fails in the yarn test:server when it tries to connect to the database

JeffersonCarvalh0 avatar May 04 '20 14:05 JeffersonCarvalh0

Nevermind, I've just solved it. The problem was being caused by by the the NODE_ENV variable not being properly set, so the database's url wasn't been properly built in my config file.

JeffersonCarvalh0 avatar May 07 '20 22:05 JeffersonCarvalh0