Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ dotnet test src/UnitTests/UnitTests.csproj --configuration Release --no-build --

The build includes `KitchenPC.Core`, `KitchenPC.DB`, and the unit tests.

Database Schema Naming
====

The PostgreSQL persistence adapter uses `shoppingingredients` as the physical table name for the
ingredient catalog. This legacy name is retained for compatibility with the KitchenPC website.
Public domain types and provisioning data continue to use the simpler `Ingredient` and
`Ingredients` terminology; those names describe application data rather than database tables.

`DBContext.InitializeStore()` recreates the KitchenPC schema and deletes existing KitchenPC data.
Use it only with a new database or when replacing all existing data is intentional. See the
[KitchenPC Samples repository](https://github.com/KitchenPC/Samples) for a PostgreSQL initializer
and a small sample dataset.

Packages and Releases
====

Expand Down
4 changes: 2 additions & 2 deletions src/Core/NLP/IngredientNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ public IngredientNode Parent
public UnitType ConversionType
{
get { return (parent == null) ? convtype : parent.convtype; }
} //Default conversion type for this ingredient (from ShoppingIngredients)
} //Default conversion type for this ingredient (from the shoppingingredients table)

public Weight UnitWeight
{
get { return (parent == null) ? unitweight : parent.unitweight; }
} //How much a single unit weighs (from ShoppingIngredients)
} //How much a single unit weighs (from the shoppingingredients table)

public IngredientNode(
Guid id,
Expand Down
2 changes: 1 addition & 1 deletion src/DB/DatabaseExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public Ingredients[] Ingredients()
})
.ToArray();

logger.DebugFormat("Read {0} row(s) from Ingredients.", list.Count());
logger.DebugFormat("Read {0} row(s) from shoppingingredients.", list.Count());
return list;
}

Expand Down
2 changes: 1 addition & 1 deletion src/DB/DatabaseImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void Import(IEnumerable<Ingredients> data)
session.Save(dbRow, row.IngredientId);
}

logger.DebugFormat("Created {0} row(s) in Ingredients", d.Count());
logger.DebugFormat("Created {0} row(s) in shoppingingredients", d.Count());
transaction.Commit();
session.Flush();
}
Expand Down
4 changes: 2 additions & 2 deletions src/DB/Models/Ingredients.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class IngredientsMap : ClassMap<Ingredients>
{
public IngredientsMap()
{
Table("ShoppingIngredients");
Table("shoppingingredients");

Id(x => x.IngredientId).GeneratedBy.GuidComb().UnsavedValue(Guid.Empty);

Expand All @@ -53,7 +53,7 @@ public IngredientsMap()
.Not.Nullable()
.Length(200)
.Unique()
.Index("IDX_Ingredients_DisplayName");
.Index("idx_shoppingingredients_displayname");
Map(x => x.UsdaDesc).Length(200);

HasMany(x => x.Forms).KeyColumn("IngredientId");
Expand Down
6 changes: 3 additions & 3 deletions src/DB/Models/NlpDefaultPairings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ public class NlpDefaultPairings

public class NlpDefaultPairingsMap : ClassMap<NlpDefaultPairings>
{
// TODO: KitchenPC doesn't have this data in a normalized manner, so we use the shoppingingredientsfornlp view to create it on the fly
// Website could create a new adapter that can load this view, or the base adapter can be configurable so we can map to a certain view and columns
// This table stores the default weight, volume, and unit forms used by ingredient parsing.
// The original KitchenPC website populated the same shape through a database view.
public NlpDefaultPairingsMap()
{
Table("shoppingingredientsfornlp"); // TODO: Make this configurable and less KitchenPC database specific
Table("shoppingingredientsfornlp");
Id(x => x.DefaultPairingId, "DefaultPairingId")
.GeneratedBy.GuidComb()
.UnsavedValue(Guid.Empty);
Expand Down
33 changes: 33 additions & 0 deletions src/UnitTests/DatabaseMappings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Linq;
using FluentNHibernate.Cfg;
using KitchenPC.DB.Models;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace KitchenPC.UnitTests;

[TestClass]
public class DatabaseMappings
{
[TestMethod]
public void IngredientTablesUseCanonicalNames()
{
var configuration = Fluently
.Configure()
.Mappings(mappings =>
mappings.FluentMappings.Add<IngredientsMap>().Add<NlpDefaultPairingsMap>()
)
.BuildConfiguration();

var ingredientTable = configuration.GetClassMapping(typeof(Ingredients)).Table.Name;
var defaultPairingsTable = configuration
.GetClassMapping(typeof(NlpDefaultPairings))
.Table.Name;

Assert.AreEqual("shoppingingredients", ingredientTable);
Assert.AreEqual("shoppingingredientsfornlp", defaultPairingsTable);
Assert.IsFalse(
configuration.ClassMappings.Any(mapping => mapping.Table.Name == "ingredients"),
"No persistence model should map to the legacy ingredients table."
);
}
}
2 changes: 1 addition & 1 deletion src/UnitTests/TestIngredientLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public IEnumerable<IngredientNode> LoadSynonyms()
);

//Add in some test ingredients, but this will eventually come from a massive Synonyms database
//DB will first load ShoppingIngredients and create root nodes for all of those, with default form data, then will load IngredientSynonyms for all aliases
//DB will first load shoppingingredients and create root nodes for all of those, with default form data, then will load IngredientSynonyms for all aliases
//TODO: Maybe there is a way to have ingredient nodes contain a singular and plural description so we don't need aliases for all the singulars
IngredientNode[] ings =
{
Expand Down
2 changes: 2 additions & 0 deletions src/UnitTests/UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentNHibernate" Version="2.1.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="MSTest.TestAdapter" Version="3.0.2" />
<PackageReference Include="MSTest.TestFramework" Version="3.0.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Core\Core.csproj" />
<ProjectReference Include="..\DB\DB.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down