тест бд

This commit is contained in:
Professional 2025-03-19 19:31:45 +07:00
parent 4db8b0fc64
commit a97fa75679

View File

@ -646,24 +646,43 @@ class Program
checkTableCommand.CommandText = "PRAGMA table_info(Reports);"; checkTableCommand.CommandText = "PRAGMA table_info(Reports);";
var tableInfo = await checkTableCommand.ExecuteReaderAsync(); var tableInfo = await checkTableCommand.ExecuteReaderAsync();
bool priorityColumnExists = false; var requiredColumns = new HashSet<string> { "Id", "ChatId", "Priority", "Room", "Description", "ReporterName", "DateCreated", "Status" };
var existingColumns = new HashSet<string>();
while (await tableInfo.ReadAsync()) while (await tableInfo.ReadAsync())
{ {
if (tableInfo["name"].ToString() == "Priority") existingColumns.Add(tableInfo["name"].ToString());
{
priorityColumnExists = true;
break;
}
} }
if (!priorityColumnExists) foreach (var column in requiredColumns)
{ {
// Добавляем столбец Priority, если его нет if (!existingColumns.Contains(column))
var alterTableCommand = connection.CreateCommand(); {
alterTableCommand.CommandText = "ALTER TABLE Reports ADD COLUMN Priority TEXT NOT NULL DEFAULT 'низкий';"; var alterTableCommand = connection.CreateCommand();
await alterTableCommand.ExecuteNonQueryAsync(); switch (column)
Log.Information("Столбец Priority добавлен в таблицу Reports."); {
case "Priority":
alterTableCommand.CommandText = "ALTER TABLE Reports ADD COLUMN Priority TEXT NOT NULL DEFAULT 'низкий';";
break;
case "Room":
alterTableCommand.CommandText = "ALTER TABLE Reports ADD COLUMN Room TEXT NOT NULL;";
break;
case "Description":
alterTableCommand.CommandText = "ALTER TABLE Reports ADD COLUMN Description TEXT NOT NULL;";
break;
case "ReporterName":
alterTableCommand.CommandText = "ALTER TABLE Reports ADD COLUMN ReporterName TEXT NOT NULL;";
break;
case "DateCreated":
alterTableCommand.CommandText = "ALTER TABLE Reports ADD COLUMN DateCreated DATETIME DEFAULT CURRENT_TIMESTAMP;";
break;
case "Status":
alterTableCommand.CommandText = "ALTER TABLE Reports ADD COLUMN Status TEXT DEFAULT 'ожидает';";
break;
}
await alterTableCommand.ExecuteNonQueryAsync();
Log.Information($"Столбец {column} добавлен в таблицу Reports.");
}
} }
// Создаем таблицу, если её не существует // Создаем таблицу, если её не существует
@ -694,6 +713,8 @@ class Program
private static Dictionary<long, int> userReportSteps = new Dictionary<long, int>(); private static Dictionary<long, int> userReportSteps = new Dictionary<long, int>();
private static Dictionary<long, Report> userReports = new Dictionary<long, Report>(); private static Dictionary<long, Report> userReports = new Dictionary<long, Report>();