Add_Table_Alarms.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using Dapper;
  2. using SWRIS.Core;
  3. using System;
  4. namespace SWRIS.Migrations
  5. {
  6. public class Add_Table_Alarms : SqLiteBaseRepository
  7. {
  8. public static DateTime Time { get; } = DateTime.Parse("2025-11-24 15:06:00");
  9. public static void Excute()
  10. {
  11. using (var conn = DbConnection())
  12. {
  13. conn.Open();
  14. var isExist = conn.QueryFirstOrDefault<int>(
  15. "SELECT COUNT(1) FROM Migrations WHERE MigrationId = @MigrationId;",
  16. new { MigrationId = "Add_Table_Alarms" });
  17. if (isExist > 0)
  18. {
  19. return;
  20. }
  21. var isDelay = conn.QueryFirstOrDefault<bool>(
  22. "SELECT MAX(Time) > @Time AS IsGreater FROM Migrations;", new { Time });
  23. if (isDelay)
  24. {
  25. return;
  26. }
  27. string @string = @"CREATE TABLE IF NOT EXISTS Alarms (
  28. Id INTEGER PRIMARY KEY AUTOINCREMENT,
  29. RopeNumber INTEGER,
  30. DamagePosition REAL,
  31. DamageValue REAL,
  32. DamageLevel INTEGER,
  33. CreateTime DATETIME NOT NULL,
  34. SourceType INTEGER
  35. );";
  36. conn.Execute(@string.ToString());
  37. #region Migrations
  38. @string = (@"INSERT INTO Migrations
  39. ( MigrationId, Time, ExcuteTime ) VALUES
  40. ( @MigrationId, @Time, @ExcuteTime );");
  41. conn.Execute(@string.ToString(), new { MigrationId = "Add_Table_Alarms", Time, ExcuteTime = DateTime.Now });
  42. #endregion
  43. }
  44. }
  45. }
  46. }