Initial_Migration.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using Dapper;
  2. using SWRIS.Core;
  3. using System;
  4. namespace SWRIS.Migrations
  5. {
  6. public class Initial_Migration : SqLiteBaseRepository
  7. {
  8. public static DateTime Time { get; } = DateTime.Parse("2025-10-01 08:00:00");
  9. public static void Excute()
  10. {
  11. using (var conn = DbConnection())
  12. {
  13. string @string = string.Empty;
  14. conn.Open();
  15. @string = @"CREATE TABLE IF NOT EXISTS Migrations (
  16. MigrationId VARCHAR(150) PRIMARY KEY,
  17. Time DATETIME NOT NULL,
  18. ExcuteTime DATETIME NOT NULL
  19. );";
  20. conn.Execute(@string.ToString());
  21. @string = @"CREATE TABLE Records (
  22. Id INTEGER PRIMARY KEY AUTOINCREMENT,
  23. RopeNumber INTEGER,
  24. RopeName TEXT (100),
  25. StartTime DATETIME NOT NULL,
  26. EndTime DATETIME NOT NULL,
  27. StartPoint REAL,
  28. EndPoint REAL,
  29. DetectionLength REAL,
  30. DetectedSpeed REAL,
  31. DamageCount INTEGER,
  32. RiskLevel INTEGER,
  33. DataFilePath TEXT (300),
  34. SensorCount INTEGER DEFAULT (4) NOT NULL,
  35. SamplingStep REAL,
  36. ExportCount INTEGER DEFAULT (0) NOT NULL,
  37. InUseSensors TEXT (100) DEFAULT ('1,2,3,4')
  38. );";
  39. conn.Execute(@string.ToString());
  40. @string = @"CREATE TABLE Damages (
  41. Id INTEGER PRIMARY KEY AUTOINCREMENT,
  42. RecordId INTEGER NOT NULL,
  43. DamagePoint REAL NOT NULL,
  44. DamageValue REAL,
  45. DamageLevel INTEGER
  46. );";
  47. conn.Execute(@string.ToString());
  48. #region Migrations
  49. @string = (@"INSERT INTO Migrations
  50. ( MigrationId, Time, ExcuteTime ) VALUES
  51. ( @MigrationId, @Time, @ExcuteTime );");
  52. conn.Execute(@string.ToString(), new { MigrationId = "Initial_Migration", Time, ExcuteTime = DateTime.Now });
  53. #endregion
  54. }
  55. }
  56. }
  57. }