Skip to content

Commit d2aa5aa

Browse files
aaronburtleseantleonardayush3797
authored
Validate relationship field names in config as backing columns (#2175)
## Why make this change? Closes #2166 Related to #2139 ## What is this change? When we validate the relationship fields in the config, ie: source fields and target fields, we use the backing column names to validate against. Previously we were using aliases if one existed, but instead we will validate only against the actual names of the backing columns. So, for example, if someone had an alias for the column "id", so that it would display as "identifier" when using this alias, we would validate that the relationship defined with that field was defined in the config using the name "id", and would throw a validation error if the config instead used, "identifier." ## How was this tested? Current test suite passing, along with a regression test for DwSql, MsSql, MySql, and PostreSql. ## Sample Request(s) Please see this issue for details on samples to reproduce. #2166 --------- Co-authored-by: Sean Leonard <sean.leonard@microsoft.com> Co-authored-by: Ayush Agarwal <34566234+ayush3797@users.noreply.github.com>
1 parent 95c46d1 commit d2aa5aa

26 files changed

+313
-20
lines changed

config-generators/dwsql-commands.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ update Broker --config "dab-config.DwSql.json" --permissions "authenticated:crea
120120
update WebsiteUser --config "dab-config.DwSql.json" --permissions "authenticated:create,read,delete,update" --rest false --graphql "websiteUser:websiteUsers"
121121
update SupportedType --config "dab-config.DwSql.json" --map "id:typeid" --permissions "authenticated:create,read,delete,update"
122122
update Tree --config "dab-config.DwSql.json" --rest true --graphql false --permissions "authenticated:create,read,update,delete" --map "species:Scientific Name,region:United State's Region"
123-
update Shrub --config "dab-config.DwSql.json" --permissions "authenticated:create,read,update,delete" --map "species:fancyName"
123+
update Shrub --config "dab-config.DwSql.json" --permissions "authenticated:create,read,update,delete" --map "species:fancyName" --relationship fungus --cardinality one --target.entity Fungus --relationship.fields "species:habitat"
124124
update Fungus --config "dab-config.DwSql.json" --permissions "authenticated:create,read,update,delete" --map "spores:hazards" --rest true
125-
update Fungus --config "dab-config.DwSql.json" --permissions "policy_tester_01:read" --fields.include "*" --policy-database "@item.region ne 'northeast'"
125+
update Fungus --config "dab-config.DwSql.json" --permissions "policy_tester_01:read" --fields.include "*" --policy-database "@item.region ne 'northeast'" --relationship Shrub --cardinality one --target.entity Shrub --relationship.fields "habitat:species"
126126
update books_view_all --config "dab-config.DwSql.json" --permissions "authenticated:create,read,update,delete" --rest true --graphql true
127127
update books_view_with_mapping --config "dab-config.DwSql.json" --map "id:book_id"
128128
update series --config "dab-config.DwSql.json" --relationship comics --target.entity Comic --cardinality many --relationship.fields "id:series_id"

config-generators/mssql-commands.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@ update series --config "dab-config.MsSql.json" --relationship comics --target.en
147147
update stocks_price --config "dab-config.MsSql.json" --relationship Stock --target.entity Stock --cardinality one
148148
update Broker --config "dab-config.MsSql.json" --permissions "authenticated:create,update,read,delete" --graphql false
149149
update Tree --config "dab-config.MsSql.json" --rest true --graphql false --permissions "authenticated:create,read,update,delete" --map "species:Scientific Name,region:United State's Region"
150-
update Shrub --config "dab-config.MsSql.json" --permissions "authenticated:create,read,update,delete" --map "species:fancyName"
150+
update Shrub --config "dab-config.MsSql.json" --permissions "authenticated:create,read,update,delete" --map "species:fancyName" --relationship fungus --cardinality one --target.entity Fungus --relationship.fields "species:habitat"
151151
update Fungus --config "dab-config.MsSql.json" --permissions "authenticated:create,read,update,delete" --map "spores:hazards" --rest true
152-
update Fungus --config "dab-config.MsSql.json" --permissions "policy_tester_01:read" --fields.include "*" --policy-database "@item.region ne 'northeast'"
152+
update Fungus --config "dab-config.MsSql.json" --permissions "policy_tester_01:read" --fields.include "*" --policy-database "@item.region ne 'northeast'" --relationship Shrub --cardinality one --target.entity Shrub --relationship.fields "habitat:species"
153153
update books_view_all --config "dab-config.MsSql.json" --permissions "authenticated:create,read,update,delete" --rest true --graphql true
154154
update stocks_view_selected --config "dab-config.MsSql.json" --permissions "authenticated:create,read,update,delete"
155155
update books_publishers_view_composite --config "dab-config.MsSql.json" --permissions "authenticated:create,read,update,delete"

config-generators/mysql-commands.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ update Comic --config "dab-config.MySql.json" --permissions "authenticated:creat
108108
update series --config "dab-config.MySql.json" --relationship comics --target.entity Comic --cardinality many
109109
update Broker --config "dab-config.MySql.json" --permissions "authenticated:create,update,read,delete" --graphql false
110110
update Tree --config "dab-config.MySql.json" --rest true --graphql false --permissions "authenticated:create,read,update,delete" --map "species:Scientific Name,region:United State's Region"
111-
update Shrub --config "dab-config.MySql.json" --permissions "authenticated:create,read,update,delete" --map "species:fancyName"
111+
update Shrub --config "dab-config.MySql.json" --permissions "authenticated:create,read,update,delete" --map "species:fancyName" --relationship fungus --cardinality one --target.entity Fungus --relationship.fields "species:habitat"
112112
update Fungus --config "dab-config.MySql.json" --permissions "authenticated:create,read,update,delete" --map "spores:hazards" --rest true
113-
update Fungus --config "dab-config.MySql.json" --permissions "policy_tester_01:read" --fields.include "*" --policy-database "@item.region ne 'northeast'"
113+
update Fungus --config "dab-config.MySql.json" --permissions "policy_tester_01:read" --fields.include "*" --policy-database "@item.region ne 'northeast'" --relationship Shrub --cardinality one --target.entity Shrub --relationship.fields "habitat:species"
114114
update books_view_all --config "dab-config.MySql.json" --permissions "authenticated:create,read,update,delete" --rest true --graphql true
115115
update stocks_view_selected --config "dab-config.MySql.json" --permissions "authenticated:create,read,update,delete"
116116
update books_publishers_view_composite --config "dab-config.MySql.json" --permissions "authenticated:create,read,update,delete"

config-generators/postgresql-commands.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ update Comic --config "dab-config.PostgreSql.json" --permissions "authenticated:
112112
update series --config "dab-config.PostgreSql.json" --relationship comics --target.entity Comic --cardinality many
113113
update Broker --config "dab-config.PostgreSql.json" --permissions "authenticated:create,update,read,delete" --graphql false
114114
update Tree --config "dab-config.PostgreSql.json" --rest true --graphql false --permissions "authenticated:create,read,update,delete" --map "species:Scientific Name,region:United State's Region"
115-
update Shrub --config "dab-config.PostgreSql.json" --permissions "authenticated:create,read,update,delete" --map "species:fancyName"
115+
update Shrub --config "dab-config.PostgreSql.json" --permissions "authenticated:create,read,update,delete" --map "species:fancyName" --relationship fungus --cardinality one --target.entity Fungus --relationship.fields "species:habitat"
116116
update Fungus --config "dab-config.PostgreSql.json" --permissions "authenticated:create,read,update,delete" --map "spores:hazards" --rest true
117-
update Fungus --config "dab-config.PostgreSql.json" --permissions "policy_tester_01:read" --fields.include "*" --policy-database "@item.region ne 'northeast'"
117+
update Fungus --config "dab-config.PostgreSql.json" --permissions "policy_tester_01:read" --fields.include "*" --policy-database "@item.region ne 'northeast'" --relationship Shrub --cardinality one --target.entity Shrub --relationship.fields "habitat:species"
118118
update books_view_with_mapping --config "dab-config.PostgreSql.json" --map "id:book_id"
119119
update BookWebsitePlacement --config "dab-config.PostgreSql.json" --relationship books --target.entity Book --cardinality one
120120
update SupportedType --config "dab-config.PostgreSql.json" --map "id:typeid" --permissions "authenticated:create,read,delete,update"

src/Core/Configurations/RuntimeConfigValidator.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,9 +1078,9 @@ public void ValidateRelationshipsInConfig(RuntimeConfig runtimeConfig, IMetadata
10781078
/// works because C# is pass by reference for referenced class types.
10791079
/// </summary>
10801080
/// <param name="invalidColumns">List in which to aggregate the invalid fields.</param>
1081-
/// <param name="fields">List of the fields to check for existence in backing DB.</param>
1081+
/// <param name="fields">List of the backing fields to check for existence in backing DB.</param>
10821082
/// <param name="entityName">The name of the entity that we check for backing columns.</param>
1083-
/// <param name="sqlMetadataProvider">The sqlMetadataProvider used to lookup if the fields are valid columns in DB.</param>
1083+
/// <param name="sqlMetadataProvider">The sqlMetadataProvider used to lookup if the backing fields are valid columns in DB.</param>
10841084
private static void GetFieldsNotBackedByColumnsInDB(
10851085
List<string> invalidColumns,
10861086
string[] fields,
@@ -1090,7 +1090,9 @@ private static void GetFieldsNotBackedByColumnsInDB(
10901090
invalidColumns.Clear();
10911091
foreach (string field in fields)
10921092
{
1093-
if (!sqlMetadataProvider.TryGetBackingColumn(entityName, field, out _))
1093+
// We call this function because the keyset are the backing columns
1094+
// which is what want to validate.
1095+
if (!sqlMetadataProvider.TryGetExposedColumnName(entityName, field, out _))
10941096
{
10951097
invalidColumns.Add(field);
10961098
}

src/Service.Tests/DatabaseSchema-DwSql.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,9 @@ VALUES
342342
(7, 'Journal7', null, null);
343343
INSERT INTO aow(NoteNum, DetailAssessmentAndPlanning, WagingWar, StrategicAttack) VALUES (1, 'chapter one notes: ', 'chapter two notes: ', 'chapter three notes: ');
344344
INSERT INTO trees(treeId, species, region, height) VALUES (1, 'Tsuga terophylla', 'Pacific Northwest', '30m'), (2, 'Pseudotsuga menziesii', 'Pacific Northwest', '40m');
345+
INSERT INTO trees(treeId, species, region, height) VALUES (4, 'test', 'Pacific Northwest', '0m');
345346
INSERT INTO fungi(speciesid, region, habitat) VALUES (1, 'northeast', 'forest'), (2, 'southwest', 'sand');
347+
INSERT INTO fungi(speciesid, region, habitat) VALUES (3, 'northeast', 'test');
346348
INSERT INTO type_table(id, short_types, int_types, long_types,
347349
string_types, nvarchar_string_types,
348350
single_types, float_types, decimal_types,

src/Service.Tests/DatabaseSchema-MsSql.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,8 +600,11 @@ INSERT INTO stocks(categoryid, pieceid, categoryName) VALUES (1, 1, 'SciFi'), (2
600600
INSERT INTO stocks_price(categoryid, pieceid, price, is_wholesale_price) VALUES (2, 1, 100.57, 1), (1, 1, 42.75, 0), (100, 99, NULL, NULL);
601601
INSERT INTO stocks_price(categoryid, pieceid, instant, price, is_wholesale_price) VALUES (2, 1, '2023-08-21 15:11:04', 100.57, 1);
602602
INSERT INTO trees(treeId, species, region, height) VALUES (1, 'Tsuga terophylla', 'Pacific Northwest', '30m'), (2, 'Pseudotsuga menziesii', 'Pacific Northwest', '40m');
603+
INSERT INTO trees(treeId, species, region, height) VALUES (4, 'test', 'Pacific Northwest', '0m');
603604
INSERT INTO aow(NoteNum, DetailAssessmentAndPlanning, WagingWar, StrategicAttack) VALUES (1, 'chapter one notes: ', 'chapter two notes: ', 'chapter three notes: ');
604605
INSERT INTO fungi(speciesid, region, habitat) VALUES (1, 'northeast', 'forest'), (2, 'southwest', 'sand');
606+
INSERT INTO fungi(speciesid, region, habitat) VALUES (3, 'northeast', 'test');
607+
605608

606609
SET IDENTITY_INSERT authors_history ON
607610
INSERT INTO authors_history(id, first_name, middle_name, last_name, year_of_publish, books_published)

src/Service.Tests/DatabaseSchema-MySql.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,9 @@ INSERT INTO type_table(id, byte_types, short_types, int_types, long_types, strin
378378
(4, 255, 32767, 2147483647, 9223372036854775807, 'null', 3.4E38, 1.7E308, 2.929292E-14, true, '9999-12-31 23:59:59', 0xFFFFFFFF),
379379
(5, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
380380
INSERT INTO trees(treeId, species, region, height) VALUES (1, 'Tsuga terophylla', 'Pacific Northwest', '30m'), (2, 'Pseudotsuga menziesii', 'Pacific Northwest', '40m');
381+
INSERT INTO trees(treeId, species, region, height) VALUES (4, 'test', 'Pacific Northwest', '0m');
381382
INSERT INTO fungi(speciesid, region, habitat) VALUES (1, 'northeast', 'forest'), (2, 'southwest', 'sand');
383+
INSERT INTO fungi(speciesid, region, habitat) VALUES (3, 'northeast', 'test');
382384
INSERT INTO notebooks(id, notebookname, color, ownername) VALUES (1, 'Notebook1', 'red', 'Sean'), (2, 'Notebook2', 'green', 'Ani'), (3, 'Notebook3', 'blue', 'Jarupat'), (4, 'Notebook4', 'yellow', 'Aaron');
383385
INSERT INTO journals(id, journalname, color, ownername)
384386
VALUES

src/Service.Tests/DatabaseSchema-PostgreSql.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,9 @@ INSERT INTO type_table(id, short_types, int_types, long_types, string_types, sin
384384
(5, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
385385
INSERT INTO type_table(id, uuid_types) values(10, 'D1D021A8-47B4-4AE4-B718-98E89C41A161');
386386
INSERT INTO trees("treeId", species, region, height) VALUES (1, 'Tsuga terophylla', 'Pacific Northwest', '30m'), (2, 'Pseudotsuga menziesii', 'Pacific Northwest', '40m');
387+
INSERT INTO trees("treeId", species, region, height) VALUES (4, 'test', 'Pacific Northwest', '0m');
387388
INSERT INTO fungi(speciesid, region, habitat) VALUES (1, 'northeast', 'forest'), (2, 'southwest', 'sand');
389+
INSERT INTO fungi(speciesid, region, habitat) VALUES (3, 'northeast', 'test');
388390
INSERT INTO notebooks(id, noteBookName, color, ownerName) VALUES (1, 'Notebook1', 'red', 'Sean'), (2, 'Notebook2', 'green', 'Ani'), (3, 'Notebook3', 'blue', 'Jarupat'), (4, 'Notebook4', 'yellow', 'Aaron');
389391
INSERT INTO journals(id, journalname, color, ownername)
390392
VALUES

src/Service.Tests/Snapshots/ConfigurationTests.TestReadingRuntimeConfigForMsSql.verified.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,6 +1829,17 @@
18291829
],
18301830
Mappings: {
18311831
species: fancyName
1832+
},
1833+
Relationships: {
1834+
fungus: {
1835+
TargetEntity: Fungus,
1836+
SourceFields: [
1837+
species
1838+
],
1839+
TargetFields: [
1840+
habitat
1841+
]
1842+
}
18321843
}
18331844
}
18341845
},
@@ -1900,6 +1911,17 @@
19001911
],
19011912
Mappings: {
19021913
spores: hazards
1914+
},
1915+
Relationships: {
1916+
Shrub: {
1917+
TargetEntity: Shrub,
1918+
SourceFields: [
1919+
habitat
1920+
],
1921+
TargetFields: [
1922+
species
1923+
]
1924+
}
19031925
}
19041926
}
19051927
},

0 commit comments

Comments
 (0)