This commit is contained in:
2018-12-18 18:37:15 +00:00
parent 1796aa3194
commit 2be97c7d37
6 changed files with 52 additions and 36 deletions

View File

@@ -307,6 +307,8 @@ namespace AyaNova.Util
}
//#########################################
//!!!!WARNING: BE SURE TO UPDATE THE DbUtil::EmptyBizDataFromDatabaseForSeedingOrImporting WHEN NEW TABLES ADDED!!!!
//////////////////////////////////////////////////
// FUTURE
@@ -318,7 +320,7 @@ namespace AyaNova.Util
// }
//!!!!WARNING: BE SURE TO UPDATE THE DbUtil::PrepareDatabaseForSeeding WHEN NEW TABLES ADDED!!!!

View File

@@ -251,8 +251,10 @@ namespace AyaNova.Util
// Erase all user entered data from the db
// This is called by seeder for trial seeding purposes
//
internal static void PrepareDatabaseForSeeding(ILogger _log)
internal static void EmptyBizDataFromDatabaseForSeedingOrImporting(ILogger _log)
{
_log.LogInformation("Erasing Database \"{0}\"", _dbName);
AyaNova.Api.ControllerHelpers.ApiServerState apiServerState = (AyaNova.Api.ControllerHelpers.ApiServerState)ServiceProviderProvider.Provider.GetService(typeof(AyaNova.Api.ControllerHelpers.ApiServerState));
@@ -265,6 +267,15 @@ namespace AyaNova.Util
{
conn.Open();
//Delete from user options table first
using (var cmd = new Npgsql.NpgsqlCommand())
{
cmd.Connection = conn;
cmd.CommandText = "delete from \"auseroptions\" where UserId <> 1;";
cmd.ExecuteNonQuery();
}
//Delete from users table
using (var cmd = new Npgsql.NpgsqlCommand())
{
cmd.Connection = conn;
@@ -272,14 +283,14 @@ namespace AyaNova.Util
cmd.ExecuteNonQuery();
}
//THIS METHOD IS ONLY CALLED BY SEEDER
//SO ONLY REMOVE DATA THAT IS SEEDED
//I.E. Normal user business data, not infrastructure data like license or localized text etc
//REMOVE ALL DATA with few exceptions of manager user, license, schema tables
//and job logs because this is called by job code
EraseTable("afileattachment", conn);
EraseTable("awidget", conn);
EraseTable("aevent", conn);
EraseTable("adatafilter", conn);
EraseTable("asearchkey", conn);
EraseTable("asearchdictionary", conn);
conn.Close();
}
@@ -309,7 +320,7 @@ namespace AyaNova.Util
///////////////////////////////////////////
// Check if DB is empty
// CALLED BY LICENSE CONTROLLER AND LICENSE.CS FOR TRIAL Request check
//
// Also called by Import
internal static bool DBIsEmpty(AyContext ctx, ILogger _log)
{
//TODO: This needs to be way more thorough, only the main tables though, no need to get crazy with it

View File

@@ -66,7 +66,7 @@ namespace AyaNova.Util
apiServerState.SetOpsOnly("Seeding database");
//Erase all the data except for the license, schema and the manager user
DbUtil.PrepareDatabaseForSeeding(log);
DbUtil.EmptyBizDataFromDatabaseForSeedingOrImporting(log);
//Set the time zone of the manager account
{