Skip to content

feat: enable label override for the display name of tables and refs#130

Merged
datnguye merged 6 commits intodatnguye:mainfrom
dsmdavid:feat/enable-label-in-table-and-refs
May 28, 2025
Merged

feat: enable label override for the display name of tables and refs#130
datnguye merged 6 commits intodatnguye:mainfrom
dsmdavid:feat/enable-label-in-table-and-refs

Conversation

@dsmdavid
Copy link
Contributor

@dsmdavid dsmdavid commented Mar 20, 2025

A potential approach to the discussion #129 to allow custom overrides. This approach uses the default values (fully qualified names for db objects, name of the columns for relationships) unless a label is specified in the meta option.
Currently only implemented for test_relationships, but not for the semantic model.

e.g. taking as input:

version 2:

models:

    - name: sample1
    - name: sample2
      columns:
        - name: date_column
          data_tests:
          - relationships:
              to: ref('sample1')
              field: date_column
              meta:
                relationship_type: many-to-one

by including the custom label value

    - name: sample1
+      meta:
+        label: alternative_sample_1

...

                relationship_type: many-to-one
+               relationship_label: preferred_relationship_name

to obtain a expanded properties file like:

version 2:

models:

    - name: sample1
      meta:
         label: alternative_sample_1    

    - name: sample2
      columns:
        - name: date_column
          data_tests:
          - relationships:
              to: ref('sample1')
              field: date_column
              meta:
                relationship_type: many-to-one
                relationship_label: preferred_relationship_name

Changes the output from:

erDiagram
 
 "MODEL.DVD_UTILS.SAMPLE1" {
   date date_column
 }
 "MODEL.DVD_UTILS.SAMPLE2" {
   date date_column
   date date_column_b
 }
 "MODEL.DVD_UTILS.SAMPLE2" }|--|| "MODEL.DVD_UTILS.SAMPLE1": date_column
Loading

to:

erDiagram
 
  "MODEL.DVD_UTILS.SAMPLE1"["ALTERNATIVE_SAMPLE_1"] {
    date date_column
  }
  "MODEL.DVD_UTILS.SAMPLE2" {
    date date_column
    date date_column_b
  }
  "MODEL.DVD_UTILS.SAMPLE2" }|--|| "MODEL.DVD_UTILS.SAMPLE1": preferred_relationship_name
Loading

@datnguye
Copy link
Owner

datnguye commented Mar 21, 2025

Thanks @dsmdavid for the PR, looks great! 🙌

Some observations on this PR:

  • Code linting: CI is failing because of this, could you help to fix it? Check out the setting-up-an-environment, run poe format, and commit the changes
  • Shall we rename from label to relationship_label?

TY

@dsmdavid
Copy link
Contributor Author

Thanks, I think I've fixed the format, what do you think of using dbterd_label?

@datnguye
Copy link
Owner

Thanks, I think I've fixed the format, what do you think of using dbterd_label?

I think let’s do relationship_label to be consistent for now. I guess you worry about the meta attributes’ name conflicts. We can consider to add these meta attributes nested in a parent attribute named dbterd later.

@datnguye
Copy link
Owner

Hey @dsmdavid just FYI and sorry for any inconveniences here since I just merged the PR to migrate the new Python package manager uv (together with some code quality refinements and so quite a lots of code refactoring).

In order to continue iteration on this PR, could you help to merge the latest code?

Feel free to let me know if you'd need any supports here.
Thank you so much!

@dsmdavid
Copy link
Contributor Author

Thanks, Dat. I merged the changes and will rename the 'label' to 'relationship_label' shortly

@codecov
Copy link

codecov bot commented May 27, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (9197c29) to head (dd5c9f9).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #130   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           31        31           
  Lines         1238      1244    +6     
=========================================
+ Hits          1238      1244    +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dsmdavid
Copy link
Contributor Author

I've modified the labels for the relationship to relationship_label, but have kept the labels for the models as label. I've updated the PR description

@datnguye
Copy link
Owner

datnguye commented May 28, 2025

I've modified the labels for the relationship to relationship_label, but have kept the labels for the models as label. I've updated the PR description

Thanks @dsmdavid Looks great to me!

Just to double check 1 thing before updating the docs about the Table Label: What would be the use case where the Label would be different from Model Name? Keen to hear so that we can update docs site accordingly

Created #132 for docs work

Cheers

@datnguye datnguye merged commit 6693b6e into datnguye:main May 28, 2025
15 checks passed
@datnguye
Copy link
Owner

This feat should be available in dbterd 1.20.0 🎉

@dsmdavid
Copy link
Contributor Author

dsmdavid commented May 28, 2025

Thanks, @datnguye!
re: the use of the table label --> I think the --entity-name-format is good, not sure I was aware when I started with this.
Even though, there may be cases to use an alias instead of the actual object name.
e.g. in the current project we use some not very user-friendly names like:

models:
    - name: <domain_name>_derived__rpt_<subdomain>_<table_name>_hist
       schema: <domain_name>_derived

with the options provided by -enf the name would still be something like axw_derived__rpt_ccd_customers_hist, but for the ERD I just want it to read customers as I'm not likely to build the ERD for the whole project and I'll be focused on the domain/subdomain of interest, i.e.

models:
    - name: axw_derived__rpt_ccd_customers_hist
      schema: axw_derived
      meta:
          label:  customers

@dsmdavid dsmdavid deleted the feat/enable-label-in-table-and-refs branch May 28, 2025 09:55
@datnguye
Copy link
Owner

FYI: the docs page is now available here: https://dbterd.datnguyen.de/latest/nav/metadata/label_override.html

Let me know if you'd have any time to review and feedback. Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants