Created
June 7, 2021 23:45
-
-
Save panasenco/31d4c12f0cadce91f576a818018970a0 to your computer and use it in GitHub Desktop.
Converts dbt manifest.json to PlantUML ERD diagram. It's not pretty but it's readable.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env pwsh | |
<# | |
.Synopsis | |
Creates a PlantUML ERD diagram from a manifest.json file. | |
.Parameter Path | |
Path to the manifest.json file. Defaults to .\target\manifest.json | |
#> | |
[CmdletBinding()] | |
param ( | |
[string] $Path = ".\target\manifest.json" | |
) | |
$ErrorActionPreference = "Stop" | |
function Sanitize-ColumnName { | |
param ( | |
[Parameter(Mandatory=$true, ValueFromPipeline=$true)] | |
[string] $ColumnName | |
) | |
process { | |
# Strip text in leading parentheses | |
$ColumnName -replace '^\s*\([^\)]*\)\s*' | |
} | |
} | |
"@startuml" | |
"hide circle" | |
"skinparam linetype ortho" | |
# "left to right direction" | |
$Manifest = Get-Content -Raw -Path $Path | ConvertFrom-Json | |
$Manifest.nodes.PSObject.Properties | where { $_.MemberType -eq 'NoteProperty' } | foreach { | |
$Value = $_.Value | |
switch -Regex ($_.Name) { | |
'model\..*' { | |
"entity `"$($Value.name)`" as $($Value.name) {" | |
$Value.columns.PSObject.Properties | foreach { | |
" $($_.Value.name | Sanitize-ColumnName) : $($_.Value.type)" | |
} | |
"}" | |
} | |
'test\.[^\.]+\.relationships_.*' { | |
$OutTable = $Value.refs[1] | |
$OutColumn = $Value.column_name | Sanitize-ColumnName | |
$InTable = $Value.refs[0] | |
$InColumn = ($Value.name -split '__')[-2] | |
"$OutTable::$OutColumn ---> $InTable::$InColumn" | |
} | |
} | |
} | |
"@enduml" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @panasenco - seems we're thinking on the same path. I have an interactive catalog for dbt under development, and one of my upcoming features is in this space - have you put thought into what a good looking solution to this could look like?
ciejer/tangata_local#6