Skip to content

Commit

Permalink
Fixed issue where some foreign keys in User table are not valid and m…
Browse files Browse the repository at this point in the history
…ust be excluded
  • Loading branch information
jeffzmartin committed Jun 23, 2018
1 parent bd7fa48 commit 5f21d35
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions SalesforceSQLSchemaGenerator/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public Visibility SaveScriptVisibility {
}
}

private string[] AllowedNullableFieldNames = new string[] {
private string[] AllowedNonNullableFieldNames = new string[] {
"Id",
"CreatedById",
"CreatedDate",
Expand All @@ -101,7 +101,10 @@ public Visibility SaveScriptVisibility {
"Name",
"OwnerId"
};

private string[] DisallowedUserForeignKeys = new string[] {
"CreatedById",
"LastModifiedById",
};
public Thickness DefaultMargin { get; set; }
private Dictionary<string, string> GeneratedSqlScript = new Dictionary<string, string>();

Expand Down Expand Up @@ -442,11 +445,11 @@ public Dictionary<string,string> GenerateSqlScript() {
}
if ((f.referenceTo != null && f.referenceTo.Length == 1) || string.Equals(f.name, "id", StringComparison.InvariantCultureIgnoreCase)) {
sb.Append(" COLLATE SQL_Latin1_General_CP1_CS_AS");
if (f.referenceTo != null && f.referenceTo.Length == 1) {
if (f.referenceTo != null && f.referenceTo.Length == 1 && !(t.name.Equals("User", StringComparison.InvariantCultureIgnoreCase) && DisallowedUserForeignKeys.Contains(f.name, StringComparer.InvariantCultureIgnoreCase))) {
foreignKeys.Add(new ForeignKeyEntry(t.name, f.name, f.referenceTo[0], "Id")); //hardcode foreign key to id of ref table
}
}
if (!f.nillable && AllowedNullableFieldNames.Contains(f.name, StringComparer.InvariantCultureIgnoreCase)) {
if (!f.nillable && AllowedNonNullableFieldNames.Contains(f.name, StringComparer.InvariantCultureIgnoreCase)) {
sb.Append(" NOT NULL");
}
sb.AppendLine();
Expand Down

0 comments on commit 5f21d35

Please sign in to comment.