From a97fa756798ffe53b03c8e13e88003942e534564 Mon Sep 17 00:00:00 2001 From: Professional Date: Wed, 19 Mar 2025 19:31:45 +0700 Subject: [PATCH] =?UTF-8?q?=D1=82=D0=B5=D1=81=D1=82=20=D0=B1=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Program.cs | 45 +++++++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 12 deletions(-) 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();