case 4221
This commit is contained in:
@@ -42,7 +42,7 @@ namespace AyaNova.Api.Controllers
|
||||
|
||||
/// <summary>
|
||||
/// Seed a trial database with sample data.
|
||||
///
|
||||
/// NOTE: the database must be erased prior to seeding
|
||||
/// You can control the size and scope of the seeded data with the passed in size value
|
||||
/// "Small" - a small one man shop dataset
|
||||
/// "Medium" - Local service company with multiple employees and departments dataset
|
||||
@@ -71,6 +71,13 @@ namespace AyaNova.Api.Controllers
|
||||
return BadRequest(new ApiErrorResponse(ApiErrorCode.INVALID_OPERATION, null, "Current license is not a trial license key. Only a trial can be seeded."));
|
||||
}
|
||||
|
||||
//if db not empty then can't seed
|
||||
if (!await DbUtil.DBIsEmptyAsync(ct, log))
|
||||
{
|
||||
return BadRequest(new ApiErrorResponse(ApiErrorCode.INVALID_OPERATION, null, "Current database is not empty. Only an empty database can be seeded."));
|
||||
}
|
||||
|
||||
|
||||
Seeder.Level.SeedLevel seedLevel = Seeder.Level.StringToSeedLevel(seedOptions.SeedLevel);
|
||||
if (seedLevel == Seeder.Level.SeedLevel.NotValid)
|
||||
return BadRequest(new ApiErrorResponse(ApiErrorCode.NOT_FOUND, "size", "Valid values are \"small\", \"medium\", \"large\", \"huge\""));
|
||||
|
||||
@@ -405,6 +405,9 @@ namespace AyaNova.Util
|
||||
//- select the superuser account back to the auser and useroptions
|
||||
//- discover where else this needs to be done
|
||||
//- $profit
|
||||
|
||||
|
||||
|
||||
bool forSeeding = jobIdToKeep != Guid.Empty;
|
||||
|
||||
_log.LogInformation("Erasing Database \"{0}\"", _dbName);
|
||||
@@ -477,6 +480,9 @@ namespace AyaNova.Util
|
||||
//alogo
|
||||
//areport
|
||||
|
||||
//TAX CODES are an edge case where they are generated by the seeder potentially so need to be erased in that case or migrate but might be kept when manually erasing from UI.
|
||||
|
||||
|
||||
//await EraseTableAsync("aopsjoblog", conn, true);
|
||||
// await EraseTableAsync("aopsjob", conn, true);
|
||||
|
||||
|
||||
@@ -62,10 +62,10 @@ namespace AyaNova.Util
|
||||
//Seed database for trial and testing purposes
|
||||
//
|
||||
|
||||
public async Task SeedDatabaseAsync(Level.SeedLevel slevel, Decimal timeZoneOffset, string forceEmail, string appendPassword, bool e2e = false)
|
||||
{
|
||||
await SeedDatabaseAsync(slevel, Guid.Empty, timeZoneOffset, forceEmail, appendPassword, e2e);
|
||||
}
|
||||
// public async Task SeedDatabaseAsync(Level.SeedLevel slevel, Decimal timeZoneOffset, string forceEmail, string appendPassword, bool e2e = false)
|
||||
// {
|
||||
// await SeedDatabaseAsync(slevel, Guid.Empty, timeZoneOffset, forceEmail, appendPassword, e2e);
|
||||
// }
|
||||
|
||||
public async Task SeedDatabaseAsync(Level.SeedLevel slevel, Guid JobId, Decimal timeZoneOffset, string forceEmail, string appendPassword, bool e2e = false)
|
||||
{
|
||||
@@ -93,6 +93,17 @@ namespace AyaNova.Util
|
||||
throw new System.NotSupportedException(msg);
|
||||
}
|
||||
|
||||
//Only empty db can be seeded
|
||||
using (AyContext ct = ServiceProviderProvider.DBContext)
|
||||
{
|
||||
if (!await DbUtil.DBIsEmptyAsync(ct, log))
|
||||
{
|
||||
var msg = $"Current database is not empty. Only an empty database can be seeded.";
|
||||
await LogStatusAsync(JobId, LogJob, log, msg);
|
||||
throw new System.NotSupportedException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
//validate timezone offset
|
||||
if (timeZoneOffset > 14 || timeZoneOffset < (-12))
|
||||
{
|
||||
@@ -106,12 +117,14 @@ namespace AyaNova.Util
|
||||
apiServerState.SetOpsOnly("Seeding database");
|
||||
ServerBootConfig.SEEDING = true;
|
||||
|
||||
//case 4221, client only seeder now and it will call erase separately to avoid issue with job etc
|
||||
//Erase all the data except for the license, schema and the SuperUser
|
||||
await DbUtil.EmptyBizDataFromDatabaseForSeedingOrImportingAsync(log, JobId);
|
||||
// await DbUtil.EmptyBizDataFromDatabaseForSeedingOrImportingAsync(log, JobId);
|
||||
//Event log erase and seeding
|
||||
using (var ct = ServiceProviderProvider.DBContext)
|
||||
{
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(1, 0, AyaType.Global, AyaEvent.EraseAllData, "(seeding preparation)"), ct);
|
||||
//case 4221
|
||||
// await EventLogProcessor.LogEventToDatabaseAsync(new Event(1, 0, AyaType.Global, AyaEvent.EraseAllData, "(seeding preparation)"), ct);
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(1, 0, AyaType.Global, AyaEvent.SeedDatabase, StatusMsg), ct);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user