This commit is contained in:
2018-10-08 20:07:38 +00:00
parent d58ede8fd3
commit 7df84c1ce8
9 changed files with 275 additions and 14 deletions

View File

@@ -404,13 +404,27 @@ namespace AyaNova
//TESTING
if (TESTING_REFRESH_DB)
{
AyaNova.Core.License.Fetch(apiServerState, dbContext, _log);
Util.Seeder.SeedDatabase(Util.Seeder.SeedLevel.HugeForLoadTest);
AyaNova.Core.License.Fetch(apiServerState, dbContext, _log);
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);
}
//Open up the server for visitors
apiServerState.SetOpen();

View File

@@ -37,7 +37,7 @@ namespace AyaNova.Biz
return new WidgetBiz(ct, 1, ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID, AuthorizationRoles.BizAdminFull);
}
////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
//EXISTS
internal async Task<bool> ExistsAsync(long id)
{
@@ -50,7 +50,7 @@ namespace AyaNova.Biz
{
//This is simple so nothing more here, but often will be copying to a different output object or some other ops
return await ct.Widget.SingleOrDefaultAsync(m => m.Id == fetchId);
}
}
////////////////////////////////////////////////////////////////////////////////////////////////
//CREATE
@@ -65,6 +65,9 @@ namespace AyaNova.Biz
Widget outObj = inObj;
outObj.OwnerId = UserId;
//Test get serial id visible id number from generator
outObj.Serial = ServerBootConfig.WIDGET_SERIAL.GetNext();
await ct.Widget.AddAsync(outObj);
await ct.SaveChangesAsync();
@@ -73,7 +76,7 @@ namespace AyaNova.Biz
//EVENT LOG
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);
@@ -94,6 +97,9 @@ namespace AyaNova.Biz
//do stuff with widget
Widget outObj = inObj;
outObj.OwnerId = UserId;
//Test get serial id visible id number from generator
outObj.Serial = ServerBootConfig.WIDGET_SERIAL.GetNext();
TempContext.Widget.Add(outObj);
TempContext.SaveChanges();
@@ -121,7 +127,7 @@ namespace AyaNova.Biz
if (ret != null)
{
//Log
EventLogProcessor.LogEventToDatabase(new Event(UserId, fetchId, BizType, AyaEvent.Retrieved), ct);
EventLogProcessor.LogEventToDatabase(new Event(UserId, fetchId, BizType, AyaEvent.Retrieved), ct);
}
return ret;
}
@@ -206,7 +212,7 @@ namespace AyaNova.Biz
{
//Replace the db object with the PUT object
CopyObject.Copy(inObj, dbObj, "Id");
CopyObject.Copy(inObj, dbObj, "Id,Serial");
//Set "original" value of concurrency token to input token
//this will allow EF to check it out
ct.Entry(dbObj).OriginalValues["ConcurrencyToken"] = inObj.ConcurrencyToken;
@@ -217,7 +223,7 @@ namespace AyaNova.Biz
//Log modification
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);
@@ -239,7 +245,7 @@ namespace AyaNova.Biz
//Log modification
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);

View File

@@ -16,6 +16,7 @@ namespace AyaNova.Models
[Required]
public long OwnerId { get; set; }
public string Name { get; set; }
public uint Serial { get; set; }
public decimal? DollarAmount { get; set; }
public bool? Active { get; set; }
public AuthorizationRoles Roles { get; set; }

View File

@@ -0,0 +1,26 @@
using System;
using System.Threading.Tasks;
namespace AyaNova.Util
{
public class AutoId
{
private readonly object valueLock = new object();
private uint currentValue; //postgre bigint
public AutoId(uint initialValue)
{
currentValue = initialValue;
}
public uint GetNext()
{
lock (valueLock)
{
currentValue += 1;
if (currentValue == 0)
currentValue += 1;
return currentValue;
}
}
}
}

View File

@@ -22,8 +22,8 @@ namespace AyaNova.Util
//!!!!WARNING: BE SURE TO UPDATE THE DbUtil::PrepareDatabaseForSeeding WHEN NEW TABLES ADDED!!!!
private const int DESIRED_SCHEMA_LEVEL = 9;
internal const long EXPECTED_COLUMN_COUNT = 99;
internal const long EXPECTED_INDEX_COUNT = 22;
internal const long EXPECTED_COLUMN_COUNT = 100;
internal const long EXPECTED_INDEX_COUNT = 23;
//!!!!WARNING: BE SURE TO UPDATE THE DbUtil::PrepareDatabaseForSeeding WHEN NEW TABLES ADDED!!!!
@@ -152,7 +152,7 @@ namespace AyaNova.Util
exec("CREATE TABLE alocaleitem (id BIGSERIAL PRIMARY KEY, localeid bigint not null REFERENCES alocale (id), key text not null, display text not null)");
//LOOKAT: this is for what exactly??
// exec("CREATE INDEX alocaleitem_localeid_key_idx ON alocaleitem (localeid,key)");
// exec("CREATE INDEX alocaleitem_localeid_key_idx ON alocaleitem (localeid,key)");
//This seems more appropriate
exec("CREATE INDEX alocaleitem_localeid_key_display_idx ON alocaleitem (localeid,key, display)");
@@ -201,9 +201,13 @@ namespace AyaNova.Util
//Add widget table
//id, text, longtext, boolean, currency,
exec("CREATE TABLE awidget (id BIGSERIAL PRIMARY KEY, ownerid bigint not null, name varchar(255) not null, " +
exec("CREATE TABLE awidget (id BIGSERIAL PRIMARY KEY, ownerid bigint not null, name varchar(255) not null, serial bigint not null," +
"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);");
//Compound index for name fetching
exec("CREATE UNIQUE INDEX awidget_name_id_idx ON awidget (id, name);");

View File

@@ -30,6 +30,10 @@ namespace AyaNova.Util
ApiServerState.ServerState wasServerState = apiServerState.GetState();
string wasReason = apiServerState.Reason;
//START SERIAL NUMBER GENERATORS
if (ServerBootConfig.WIDGET_SERIAL == null)
ServerBootConfig.WIDGET_SERIAL = new AutoId(0);
try
{
log.LogInformation("SEEDER: Seed data level - " + slevel.ToString());

View File

@@ -12,6 +12,10 @@ namespace AyaNova.Util
internal static class ServerBootConfig
{
//TEST AUTOID
//Get the highest id number issued previously and start the auto-id at that level
internal static AutoId WIDGET_SERIAL { get; set; }
//Diagnostic static values used during development, may not be related to config at all, this is just a convenient class to put them in
#if (DEBUG)