Skip to content

er.showColumnTypes.related/primary are ignored If include is set and number of result tables are less than input schema #685

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
shellyln opened this issue Apr 21, 2025 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@shellyln
Copy link

What happened

When filtering tables in the input schema with include in .tbls.yml, the er.showColumnTypes.related/primary setting to hide columns other than PK and FK in the ER diagram output no longer works.
When I wrote all tables in the input schema in the include (even with wildcards), the problem did not occur.

What you expected to happened

I expect that even if include is set, columns other than PK and FK will be hidden in the same way as if it were not set.

What stack trace or error message from tbls did you see?

Anything else we need to know?

Environment

  • tbls version
    • 1.85.0
  • Database version
    • json DSN
  • OS ( Ubuntu bionic, macOS Calalina, WSL2, etc )
    • Windows 11
  • Shell ( bash, zsh, poworshell, etc )
    • poworshell
  • Stacktrace or error message from tbls ( If you can, set DEBUG=1)
  • Config ( .tbls.yml )
# .tbls.yml
dsn: json://schema.json

docPath: doc/schema

format:
  # Adjust the column width of Markdown format table
  # Default is false
  adjust: false
  # Sort the order of table list and columns
  # Default is false
  sort: true
  # Display sequential numbers in table rows
  # Default is false
  number: false
  # The comments for each table in the Tables section of the index page will display the text up to the first double newline (first paragraph).
  # Default is false
  showOnlyFirstParagraph: false
  # Hide table columns without values
  # Default is false
  hideColumnsWithoutValues: false
  # It can be boolean or array
  # hideColumnsWithoutValues: ["Parents", "Children"]

er:
  # Skip generation of ER diagram
  # Default is false
  skip: false
  # ER diagram image format (`png`, `jpg`, `svg`, `mermaid`)
  # Default is `svg`
  format: mermaid
  # Add table/column comment to ER diagram
  # Default is false
  comment: false
  # Hide relation definition from ER diagram
  # Default is false
  hideDef: false
  # Show column settings in ER diagram. If this section is not set, all columns will be displayed (default).
  showColumnTypes:
    # Show related columns
    related: true
    # Show primary key columns
    primary: true
  # Distance between tables that display relations in the ER
  # Default is 1
  distance: 2
  # ER diagram (png/jpg) font (font name, font file, font path or keyword)
  # Default is "" (system default)
  font:

include:
  - Account
  - Contact

schema.json

{
    "tables": [
        {
            "name": "Account",
            "type": "Standard object",
            "columns": [
                {
                    "name": "Id",
                    "type": "Id",
                    "nullable": false,
                    "comment": "Id"
                },
                {
                    "name": "Foo",
                    "type": "Text",
                    "nullable": false,
                    "comment": "Foo"
                }
            ]
        },
        {
            "name": "Product2",
            "type": "Standard object",
            "columns": [
                {
                    "name": "Id",
                    "def": "Primary Key",
                    "table": "Product2",
                    "columns": [
                        "Id"
                    ]
                }
            ]
        },
        {
            "name": "Contact",
            "type": "Standard object",
            "columns": [
                {
                    "name": "Id",
                    "type": "Id",
                    "nullable": false,
                    "comment": "Id"
                },
                {
                    "name": "Bar",
                    "type": "Text",
                    "nullable": false,
                    "comment": "Bar"
                }
            ]
        }
    ],
    "driver": {
        "name": "",
        "database_version": ""
    }
}

memo

Isn't len(cc.ChildRelations) > 0 || len(cc.ParentRelations) > 0 correct?

tbls/config/config.go

Lines 594 to 605 in adffc63

func (c *Config) detectShowColumnsForER(s *schema.Schema) error {
if c.ER.ShowColumnTypes == nil {
return nil
}
if !c.ER.ShowColumnTypes.Related && !c.ER.ShowColumnTypes.Primary {
return errors.New("er.showColumnTypes: must be true at least one")
}
for _, t := range s.Tables {
for _, cc := range t.Columns {
if c.ER.ShowColumnTypes.Related && (cc.ChildRelations != nil || cc.ParentRelations != nil) {

tbls/schema/filter.go

Lines 110 to 125 in adffc63

func excludeTableFromSchema(name string, s *Schema) error {
// Tables
tables := []*Table{}
for _, t := range s.Tables {
if t.Name != name {
tables = append(tables, t)
}
for _, c := range t.Columns {
// ChildRelations
childRelations := []*Relation{}
for _, r := range c.ChildRelations {
if r.Table.Name != name && r.ParentTable.Name != name {
childRelations = append(childRelations, r)
}
}
c.ChildRelations = childRelations

@shellyln shellyln added the bug Something isn't working label Apr 21, 2025
@k1LoW
Copy link
Owner

k1LoW commented Apr 21, 2025

@shellyln Thank you for your contribution!

I'll check it.

@k1LoW k1LoW self-assigned this Apr 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants