2

I am trying to generate database migrations using SQLC over Windows OS. According to the official documentation I need to run the Docker command (because it supports Postgres over Windows).

If I run docker run --rm -v "${pwd}:/src" -w /src kjconroy/sqlc generate from a CLI it works. But if I run make sqlc it displays an error:

docker run --rm -v ":/src" -w /src kjconroy/sqlc generate

error parsing configuration files. sqlc.yaml or sqlc.json: file does not exist

make: *** [Makefile:12: sqlc] Error 1

I have my folder structure like this:

  • app/
    • db/
      • migration/
      • query/
        • myquery.sql
      • sqlc/
    • sqlc.yaml
    • Makefile

My sqlc.yaml file has this:

version: "1"
packages:
    - name: "db"
      path: "./db/sqlc"
      queries: "./db/query"
      schema: "./db/migration/"
      engine: "postgresql"
      emit_json_tags: true
      emit_prepared_queries: false
      emit_interface: false
      emit_exact_table_names: false

And Makefile this:

sqlc:
    docker run --rm -v "${pwd}:/src" -w /src kjconroy/sqlc generate

.PHONY: sqlc

So, how to make it work from the Makefile? I am not getting the error here? Maybe the field mapping is wrong?

Maramal
  • 3,145
  • 9
  • 46
  • 90
  • 1
    I'd guess that `"${pwd}` is not evaluating to what you expect (either `make` is attempting to expand it, or its just not resolving to the `db` folder); [this](https://stackoverflow.com/q/71760845/11810946) might help. Please let us know which implementation of make you are using. – Brits Sep 13 '22 at 02:05
  • @Brits, thank you. `${CURDIR}` made the trick. Just answer that so I can mark it as the correct one. – Maramal Sep 13 '22 at 02:53

1 Answers1

2

The error sqlc.yaml or sqlc.json: file does not exist simply means that sqlc (running in a container) is not finding the sqlc.yaml file in /src. When starting the container you are mapping ${pwd} to /src so the issue is that ${pwd} is not evaluating to the app/db folder as you expect it to. This is could be due to either:

In your case (based on your comment) it's the former and changing ${pwd} to ${CURDIR} fixes the issue.

Brits
  • 14,829
  • 2
  • 18
  • 31