sqlc icon indicating copy to clipboard operation
sqlc copied to clipboard

Support Schema Filter For Model Generation

Open mneverov opened this issue 4 weeks ago • 0 comments

What do you want to change?

Consider the following sqlc config:

version: "2"
sql:
  - schema: "migrations/*.sql"
    queries:
    - "db/schema1-queries.sql"
    engine: "postgresql"
    gen:
      go:
        package: "schema1"
        out: "db/schema1"
        ...
  - schema: "migrations/*.sql"
    queries:
    - "db/schema2-queries.sql"
    engine: "postgresql"
    gen:
      go:
        package: "schmea2"
        out: "db/schema2"
        ...

migrations directory contains multiple files with DDL statements for both schemas. Also, when adding a new feature both schemas are modified, so one migration file contain changes for both schema1 and schema2. In this case sqlc generates two identical models files that contain all models for both schema1 and schema2.

It would be nice to be able to specify a sql schema such that only related models are generated, i.e.

version: "2"
sql:
  - schema: "migrations/*.sql"
    sql_schema: "schema1"     # <-----
    queries:
    - "db/schema1-queries.sql"
    engine: "postgresql"
    gen:
      go:
        package: "schema1"
        out: "db/schema1"
        ...

Existing Workaround: split migration files between schemas and indicate the related schema in file names like migrations/.*_schema1.sql. The problem with this approach is that features might span across multiple schemas and it significantly increases number of migration files.

What database engines need to be changed?

No response

What programming language backends need to be changed?

No response

mneverov avatar Nov 24 '25 10:11 mneverov