pgschema icon indicating copy to clipboard operation
pgschema copied to clipboard

Use of .pgschemaignore in github actions with pgschema install using Go vs AMD package

Open matthewswogger opened this issue 7 months ago • 1 comments

As I developed my projects github action workflow for using pgschema plan/apply I noticed with the go install it would not use the .pgschemaignore when running plan or apply. With the AMD package release it works as expected.

I first followed https://www.pgschema.com/workflow/gitops and https://github.com/pgplex/pgschema-github-actions-example when writing the github actions yml file; both of which use the go install methods.

My .pgschemaignore contains:

[views]
patterns = ["pg_stat_statements", "pg_stat_statements_info", "pg_stat_statements_reset"]

[functions]
patterns = ["pg_stat_statements_reset"]

The go install steps:

  steps:

    - name: Setup Go
      uses: actions/setup-go@v6
      with:
        go-version: "stable"
        cache: false

    - name: Install pgschema
      run: go install github.com/pgplex/pgschema@latest

The AMD install step:

  steps:

    - name: Install pgschema
      run: |
        echo "Downloading pgschema..."
        curl -LO https://github.com/pgplex/pgschema/releases/download/v1.9.0/pgschema_1.9.0_amd64.deb

        echo "Installing pgschema..."
        sudo dpkg -i pgschema_1.9.0_amd64.deb

And the complete yaml that works as expected and I'm currently using succesfully:

name: pgschema migration

on:
  push:
    branches:
      - main
    paths:
      - "database_schema/**"

permissions:
  contents: read

jobs:
  plan-apply:
    runs-on: ubuntu-latest
    environment: focused-rejoicing / production
    env:
      PGPASSWORD: ${{ secrets.PGPASSWORD }}
      PGHOST: ${{ secrets.PGHOST }}
      PGPORT: ${{ secrets.PGPORT }}
      PGDATABASE: ${{ secrets.PGDATABASE }}
      PGUSER: ${{ secrets.PGUSER }}

    steps:
      - name: Checkout code
        uses: actions/checkout@v6

      - name: Install pgschema
        run: |
          echo "Downloading pgschema..."
          curl -LO https://github.com/pgplex/pgschema/releases/download/v1.9.0/pgschema_1.9.0_amd64.deb

          echo "Installing pgschema..."
          sudo dpkg -i pgschema_1.9.0_amd64.deb

      - name: Generate migration plan
        run: |
          echo "Producing migration plan..."
          pgschema plan --schema public --file database_schema/main.sql --output-json plan.json --output-human stdout

      - name: Apply migration
        run: |
          echo "Applying migration plan..."
          pgschema apply --schema public --plan plan.json --auto-approve

Wanted to let you and others know that this issue exists (if you see something I did incorrectly and caused it let me know). For users it's a simple fix to switch to installing the AMD/ARM install if Go isn't working for you.

I'll finish with letting you know how awesome I think this tool is. Trying to define and migrate schemas using orm's (at least in python) is a really bad time. Being able to use the actual sql commands is both faster and clearer.

matthewswogger avatar Apr 28 '26 17:04 matthewswogger

Thanks for the detailed report (and the kind words 🙏)!

I dug into this, and I want to share what I found because the root cause is a little different from "go install vs the .deb package."

The install method can't actually change ignore behavior

.pgschemaignore is loaded from the current working directory via a relative path (cmd/util/ignoreloader.go), and nothing in pgschema ever changes directories. The loader code is also identical between v1.9.0 (the .deb you used) and v1.10.0 (what go install ...@latest resolves to — Go uses proper semver, so 1.10.0 > 1.9.0). The only change between those versions was an additive [indexes] section. So a binary built by go install and one from the .deb of the same code will behave identically for ignore.

That means the difference you saw almost certainly comes from the two workflows themselves, not the install method — most likely the working directory pgschema ran in (i.e. whether .pgschemaignore was actually present in the dir where plan/apply executed). You pasted the full YAML for the working (.deb) path but only the install step for the go path, so I can't compare them directly.

Could you share the complete go-install workflow YAML? That'll let me confirm.

The real bug this exposes

Here's the legitimate issue: when .pgschemaignore isn't found, pgschema returned nil silently — no log, no warning. So if you're in the wrong directory, your ignore patterns are quietly skipped and the plan looks "wrong" with zero diagnostic signal. That's exactly what makes this look like a mysterious install-method bug.

I've put up a fix so pgschema now logs (to stderr, at info level) when no ignore file is found, including the resolved path and CWD:

level=INFO msg="no ignore file found, no filtering applied" file=.pgschemaignore cwd=/path/where/it/ran

With that, a wrong-directory situation is immediately visible. PR incoming.

tianzhou avatar Jun 09 '26 10:06 tianzhou