diff --git a/Program.cs b/Program.cs index ce94308..67741f4 100644 --- a/Program.cs +++ b/Program.cs @@ -646,24 +646,43 @@ class Program checkTableCommand.CommandText = "PRAGMA table_info(Reports);"; var tableInfo = await checkTableCommand.ExecuteReaderAsync(); - bool priorityColumnExists = false; + var requiredColumns = new HashSet { "Id", "ChatId", "Priority", "Room", "Description", "ReporterName", "DateCreated", "Status" }; + var existingColumns = new HashSet(); while (await tableInfo.ReadAsync()) { - if (tableInfo["name"].ToString() == "Priority") - { - priorityColumnExists = true; - break; - } + existingColumns.Add(tableInfo["name"].ToString()); } - if (!priorityColumnExists) + foreach (var column in requiredColumns) { - // Добавляем столбец Priority, если его нет - var alterTableCommand = connection.CreateCommand(); - alterTableCommand.CommandText = "ALTER TABLE Reports ADD COLUMN Priority TEXT NOT NULL DEFAULT 'низкий';"; - await alterTableCommand.ExecuteNonQueryAsync(); - Log.Information("Столбец Priority добавлен в таблицу Reports."); + if (!existingColumns.Contains(column)) + { + var alterTableCommand = connection.CreateCommand(); + switch (column) + { + 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 userReportSteps = new Dictionary(); private static Dictionary userReports = new Dictionary();