This commit is contained in:
@@ -580,7 +580,13 @@ namespace AyaNova
|
|||||||
|
|
||||||
//Check database integrity
|
//Check database integrity
|
||||||
_newLog.LogDebug("DB integrity check");
|
_newLog.LogDebug("DB integrity check");
|
||||||
DbUtil.CheckFingerPrintAsync(AySchema.EXPECTED_COLUMN_COUNT, AySchema.EXPECTED_INDEX_COUNT, _newLog).Wait();
|
DbUtil.CheckFingerPrintAsync(AySchema.EXPECTED_COLUMN_COUNT,
|
||||||
|
AySchema.EXPECTED_INDEX_COUNT,
|
||||||
|
AySchema.EXPECTED_CHECK_CONSTRAINTS,
|
||||||
|
AySchema.EXPECTED_FOREIGN_KEY_CONSTRAINTS,
|
||||||
|
AySchema.EXPECTED_VIEWS,
|
||||||
|
AySchema.EXPECTED_ROUTINES,
|
||||||
|
_newLog).Wait();
|
||||||
|
|
||||||
//Initialize license
|
//Initialize license
|
||||||
AyaNova.Core.License.InitializeAsync(apiServerState, dbContext, _newLog).Wait();
|
AyaNova.Core.License.InitializeAsync(apiServerState, dbContext, _newLog).Wait();
|
||||||
|
|||||||
@@ -24,6 +24,10 @@ namespace AyaNova.Util
|
|||||||
|
|
||||||
internal const long EXPECTED_COLUMN_COUNT = 710;
|
internal const long EXPECTED_COLUMN_COUNT = 710;
|
||||||
internal const long EXPECTED_INDEX_COUNT = 124;
|
internal const long EXPECTED_INDEX_COUNT = 124;
|
||||||
|
internal const long EXPECTED_CHECK_CONSTRAINTS=1;
|
||||||
|
internal const long EXPECTED_FOREIGN_KEY_CONSTRAINTS=1;
|
||||||
|
internal const long EXPECTED_VIEWS=1;
|
||||||
|
internal const long EXPECTED_ROUTINES=1;
|
||||||
|
|
||||||
//!!!!WARNING: BE SURE TO UPDATE THE DbUtil::EmptyBizDataFromDatabaseForSeedingOrImporting WHEN NEW TABLES ADDED!!!!
|
//!!!!WARNING: BE SURE TO UPDATE THE DbUtil::EmptyBizDataFromDatabaseForSeedingOrImporting WHEN NEW TABLES ADDED!!!!
|
||||||
|
|
||||||
|
|||||||
@@ -497,13 +497,20 @@ namespace AyaNova.Util
|
|||||||
///////////////////////////////////////////
|
///////////////////////////////////////////
|
||||||
// Ensure the db is not modified
|
// Ensure the db is not modified
|
||||||
//
|
//
|
||||||
internal static async Task CheckFingerPrintAsync(long ExpectedColumns, long ExpectedIndexes, ILogger _log)
|
internal static async Task CheckFingerPrintAsync(long ExpectedColumns, long ExpectedIndexes,
|
||||||
|
long ExpectedCheckConstraints, long ExpectedForeignKeyConstraints,
|
||||||
|
long ExpectedViews, long ExpectedRoutines, ILogger _log)
|
||||||
{
|
{
|
||||||
_log.LogDebug("Checking DB integrity");
|
_log.LogDebug("Checking DB integrity");
|
||||||
|
|
||||||
long actualColumns = 0;
|
long actualColumns = 0;
|
||||||
long actualIndexes = 0;
|
long actualIndexes = 0;
|
||||||
|
long actualCheckConstraints = 0;
|
||||||
|
long actualForeignKeyConstraints = 0;
|
||||||
|
long actualViews = 0;
|
||||||
|
long actualRoutines = 0;
|
||||||
|
|
||||||
|
//COLUMNS
|
||||||
using (var conn = new Npgsql.NpgsqlConnection(_dbConnectionString))
|
using (var conn = new Npgsql.NpgsqlConnection(_dbConnectionString))
|
||||||
{
|
{
|
||||||
await conn.OpenAsync();
|
await conn.OpenAsync();
|
||||||
@@ -523,7 +530,7 @@ namespace AyaNova.Util
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var err = "E1030 - Database integrity check failed, could not obtain column data. Contact support.";
|
var err = "E1030 - Database integrity check failed, could not obtain COLUMN data. Contact support.";
|
||||||
_log.LogCritical(err);
|
_log.LogCritical(err);
|
||||||
|
|
||||||
throw new ApplicationException(err);
|
throw new ApplicationException(err);
|
||||||
@@ -531,6 +538,7 @@ namespace AyaNova.Util
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//INDEXES
|
||||||
using (var command = conn.CreateCommand())
|
using (var command = conn.CreateCommand())
|
||||||
{
|
{
|
||||||
//Count all indexes in all our tables
|
//Count all indexes in all our tables
|
||||||
@@ -546,7 +554,7 @@ namespace AyaNova.Util
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var err = "E1030 - Database integrity check failed, could not obtain index data. Contact support.";
|
var err = "E1030 - Database integrity check failed, could not obtain INDEX data. Contact support.";
|
||||||
_log.LogCritical(err);
|
_log.LogCritical(err);
|
||||||
throw new ApplicationException(err);
|
throw new ApplicationException(err);
|
||||||
}
|
}
|
||||||
@@ -554,6 +562,109 @@ namespace AyaNova.Util
|
|||||||
}
|
}
|
||||||
await conn.CloseAsync();
|
await conn.CloseAsync();
|
||||||
|
|
||||||
|
//CHECK CONSTRAINTS
|
||||||
|
using (var command = conn.CreateCommand())
|
||||||
|
{
|
||||||
|
|
||||||
|
command.CommandText = "SELECT count(*) FROM information_schema.check_constraints where constraint_schema='public'";
|
||||||
|
|
||||||
|
using (var result = await command.ExecuteReaderAsync())
|
||||||
|
{
|
||||||
|
if (result.HasRows)
|
||||||
|
{
|
||||||
|
//check the values
|
||||||
|
await result.ReadAsync();
|
||||||
|
actualCheckConstraints = result.GetInt64(0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var err = "E1030 - Database integrity check failed, could not obtain CHECK CONSTRAINT data. Contact support.";
|
||||||
|
_log.LogCritical(err);
|
||||||
|
throw new ApplicationException(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await conn.CloseAsync();
|
||||||
|
|
||||||
|
|
||||||
|
//FOREIGN KEY CONSTRAINTS
|
||||||
|
using (var command = conn.CreateCommand())
|
||||||
|
{
|
||||||
|
|
||||||
|
command.CommandText = "SELECT count(*) FROM information_schema.referential_constraints where constraint_schema='public'";
|
||||||
|
|
||||||
|
using (var result = await command.ExecuteReaderAsync())
|
||||||
|
{
|
||||||
|
if (result.HasRows)
|
||||||
|
{
|
||||||
|
//check the values
|
||||||
|
await result.ReadAsync();
|
||||||
|
actualForeignKeyConstraints = result.GetInt64(0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var err = "E1030 - Database integrity check failed, could not obtain FOREIGN KEY CONSTRAINT data. Contact support.";
|
||||||
|
_log.LogCritical(err);
|
||||||
|
throw new ApplicationException(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await conn.CloseAsync();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//VIEWS
|
||||||
|
using (var command = conn.CreateCommand())
|
||||||
|
{
|
||||||
|
|
||||||
|
command.CommandText = "SELECT count(*) FROM information_schema.views where table_schema='public'";
|
||||||
|
|
||||||
|
using (var result = await command.ExecuteReaderAsync())
|
||||||
|
{
|
||||||
|
if (result.HasRows)
|
||||||
|
{
|
||||||
|
//check the values
|
||||||
|
await result.ReadAsync();
|
||||||
|
actualViews = result.GetInt64(0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var err = "E1030 - Database integrity check failed, could not obtain VIEW data. Contact support.";
|
||||||
|
_log.LogCritical(err);
|
||||||
|
throw new ApplicationException(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await conn.CloseAsync();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//ROUTINES
|
||||||
|
using (var command = conn.CreateCommand())
|
||||||
|
{
|
||||||
|
|
||||||
|
command.CommandText = "SELECT count(*) FROM information_schema.routines where routine_schema='public'";
|
||||||
|
|
||||||
|
using (var result = await command.ExecuteReaderAsync())
|
||||||
|
{
|
||||||
|
if (result.HasRows)
|
||||||
|
{
|
||||||
|
//check the values
|
||||||
|
await result.ReadAsync();
|
||||||
|
actualRoutines = result.GetInt64(0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var err = "E1030 - Database integrity check failed, could not obtain ROUTINE data. Contact support.";
|
||||||
|
_log.LogCritical(err);
|
||||||
|
throw new ApplicationException(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await conn.CloseAsync();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (ExpectedColumns != actualColumns || ExpectedIndexes != actualIndexes)
|
if (ExpectedColumns != actualColumns || ExpectedIndexes != actualIndexes)
|
||||||
{
|
{
|
||||||
var err = string.Format("E1030 - Database integrity check failed (C{0}I{1})", actualColumns, actualIndexes);
|
var err = string.Format("E1030 - Database integrity check failed (C{0}I{1})", actualColumns, actualIndexes);
|
||||||
|
|||||||
Reference in New Issue
Block a user