Skip to content

Support Schema Filter For Model Generation #4194

@mneverov

Description

@mneverov

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions