This commit is contained in:
2022-03-09 22:41:12 +00:00
parent 7b05a63bae
commit 6e94270628
4 changed files with 26 additions and 69 deletions

View File

@@ -265,7 +265,7 @@ namespace AyaNova.Api.Controllers
//empty the db
await AyaNova.Util.DbUtil.EmptyBizDataFromDatabaseForSeedingOrImportingAsync(log);
await AyaNova.Util.DbUtil.EmptyBizDataFromDatabaseForSeedingOrImportingAsync(log, Guid.Empty);
//Log
await EventLogProcessor.LogEventToDatabaseAsync(new Event(1, 0, AyaType.Global, AyaEvent.EraseAllData), ct);

View File

@@ -306,7 +306,7 @@ namespace AyaNova.Util
// Erase all user entered data from the db
// This is called by seeder for trial seeding purposes
// and by v8 migrate and by license controller when erasing db
internal static async Task EmptyBizDataFromDatabaseForSeedingOrImportingAsync(ILogger _log)
internal static async Task EmptyBizDataFromDatabaseForSeedingOrImportingAsync(ILogger _log, Guid jobIdToKeep)
{
_log.LogInformation("Erasing Database \"{0}\"", _dbName);
@@ -321,12 +321,6 @@ namespace AyaNova.Util
{
await conn.OpenAsync();
//### DELIBERATELY IGNORED
//Some data is deliberately not deleted for now:
//Reports
//Logos
//prepare to delete by removing foreign keys
using (var cmd = new Npgsql.NpgsqlCommand())
{
@@ -350,48 +344,31 @@ namespace AyaNova.Util
cmd.CommandText = "update apurchaseorderitem set workorderitempartrequestid=null;";
await cmd.ExecuteNonQueryAsync();
cmd.CommandText = "update aglobalbizsettings set "
+ "webaddress =null, phone1 =null, phone2 =null, emailaddress =null, postaddress =null, postcity =null, postregion =null, postcountry =null, postcode =null, "
+ "address =null, city =null, region =null, country =null, latitude=null, longitude =null, "
+ "filtercasesensitive = FALSE, "
+ "useinventory = TRUE, "
+ "allowscheduleconflicts = TRUE, "
+ "workordercompletebyage = '00:00:00', "
+ "workordertraveldefaultminutes = 0, "
+ "worklaborscheduledefaultminutes = 0, "
+ "signaturetitle =null, "
+ "signatureheader =null, "
+ "signaturefooter =null, "
+ "customerservicerequestinfotext =null, "
+ "customerallowcsr = FALSE, customerallowcsrintags ='{}', "
+ "customerallowcreateunit = FALSE, customerallowcreateunitintags ='{}', "
+ "customerallowviewwo = FALSE, customerallowviewwointags ='{}', "
+ "customerworkorderreport1tags ='{}', customerworkorderreport2tags ='{}', "
+ "customerworkorderreport3tags ='{}', customerworkorderreport4tags ='{}', customerworkorderreport5tags ='{}', "
+ "customerallowwowiki = FALSE, customerallowwowikiintags ='{}', "
+ "customerallowwoattachments = FALSE, customerallowwoattachmentsintags ='{}', "
+ "customerallowusersettings = FALSE, customerallowusersettingsintags ='{}', "
+ "customerallownotifyserviceimminent = FALSE, customerallownotifyserviceimminentintags ='{}', "
+ "customerallownotifycsraccepted = FALSE, customerallownotifycsracceptedintags ='{}', "
+ "customerallownotifycsrrejected = FALSE, customerallownotifycsrrejectedintags ='{}', "
+ "customerallownotifywocreated = FALSE, customerallownotifywocreatedintags ='{}', "
+ "customerallownotifywocompleted = FALSE, customerallownotifywocompletedintags ='{}', "
+ "taxpartpurchaseid=null,taxpartsaleid=null,taxratesaleid=null, "
+ "customerdefaultworkorderreportid=null, customertagworkorderreport1id=null, customertagworkorderreport2id=null, "
+ "customertagworkorderreport3id=null, customertagworkorderreport4id=null, customertagworkorderreport5id=null ";
await cmd.ExecuteNonQueryAsync();
//reset global settings cache taxes
ServerGlobalBizSettings.Cache.TaxPartPurchaseId = null;
ServerGlobalBizSettings.Cache.TaxPartSaleId = null;
ServerGlobalBizSettings.Cache.TaxRateSaleId = null;
cmd.CommandText = "update aworkorderitem set fromcsrid=null;";
await cmd.ExecuteNonQueryAsync();
//aglobalopsbackupsettings just keep as is which is the safe option
if (jobIdToKeep != Guid.Empty)
{
//delete from aopsjoblog where jobid <> '8acec231-aab4-4fdc-b01e-8908378a0e7f';
//delete from aopsjob where gid <> '8acec231-aab4-4fdc-b01e-8908378a0e7f';
cmd.CommandText = $"delete from aopsjoblog where jobid <> '{jobIdToKeep}'";
await cmd.ExecuteNonQueryAsync();
cmd.CommandText = $"delete from aopsjob where gid <> '{jobIdToKeep}'";
await cmd.ExecuteNonQueryAsync();
}
cmd.CommandText = "update aglobalopsnotificationsettings set smtpdeliveryactive=false, smtpserveraddress=null,smtpaccount=null,smtppassword=null,connectionsecurity=0, smtpserverport=null,notifyfromaddress=null,ayanovaserverurl=null;";
await cmd.ExecuteNonQueryAsync();
//DELIBERATELY NOT ERASED:
//NOTE: these tables commented below are deliberately not affected as it's assumed for a **COMPLETE** erase users will erase manually or use the config setting to completely drop the database
//For anything less than that it's assumed users are testing things out and want to keep these tables but erase the biz data
//aglobalopsbackupsettings
//aglobalopsnotificationsettings
//aglobalbizsettings
//alogo
//areport
//await EraseTableAsync("aopsjoblog", conn, true);
// await EraseTableAsync("aopsjob", conn, true);
}
@@ -509,7 +486,7 @@ namespace AyaNova.Util
await EraseTableAsync("aservicerate", conn);
await EraseTableAsync("atravelrate", conn);
await EraseTableAsync("ataxcode", conn);
//await EraseTableAsync("ataxcode", conn);
await EraseTableAsync("aquotestatus", conn);
@@ -522,12 +499,7 @@ namespace AyaNova.Util
await EraseTableAsync("ametricdd", conn, true);
await EraseTableAsync("adashboardview", conn);
await EraseTableAsync("aopsjoblog", conn, true);
await EraseTableAsync("aopsjob", conn, true);
await EraseTableAsync("alogo", conn);
await EraseTableAsync("areport", conn);
await Biz.PrimeData.PrimeReportTemplates();
// await EraseTableAsync("XXXXX", conn);

View File

@@ -104,7 +104,7 @@ namespace AyaNova.Util
ServerBootConfig.SEEDING = true;
//Erase all the data except for the license, schema and the SuperUser
await DbUtil.EmptyBizDataFromDatabaseForSeedingOrImportingAsync(log);
await DbUtil.EmptyBizDataFromDatabaseForSeedingOrImportingAsync(log, JobId);
//Event log erase and seeding
using (var ct = ServiceProviderProvider.DBContext)
{