Skip to content

Commit

Permalink
add unique symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikEJ committed Dec 21, 2023
1 parent 1ed0eb9 commit 67366fb
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/GUI/RevEng.Core.60/Mermaid/DatabaseModelToMermaid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,22 @@ public string CreateMermaid()

foreach (var foreignKey in table.ForeignKeys)
{
var relationship = "}o--||";
//TODO: detect 1:1, 1:n, n:n
if (foreignKey.Columns.Any(c => c.IsNullable))
var relationship = "}o--|";

var dependentIndexes = foreignKey.PrincipalTable.Indexes
.Where(i => i.Columns.SequenceEqual(foreignKey.PrincipalColumns));

if (dependentIndexes.Any(i => i.IsUnique))
{
relationship = "|o--|";
}

if (foreignKey.PrincipalColumns.Any(c => c.IsNullable))
{
relationship = "}o--o|";
relationship = "}o--o";
}

sb.AppendLine(CultureInfo.InvariantCulture, $" {formattedTableName} {relationship} {foreignKey.PrincipalTable.Name} : {foreignKey.Name}");
sb.AppendLine(CultureInfo.InvariantCulture, $" {formattedTableName} {relationship}| {foreignKey.PrincipalTable.Name} : {foreignKey.Name}");
}
}

Expand Down

0 comments on commit 67366fb

Please sign in to comment.