This commit is contained in:
@@ -3,6 +3,7 @@ using Microsoft.Extensions.Logging;
|
||||
using AyaNova.Models;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace AyaNova.Util
|
||||
@@ -251,7 +252,7 @@ namespace AyaNova.Util
|
||||
// Erase all user entered data from the db
|
||||
// This is called by seeder for trial seeding purposes
|
||||
//
|
||||
internal static void EmptyBizDataFromDatabaseForSeedingOrImporting(ILogger _log)
|
||||
internal static async Task EmptyBizDataFromDatabaseForSeedingOrImportingAsync(ILogger _log)
|
||||
{
|
||||
|
||||
|
||||
@@ -265,14 +266,14 @@ namespace AyaNova.Util
|
||||
|
||||
using (var conn = new Npgsql.NpgsqlConnection(_dbConnectionString))
|
||||
{
|
||||
conn.Open();
|
||||
await conn.OpenAsync();
|
||||
|
||||
//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();
|
||||
await cmd.ExecuteNonQueryAsync();
|
||||
}
|
||||
|
||||
//Delete from users table
|
||||
@@ -280,20 +281,20 @@ namespace AyaNova.Util
|
||||
{
|
||||
cmd.Connection = conn;
|
||||
cmd.CommandText = "delete from \"auser\" where id <> 1;";
|
||||
cmd.ExecuteNonQuery();
|
||||
await cmd.ExecuteNonQueryAsync();
|
||||
}
|
||||
|
||||
//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("adatalistfilter", conn);
|
||||
EraseTable("adatalisttemplate", conn);
|
||||
EraseTable("aformcustom", conn);
|
||||
EraseTable("asearchkey", conn);
|
||||
EraseTable("asearchdictionary", conn);
|
||||
EraseTable("atag", conn);
|
||||
EraseTableAsync("afileattachment", conn);
|
||||
EraseTableAsync("awidget", conn);
|
||||
EraseTableAsync("aevent", conn);
|
||||
EraseTableAsync("adatalistfilter", conn);
|
||||
EraseTableAsync("adatalisttemplate", conn);
|
||||
EraseTableAsync("aformcustom", conn);
|
||||
EraseTableAsync("asearchkey", conn);
|
||||
EraseTableAsync("asearchdictionary", conn);
|
||||
EraseTableAsync("atag", conn);
|
||||
|
||||
conn.Close();
|
||||
}
|
||||
@@ -309,13 +310,13 @@ namespace AyaNova.Util
|
||||
///////////////////////////////////////////
|
||||
// Erase all data from the table specified
|
||||
//
|
||||
private static void EraseTable(string sTable, Npgsql.NpgsqlConnection conn)
|
||||
private static async Task EraseTableAsync(string sTable, Npgsql.NpgsqlConnection conn)
|
||||
{
|
||||
using (var cmd = new Npgsql.NpgsqlCommand())
|
||||
{
|
||||
cmd.Connection = conn;
|
||||
cmd.CommandText = "TRUNCATE \"" + sTable + "\" RESTART IDENTITY CASCADE;";
|
||||
cmd.ExecuteNonQuery();
|
||||
await cmd.ExecuteNonQueryAsync();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -324,7 +325,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)
|
||||
internal static bool DBIsEmpty(AyContext ct, ILogger _log)
|
||||
{
|
||||
//TODO: This needs to be way more thorough, only the main tables though, no need to get crazy with it
|
||||
//just stuff that would be shitty to have to re-enter
|
||||
@@ -332,7 +333,7 @@ namespace AyaNova.Util
|
||||
_log.LogDebug("DB empty check");
|
||||
|
||||
//An empty db contains only one User
|
||||
if (ctx.User.Count() > 1) return false;
|
||||
if (ct.User.Count() > 1) return false;
|
||||
|
||||
//No clients
|
||||
//if(ctx.Client.Count()>0) return false;
|
||||
@@ -354,7 +355,7 @@ namespace AyaNova.Util
|
||||
///////////////////////////////////////////
|
||||
// Ensure the db is not modified
|
||||
//
|
||||
internal static void CheckFingerPrint(long ExpectedColumns, long ExpectedIndexes, ILogger _log)
|
||||
internal static async Task CheckFingerPrintAsync(long ExpectedColumns, long ExpectedIndexes, ILogger _log)
|
||||
{
|
||||
_log.LogDebug("Checking DB integrity");
|
||||
|
||||
@@ -363,19 +364,19 @@ namespace AyaNova.Util
|
||||
|
||||
using (var conn = new Npgsql.NpgsqlConnection(_dbConnectionString))
|
||||
{
|
||||
conn.Open();
|
||||
await conn.OpenAsync();
|
||||
|
||||
using (var command = conn.CreateCommand())
|
||||
{
|
||||
//Count all columns in all our tables
|
||||
command.CommandText = "SELECT count(*) FROM information_schema.columns where table_schema='public'";
|
||||
|
||||
using (var result = command.ExecuteReader())
|
||||
using (var result = await command.ExecuteReaderAsync())
|
||||
{
|
||||
if (result.HasRows)
|
||||
{
|
||||
//check the values
|
||||
result.Read();
|
||||
await result.ReadAsync();
|
||||
actualColumns = result.GetInt64(0);
|
||||
}
|
||||
else
|
||||
@@ -393,12 +394,12 @@ namespace AyaNova.Util
|
||||
//Count all indexes in all our tables
|
||||
command.CommandText = "select Count(*) from pg_indexes where schemaname='public'";
|
||||
|
||||
using (var result = command.ExecuteReader())
|
||||
using (var result = await command.ExecuteReaderAsync())
|
||||
{
|
||||
if (result.HasRows)
|
||||
{
|
||||
//check the values
|
||||
result.Read();
|
||||
await result.ReadAsync();
|
||||
actualIndexes = result.GetInt64(0);
|
||||
}
|
||||
else
|
||||
@@ -409,7 +410,7 @@ namespace AyaNova.Util
|
||||
}
|
||||
}
|
||||
}
|
||||
conn.Close();
|
||||
await conn.CloseAsync();
|
||||
|
||||
if (ExpectedColumns != actualColumns || ExpectedIndexes != actualIndexes)
|
||||
{
|
||||
@@ -426,27 +427,27 @@ namespace AyaNova.Util
|
||||
// Used for metrics
|
||||
//
|
||||
///
|
||||
internal static long CountOfRecords(string TableName)
|
||||
internal static async Task<long> CountOfRecordsAsync(string TableName)
|
||||
{
|
||||
long ret = 0;
|
||||
|
||||
using (var conn = new Npgsql.NpgsqlConnection(_dbConnectionString))
|
||||
{
|
||||
conn.Open();
|
||||
await conn.OpenAsync();
|
||||
|
||||
using (var command = conn.CreateCommand())
|
||||
{
|
||||
command.CommandText = $"SELECT count(*) FROM {TableName}";
|
||||
using (var result = command.ExecuteReader())
|
||||
using (var result = await command.ExecuteReaderAsync())
|
||||
{
|
||||
if (result.HasRows)
|
||||
{
|
||||
result.Read();
|
||||
await result.ReadAsync();
|
||||
ret = result.GetInt64(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
conn.Close();
|
||||
await conn.CloseAsync();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -456,7 +457,7 @@ namespace AyaNova.Util
|
||||
// Returns all table names that are ours in current schema
|
||||
//
|
||||
///
|
||||
internal static List<string> GetAllTablenames()
|
||||
internal static async Task<List<string>> GetAllTablenamesAsync()
|
||||
{
|
||||
|
||||
List<string> ret = new List<string>();
|
||||
|
||||
@@ -522,7 +522,7 @@ namespace AyaNova.Core
|
||||
}
|
||||
|
||||
//Can't install a trial into a non-empty db
|
||||
if (ParsedNewKey.TrialLicense && !DbUtil.DBIsEmpty(ct, log))
|
||||
if (ParsedNewKey.TrialLicense && !DbUtil.DBIsEmptyAsync(ct, log))
|
||||
{
|
||||
throw new ApplicationException("E1020 - Can't install a trial key into a non empty AyaNova database. Erase the database first.");
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ namespace AyaNova.Util
|
||||
apiServerState.SetOpsOnly("Seeding database");
|
||||
|
||||
//Erase all the data except for the license, schema and the manager user
|
||||
DbUtil.EmptyBizDataFromDatabaseForSeedingOrImporting(log);
|
||||
DbUtil.EmptyBizDataFromDatabaseForSeedingOrImportingAsync(log);
|
||||
|
||||
|
||||
//Set the time zone of the manager account
|
||||
|
||||
Reference in New Issue
Block a user