|
@@ -128,11 +128,9 @@ namespace InABox.Database.SQLite
|
|
|
File.Copy(URL, Path.ChangeExtension(URL, string.Format("{0:D3}", i)));
|
|
|
}
|
|
|
|
|
|
+ using var access = GetWriteAccess();
|
|
|
|
|
|
- using (var access = GetWriteAccess())
|
|
|
- {
|
|
|
- ExecuteSQL(access, "PRAGMA journal_mode=WAL;");
|
|
|
- }
|
|
|
+ ExecuteSQL(access, "PRAGMA journal_mode=WAL;");
|
|
|
|
|
|
//using (var access = GetReadAccess())
|
|
|
//{
|
|
@@ -150,7 +148,10 @@ namespace InABox.Database.SQLite
|
|
|
|
|
|
//ExecuteSQL("PRAGMA foreign_keys = on;");
|
|
|
|
|
|
- //using var profiler = new Profiler(true);
|
|
|
+ foreach(var type in Types)
|
|
|
+ {
|
|
|
+ DatabaseSchema.CheckProperties(type);
|
|
|
+ }
|
|
|
|
|
|
// Need to arrange the typelist to ensure that foreign keys
|
|
|
// refer to tables that already exist
|
|
@@ -158,8 +159,6 @@ namespace InABox.Database.SQLite
|
|
|
foreach (var type in Types)
|
|
|
LoadType(type, ordered);
|
|
|
|
|
|
- //profiler.Log("Ordered");
|
|
|
-
|
|
|
//Load up the metadata
|
|
|
var metadata = LoadMetaData();
|
|
|
|
|
@@ -168,20 +167,15 @@ namespace InABox.Database.SQLite
|
|
|
{
|
|
|
OnLog?.Invoke(LogType.Information, $"Creating Table: {nameof(CustomProperty)}");
|
|
|
|
|
|
- using var access = GetWriteAccess();
|
|
|
CreateTable(access, typeof(CustomProperty), true, []);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- using var access = GetWriteAccess();
|
|
|
CheckFields(access, typeof(CustomProperty), value.Item1, []);
|
|
|
}
|
|
|
|
|
|
- //profiler.Log("Ordered");
|
|
|
-
|
|
|
var customproperties = Load<CustomProperty>(); // new Filter<CustomProperty>(x => x.Class).IsEqualTo(type.EntityName()))
|
|
|
|
|
|
-
|
|
|
metadata = LoadMetaData();
|
|
|
|
|
|
foreach (var type in ordered)
|
|
@@ -191,41 +185,31 @@ namespace InABox.Database.SQLite
|
|
|
table = type.EntityName().Split('.').Last();
|
|
|
if (!metadata.ContainsKey(table))
|
|
|
{
|
|
|
- OnLog?.Invoke(LogType.Information, "Creating Table: " + type.EntityName().Split('.').Last());
|
|
|
- using (var access = GetWriteAccess())
|
|
|
- {
|
|
|
- CreateTable(access, type, true, customproperties);
|
|
|
- }
|
|
|
+ OnLog?.Invoke(LogType.Information, "Creating Table: " + type.Name);
|
|
|
+ CreateTable(access, type, true, customproperties);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
metadata = LoadMetaData();
|
|
|
-
|
|
|
+
|
|
|
foreach (var type in ordered)
|
|
|
{
|
|
|
if (type.GetCustomAttribute<AutoEntity>() == null)
|
|
|
{
|
|
|
table = type.EntityName().Split('.').Last();
|
|
|
- using (var access = GetWriteAccess())
|
|
|
- {
|
|
|
- CheckFields(access, type, metadata[table].Item1, customproperties);
|
|
|
- }
|
|
|
+ CheckFields(access, type, metadata[table].Item1, customproperties);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
metadata = LoadMetaData();
|
|
|
-
|
|
|
+
|
|
|
foreach (var type in ordered)
|
|
|
{
|
|
|
if (type.GetCustomAttribute<AutoEntity>() == null)
|
|
|
-
|
|
|
{
|
|
|
- table = type.EntityName().Split('.').Last();
|
|
|
- using (var access = GetWriteAccess())
|
|
|
- {
|
|
|
- CheckTriggers(access, type, metadata[table].Item2);
|
|
|
- }
|
|
|
+ table = type.Name;
|
|
|
+ CheckTriggers(access, type, metadata[table].Item2);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -237,10 +221,7 @@ namespace InABox.Database.SQLite
|
|
|
{
|
|
|
|
|
|
table = type.EntityName().Split('.').Last();
|
|
|
- using (var access = GetWriteAccess())
|
|
|
- {
|
|
|
- CheckIndexes(access, type, metadata[table].Item3);
|
|
|
- }
|
|
|
+ CheckIndexes(access, type, metadata[table].Item3);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -254,27 +235,18 @@ namespace InABox.Database.SQLite
|
|
|
if (!metadata.ContainsKey(table))
|
|
|
{
|
|
|
OnLog?.Invoke(LogType.Information, "Creating Table: " + type.EntityName().Split('.').Last());
|
|
|
- using (var access = GetWriteAccess())
|
|
|
- {
|
|
|
- CreateTable(access, type, true, customproperties);
|
|
|
- }
|
|
|
+ CreateTable(access, type, true, customproperties);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- using (var access = GetWriteAccess())
|
|
|
- {
|
|
|
- CheckFields(access, type, metadata[table].Item1, customproperties);
|
|
|
- }
|
|
|
+ CheckFields(access, type, metadata[table].Item1, customproperties);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (bForceRebuild)
|
|
|
{
|
|
|
- using (var access = GetWriteAccess())
|
|
|
- {
|
|
|
- ExecuteSQL(access, "VACUUM;");
|
|
|
- }
|
|
|
+ ExecuteSQL(access, "VACUUM;");
|
|
|
|
|
|
File.Delete(chkfile);
|
|
|
}
|