Skip to content

Do not generate unused structs when using one migration for multiple repositories  #917

@brunoluiz

Description

@brunoluiz

To avoid big repo.Querier interfaces, we split our queries into multiple packages. As these repositories use the same database, it uses as well the same migrations.

Once sqlc generates the files, everything works fine but we end-up with duplicated and un-used structs. On the example below, we would have a struct Foo in both internal/repository/x and internal/repository/y, although only one of the repositories might use it.

It doesn't affect the code generated (it still works), but it might confuse developers when going through the code. Wouldn't it be better to have a flag to clean / not generate structs that are not used by that repository?

version: "1"
packages:
  - name: "x"
    emit_json_tags: true
    emit_interface: true
    path: "./internal/repository/x"
    queries: "./internal/repository/x/queries/"
    schema: "./internal/repository/migrations/"
  - name: "y"
    emit_json_tags: true
    emit_interface: true
    path: "./internal/repository/y"
    queries: "./internal/repository/y/queries/"
    schema: "./internal/repository/migrations/"
CREATE TABLE foo (
	id text NOT NULL,
	PRIMARY KEY (id)
);

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions