This commit is contained in:
2018-10-09 15:05:26 +00:00
parent 7f03a019d7
commit 2f5d2a8d26
6 changed files with 46 additions and 29 deletions

View File

@@ -28,8 +28,7 @@ Once that is done then can steam ahead on the biz objects but until I have the c
IMMEDIATE ITEMS:
================
- Auto visible id number assigning code
- Give widgets a visible ID number scheme and add to tests
- Auto visible id number assigning code
- Ensure search code process keywords includes the Visible ID value andadd test for that in Search indexing tests
- Remove validation index from awidget table that was only for testing uniqueness of serial field

View File

@@ -363,7 +363,7 @@ namespace AyaNova
// ******************** TESTING WIPE DB *****************************
//
//Set this to true to wipe the db and reinstall a trial license and re-seed the data
var TESTING_REFRESH_DB = false;
var TESTING_REFRESH_DB = true;
#if (DEBUG)
//TESTING
@@ -372,8 +372,6 @@ namespace AyaNova
#endif
if (ServerBootConfig.AYANOVA_PERMANENTLY_ERASE_DATABASE)
{
_log.LogWarning("BOOT: AYANOVA_PERMANENTLY_ERASE_DATABASE is true, dropping and recreating database");
@@ -389,8 +387,6 @@ namespace AyaNova
_log.LogDebug("BOOT: db integrity check");
DbUtil.CheckFingerPrint(AySchema.EXPECTED_COLUMN_COUNT, AySchema.EXPECTED_INDEX_COUNT, _log);
//Initialize license
AyaNova.Core.License.Initialize(apiServerState, dbContext, _log);
@@ -405,25 +401,14 @@ namespace AyaNova
if (TESTING_REFRESH_DB)
{
AyaNova.Core.License.Fetch(apiServerState, dbContext, _log);
Util.Seeder.SeedDatabase(Util.Seeder.SeedLevel.HugeForLoadTest);
Util.Seeder.SeedDatabase(Util.Seeder.SeedLevel.SmallOneManShopTrialDataSet);
}
//TESTING
#endif
//TEST AUTOID
//Note that seeder may init this already in which case this code doesn't even need to run
if (ServerBootConfig.WIDGET_SERIAL == null)
{
//query for most recently used serial number
//(note, can't query for highest serial as it can and likely will reset or be changed manually from time to time
// so the algorithm is to keep the most recent sequence going on startup of the server)
var MostRecentWidget = dbContext.Widget.AsNoTracking().OrderByDescending(x => x.Id).FirstOrDefault();
uint MaxWidgetId = 0;
if (MostRecentWidget != null)
MaxWidgetId = MostRecentWidget.Serial;
ServerBootConfig.WIDGET_SERIAL = new AutoId(MaxWidgetId);
}
//Set autoId values
ServerBootConfig.SetMostRecentAutoIdValuesFromDatabase(dbContext);
//Open up the server for visitors
apiServerState.SetOpen();

View File

@@ -43,6 +43,12 @@ namespace AyaNova.Biz
IsValid = false;
}
if (objectPatch.Operations.Any(m => m.path == "/serial"))
{
biz.AddError(ValidationErrorType.NotChangeable, "Serial");
IsValid = false;
}
if (objectPatch.Operations.Any(m => m.op == "add"))
{
biz.AddError(ValidationErrorType.InvalidOperation, "add");

View File

@@ -78,7 +78,7 @@ namespace AyaNova.Biz
EventLogProcessor.LogEventToDatabase(new Event(UserId, outObj.Id, BizType, AyaEvent.Created), ct);
//SEARCH INDEXING
Search.ProcessNewObjectKeywords(ct, UserLocaleId, outObj.Id, BizType, outObj.Name, outObj.Notes, outObj.Name);
Search.ProcessNewObjectKeywords(ct, UserLocaleId, outObj.Id, BizType, outObj.Name, outObj.Notes, outObj.Name, outObj.Serial.ToString());
return outObj;
@@ -109,7 +109,7 @@ namespace AyaNova.Biz
EventLogProcessor.LogEventToDatabase(new Event(UserId, outObj.Id, BizType, AyaEvent.Created), TempContext);
//SEARCH INDEXING
Search.ProcessNewObjectKeywords(TempContext, UserLocaleId, outObj.Id, BizType, outObj.Name, outObj.Notes, outObj.Name);
Search.ProcessNewObjectKeywords(TempContext, UserLocaleId, outObj.Id, BizType, outObj.Name, outObj.Notes, outObj.Name, outObj.Serial.ToString());
return outObj;
@@ -225,7 +225,7 @@ namespace AyaNova.Biz
EventLogProcessor.LogEventToDatabase(new Event(UserId, dbObj.Id, BizType, AyaEvent.Modified), ct);
//Update keywords
Search.ProcessUpdatedObjectKeywords(ct, UserLocaleId, dbObj.Id, BizType, dbObj.Name, dbObj.Notes, dbObj.Name);
Search.ProcessUpdatedObjectKeywords(ct, UserLocaleId, dbObj.Id, BizType, dbObj.Name, dbObj.Notes, dbObj.Name, dbObj.Serial.ToString());
return true;
}
@@ -234,6 +234,7 @@ namespace AyaNova.Biz
internal bool Patch(Widget dbObj, JsonPatchDocument<Widget> objectPatch, uint concurrencyToken)
{
//Validate Patch is allowed
//Note: Id, OwnerId and Serial are all checked for and disallowed in the validate code by default
if (!ValidateJsonPatch<Widget>.Validate(this, objectPatch)) return false;
//Do the patching
@@ -247,7 +248,7 @@ namespace AyaNova.Biz
EventLogProcessor.LogEventToDatabase(new Event(UserId, dbObj.Id, BizType, AyaEvent.Modified), ct);
//Update keywords
Search.ProcessUpdatedObjectKeywords(ct, UserLocaleId, dbObj.Id, BizType, dbObj.Name, dbObj.Notes, dbObj.Name);
Search.ProcessUpdatedObjectKeywords(ct, UserLocaleId, dbObj.Id, BizType, dbObj.Name, dbObj.Notes, dbObj.Name, dbObj.Serial.ToString());
return true;
}

View File

@@ -23,7 +23,7 @@ namespace AyaNova.Util
private const int DESIRED_SCHEMA_LEVEL = 9;
internal const long EXPECTED_COLUMN_COUNT = 100;
internal const long EXPECTED_INDEX_COUNT = 23;
internal const long EXPECTED_INDEX_COUNT = 22;
//!!!!WARNING: BE SURE TO UPDATE THE DbUtil::PrepareDatabaseForSeeding WHEN NEW TABLES ADDED!!!!
@@ -205,7 +205,7 @@ namespace AyaNova.Util
"startdate timestamp, enddate timestamp, dollaramount decimal(19,5), active bool, roles int4, notes text)");
//TEST TEST TEST ONLY FOR DEVELOPMENT TESTING TO ENSURE UNIQUENESS
exec("CREATE UNIQUE INDEX awidget_serial_idx ON awidget (serial);");
//exec("CREATE UNIQUE INDEX awidget_serial_idx ON awidget (serial);");
//Compound index for name fetching

View File

@@ -2,6 +2,8 @@ using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.Extensions.Configuration;
using Microsoft.EntityFrameworkCore;
using System.Linq;
namespace AyaNova.Util
{
@@ -12,7 +14,8 @@ namespace AyaNova.Util
internal static class ServerBootConfig
{
//TEST AUTOID
//AUTOID's
//Get the highest id number issued previously and start the auto-id at that level
internal static AutoId WIDGET_SERIAL { get; set; }
@@ -202,6 +205,29 @@ namespace AyaNova.Util
}
}
//Get the auto-id most recent values at boot time
internal static void SetMostRecentAutoIdValuesFromDatabase(AyaNova.Models.AyContext ct)
{
//WIDGET SERIALS
if (WIDGET_SERIAL == null)
{
//query for most recently used serial number
//(note, can't query for highest serial as it can and likely will reset or be changed manually from time to time
// so the algorithm is to keep the most recent sequence going on startup of the server)
var MostRecentWidget = ct.Widget.AsNoTracking().OrderByDescending(x => x.Id).FirstOrDefault();
uint MaxWidgetId = 0;
if (MostRecentWidget != null)
MaxWidgetId = MostRecentWidget.Serial;
WIDGET_SERIAL = new AutoId(MaxWidgetId);
}
//OTHER SERIALS HERE IN FUTURE...
}
}//eoc