201907180821556_Init.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. namespace EVCB_OCPP.Domain.MainDBContextMigrations
  2. {
  3. using System;
  4. using System.Data.Entity.Migrations;
  5. public partial class Init : DbMigration
  6. {
  7. public override void Up()
  8. {
  9. CreateTable(
  10. "dbo.ApiLogEntry",
  11. c => new
  12. {
  13. ApiLogEntryId = c.Long(nullable: false, identity: true),
  14. Application = c.String(),
  15. User = c.String(),
  16. Machine = c.String(),
  17. RequestIpAddress = c.String(),
  18. RequestContentType = c.String(),
  19. RequestContentBody = c.String(),
  20. RequestUri = c.String(),
  21. RequestMethod = c.String(),
  22. RequestRouteTemplate = c.String(),
  23. RequestRouteData = c.String(),
  24. RequestHeaders = c.String(),
  25. RequestTimestamp = c.DateTime(),
  26. ResponseContentType = c.String(),
  27. ResponseContentBody = c.String(),
  28. ResponseStatusCode = c.Int(),
  29. ResponseHeaders = c.String(),
  30. ResponseTimestamp = c.DateTime(),
  31. IsOutData = c.Boolean(nullable: false),
  32. ErrorMsg = c.String(),
  33. ErrorOn = c.DateTime(),
  34. })
  35. .PrimaryKey(t => t.ApiLogEntryId)
  36. .Index(t => t.RequestTimestamp);
  37. CreateTable(
  38. "dbo.ConnectorStatus",
  39. c => new
  40. {
  41. Id = c.String(nullable: false, maxLength: 36),
  42. ChargePointSerialNumber = c.String(maxLength: 25),
  43. ConnectorId = c.Byte(nullable: false),
  44. Status = c.Int(nullable: false),
  45. ChargePointErrorCodeNo = c.Int(nullable: false),
  46. ErrorInfo = c.String(maxLength: 50),
  47. VendorId = c.String(maxLength: 255),
  48. VendorErrorCodeNo = c.Int(nullable: false),
  49. CreatedOn = c.DateTime(nullable: false),
  50. })
  51. .PrimaryKey(t => t.Id);
  52. CreateTable(
  53. "dbo.Customer",
  54. c => new
  55. {
  56. Id = c.Guid(nullable: false),
  57. Name = c.String(maxLength: 50),
  58. CreatedOn = c.DateTime(nullable: false),
  59. CreatedBy = c.String(maxLength: 50),
  60. Deadline = c.DateTime(),
  61. UpdatedOn = c.DateTime(),
  62. UpdatedBy = c.String(maxLength: 50),
  63. ApiUrl = c.String(maxLength: 256),
  64. ApiKey = c.String(maxLength: 128),
  65. ApiKeyUpdatedOn = c.DateTime(),
  66. PartnerId = c.String(maxLength: 36),
  67. ApiCustomerId = c.String(maxLength: 36),
  68. CallPartnerApiOnSchedule = c.Boolean(nullable: false),
  69. IsShow = c.Boolean(nullable: false),
  70. })
  71. .PrimaryKey(t => t.Id);
  72. CreateTable(
  73. "dbo.CustomerMachineComponent",
  74. c => new
  75. {
  76. Id = c.Int(nullable: false, identity: true),
  77. CustomerId = c.Guid(nullable: false),
  78. MachineComponentId = c.Int(nullable: false),
  79. CreatedOn = c.DateTime(nullable: false),
  80. CreatedBy = c.String(maxLength: 50),
  81. })
  82. .PrimaryKey(t => t.Id)
  83. .ForeignKey("dbo.Customer", t => t.CustomerId, cascadeDelete: true)
  84. .ForeignKey("dbo.MachineComponent", t => t.MachineComponentId, cascadeDelete: true)
  85. .Index(t => t.CustomerId)
  86. .Index(t => t.MachineComponentId);
  87. CreateTable(
  88. "dbo.MachineComponent",
  89. c => new
  90. {
  91. Id = c.Int(nullable: false, identity: true),
  92. MachineModelId = c.Int(nullable: false),
  93. GunAmt = c.Int(),
  94. MachinePartId = c.Int(nullable: false),
  95. ModelName = c.String(),
  96. })
  97. .PrimaryKey(t => t.Id)
  98. .ForeignKey("dbo.MachineModel", t => t.MachineModelId, cascadeDelete: true)
  99. .ForeignKey("dbo.MachinePart", t => t.MachinePartId, cascadeDelete: true)
  100. .Index(t => t.MachineModelId)
  101. .Index(t => t.MachinePartId);
  102. CreateTable(
  103. "dbo.MachineModel",
  104. c => new
  105. {
  106. Id = c.Int(nullable: false, identity: true),
  107. Name = c.String(maxLength: 36),
  108. })
  109. .PrimaryKey(t => t.Id);
  110. CreateTable(
  111. "dbo.MachinePart",
  112. c => new
  113. {
  114. Id = c.Int(nullable: false),
  115. Desc = c.String(maxLength: 36),
  116. })
  117. .PrimaryKey(t => t.Id);
  118. CreateTable(
  119. "dbo.Machine",
  120. c => new
  121. {
  122. Id = c.String(nullable: false, maxLength: 36),
  123. ChargePointSerialNumber = c.String(maxLength: 25),
  124. ChargeBoxSerialNumber = c.String(maxLength: 25),
  125. ChargePointModel = c.String(maxLength: 20),
  126. ChargePointVendor = c.String(maxLength: 20),
  127. Iccid = c.String(maxLength: 20),
  128. Imsi = c.String(maxLength: 20),
  129. MeterType = c.String(maxLength: 25),
  130. MeterSerialNumber = c.String(maxLength: 25),
  131. CreatedOn = c.DateTime(nullable: false),
  132. CreatedBy = c.String(maxLength: 50),
  133. Comment = c.String(maxLength: 100),
  134. CustomerId = c.Guid(nullable: false),
  135. AC = c.Boolean(nullable: false),
  136. GunAmt = c.Int(nullable: false),
  137. HeartbeatUpdatedOn = c.DateTime(),
  138. FW_VersionReport = c.Int(),
  139. FW_AssignedVersion = c.Int(),
  140. FW_AssignedMachineVersionId = c.Int(),
  141. Online = c.Boolean(nullable: false),
  142. WattId = c.Int(nullable: false),
  143. MachineModelId = c.Int(nullable: false),
  144. MachinePartId = c.Int(nullable: false),
  145. OfflineOn = c.DateTime(),
  146. FW_CurrentVersion = c.String(maxLength: 50),
  147. })
  148. .PrimaryKey(t => t.Id)
  149. .ForeignKey("dbo.Customer", t => t.CustomerId, cascadeDelete: true)
  150. .ForeignKey("dbo.MachineVersion", t => t.FW_AssignedMachineVersionId)
  151. .ForeignKey("dbo.MachineModel", t => t.MachineModelId, cascadeDelete: true)
  152. .ForeignKey("dbo.MachinePart", t => t.MachinePartId, cascadeDelete: true)
  153. .Index(t => t.ChargePointSerialNumber, unique: true)
  154. .Index(t => t.CustomerId)
  155. .Index(t => t.FW_AssignedMachineVersionId)
  156. .Index(t => t.MachineModelId)
  157. .Index(t => t.MachinePartId);
  158. CreateTable(
  159. "dbo.MachineVersion",
  160. c => new
  161. {
  162. Id = c.Int(nullable: false, identity: true),
  163. CreatedOn = c.DateTime(nullable: false),
  164. PublishVersionId = c.Int(nullable: false),
  165. MachineId = c.String(nullable: false, maxLength: 36),
  166. UpdatedOn = c.DateTime(),
  167. })
  168. .PrimaryKey(t => t.Id)
  169. .ForeignKey("dbo.Machine", t => t.MachineId, cascadeDelete: true)
  170. .ForeignKey("dbo.PublishVersion", t => t.PublishVersionId, cascadeDelete: true)
  171. .Index(t => t.PublishVersionId)
  172. .Index(t => t.MachineId);
  173. CreateTable(
  174. "dbo.MachineVersionFile",
  175. c => new
  176. {
  177. Id = c.Int(nullable: false, identity: true),
  178. CreatedOn = c.DateTime(nullable: false),
  179. UpdatedOn = c.DateTime(),
  180. MachineVersionId = c.Int(nullable: false),
  181. UploadFileId = c.Guid(nullable: false),
  182. DownloadedOn = c.DateTime(),
  183. Seq = c.Int(nullable: false),
  184. })
  185. .PrimaryKey(t => t.Id)
  186. .ForeignKey("dbo.MachineVersion", t => t.MachineVersionId, cascadeDelete: true)
  187. .ForeignKey("dbo.UploadFile", t => t.UploadFileId, cascadeDelete: true)
  188. .Index(t => t.MachineVersionId)
  189. .Index(t => t.UploadFileId);
  190. CreateTable(
  191. "dbo.UploadFile",
  192. c => new
  193. {
  194. Id = c.Guid(nullable: false),
  195. FileName = c.String(nullable: false, maxLength: 500),
  196. OriginName = c.String(nullable: false, maxLength: 500),
  197. FileSize = c.Int(nullable: false),
  198. FileType = c.String(maxLength: 200),
  199. FileExtensionName = c.String(maxLength: 50),
  200. FilePath = c.String(nullable: false, maxLength: 500),
  201. CreatedOn = c.DateTime(nullable: false),
  202. CreatedBy = c.String(maxLength: 50),
  203. IsOnline = c.Boolean(nullable: false),
  204. CustomerId = c.Guid(nullable: false),
  205. FileMD5 = c.String(maxLength: 50),
  206. FileUrl = c.String(maxLength: 512),
  207. })
  208. .PrimaryKey(t => t.Id);
  209. CreateTable(
  210. "dbo.PublishVersion",
  211. c => new
  212. {
  213. Id = c.Int(nullable: false, identity: true),
  214. CreatedOn = c.DateTime(nullable: false),
  215. Version = c.Int(nullable: false),
  216. CustomerMachineComponentId = c.Int(nullable: false),
  217. })
  218. .PrimaryKey(t => t.Id)
  219. .ForeignKey("dbo.CustomerMachineComponent", t => t.CustomerMachineComponentId)
  220. .Index(t => t.CustomerMachineComponentId);
  221. CreateTable(
  222. "dbo.PublishVersionFile",
  223. c => new
  224. {
  225. Id = c.Int(nullable: false, identity: true),
  226. PublishVersionId = c.Int(nullable: false),
  227. UploadFileId = c.Guid(nullable: false),
  228. Seq = c.Int(nullable: false),
  229. })
  230. .PrimaryKey(t => t.Id)
  231. .ForeignKey("dbo.PublishVersion", t => t.PublishVersionId, cascadeDelete: true)
  232. .ForeignKey("dbo.UploadFile", t => t.UploadFileId, cascadeDelete: true)
  233. .Index(t => t.PublishVersionId)
  234. .Index(t => t.UploadFileId);
  235. CreateTable(
  236. "dbo.MachineConfigures",
  237. c => new
  238. {
  239. Id = c.Int(nullable: false, identity: true),
  240. ChargePointSerialNumber = c.String(maxLength: 25),
  241. ConfigureName = c.String(maxLength: 50),
  242. ConfigureSetting = c.String(maxLength: 500),
  243. })
  244. .PrimaryKey(t => t.Id);
  245. CreateTable(
  246. "dbo.MachineError",
  247. c => new
  248. {
  249. Id = c.Int(nullable: false, identity: true),
  250. ChargePointSerialNumber = c.String(maxLength: 25),
  251. ConnectorId = c.Byte(nullable: false),
  252. PreStatus = c.Int(nullable: false),
  253. Status = c.Int(nullable: false),
  254. ErrorCode = c.Int(nullable: false),
  255. ErrorInfo = c.String(maxLength: 50),
  256. VendorId = c.String(maxLength: 255),
  257. VendorErrorCodeNum = c.Int(nullable: false),
  258. CreatedOn = c.DateTime(nullable: false),
  259. })
  260. .PrimaryKey(t => t.Id);
  261. CreateTable(
  262. "dbo.MachineOperateRecord",
  263. c => new
  264. {
  265. Id = c.Int(nullable: false, identity: true),
  266. ChargePointSerialNumber = c.String(maxLength: 25),
  267. SerialNo = c.String(maxLength: 36),
  268. RequestType = c.Int(nullable: false),
  269. RequestContent = c.String(maxLength: 36),
  270. Status = c.Int(nullable: false),
  271. CreatedOn = c.DateTime(nullable: false),
  272. FinishedOn = c.DateTime(nullable: false),
  273. })
  274. .PrimaryKey(t => t.Id);
  275. CreateTable(
  276. "dbo.ServerMessage",
  277. c => new
  278. {
  279. Id = c.Int(nullable: false, identity: true),
  280. ChargePointSerialNumber = c.String(maxLength: 25),
  281. SerialNo = c.String(maxLength: 36),
  282. OutAction = c.String(),
  283. OutRequest = c.String(),
  284. InMessage = c.String(),
  285. CreatedOn = c.DateTime(nullable: false),
  286. CreatedBy = c.String(),
  287. ReceivedOn = c.DateTime(),
  288. })
  289. .PrimaryKey(t => t.Id);
  290. CreateTable(
  291. "dbo.TransactionRecord",
  292. c => new
  293. {
  294. Id = c.Long(nullable: false, identity: true),
  295. CustomerId = c.Guid(nullable: false),
  296. MachineId = c.String(nullable: false, maxLength: 36),
  297. ConnectorId = c.Byte(nullable: false),
  298. TransactionId = c.Int(nullable: false),
  299. chargePointSerialNumber = c.String(maxLength: 25),
  300. IdTag = c.String(maxLength: 20),
  301. StartTime = c.DateTime(nullable: false),
  302. StopTime = c.DateTime(nullable: false),
  303. StopTransactionReasonId = c.Int(nullable: false),
  304. MeterStart = c.Decimal(nullable: false, precision: 18, scale: 2),
  305. MeterStop = c.Decimal(nullable: false, precision: 18, scale: 2),
  306. SOCStart = c.Decimal(nullable: false, precision: 18, scale: 2),
  307. SOCStop = c.Decimal(nullable: false, precision: 18, scale: 2),
  308. ReportedOn = c.DateTime(),
  309. CreatedOn = c.DateTime(nullable: false),
  310. UpdatedOn = c.DateTime(),
  311. StartTransactionReportedOn = c.DateTime(nullable: false),
  312. RetryStartTransactionTimes = c.Int(nullable: false),
  313. StopTransactionReportedOn = c.DateTime(nullable: false),
  314. RtryStopTransactionTimes = c.Int(nullable: false),
  315. ErrorMsg = c.String(),
  316. })
  317. .PrimaryKey(t => t.Id)
  318. .ForeignKey("dbo.Machine", t => t.MachineId, cascadeDelete: true)
  319. .Index(t => new { t.MachineId, t.ConnectorId, t.TransactionId, t.StartTime }, unique: true, name: "IX_1202_Issue_Report")
  320. .Index(t => t.MachineId)
  321. .Index(t => t.TransactionId);
  322. }
  323. public override void Down()
  324. {
  325. DropForeignKey("dbo.TransactionRecord", "MachineId", "dbo.Machine");
  326. DropForeignKey("dbo.Machine", "MachinePartId", "dbo.MachinePart");
  327. DropForeignKey("dbo.Machine", "MachineModelId", "dbo.MachineModel");
  328. DropForeignKey("dbo.Machine", "FW_AssignedMachineVersionId", "dbo.MachineVersion");
  329. DropForeignKey("dbo.MachineVersion", "PublishVersionId", "dbo.PublishVersion");
  330. DropForeignKey("dbo.PublishVersionFile", "UploadFileId", "dbo.UploadFile");
  331. DropForeignKey("dbo.PublishVersionFile", "PublishVersionId", "dbo.PublishVersion");
  332. DropForeignKey("dbo.PublishVersion", "CustomerMachineComponentId", "dbo.CustomerMachineComponent");
  333. DropForeignKey("dbo.MachineVersionFile", "UploadFileId", "dbo.UploadFile");
  334. DropForeignKey("dbo.MachineVersionFile", "MachineVersionId", "dbo.MachineVersion");
  335. DropForeignKey("dbo.MachineVersion", "MachineId", "dbo.Machine");
  336. DropForeignKey("dbo.Machine", "CustomerId", "dbo.Customer");
  337. DropForeignKey("dbo.CustomerMachineComponent", "MachineComponentId", "dbo.MachineComponent");
  338. DropForeignKey("dbo.MachineComponent", "MachinePartId", "dbo.MachinePart");
  339. DropForeignKey("dbo.MachineComponent", "MachineModelId", "dbo.MachineModel");
  340. DropForeignKey("dbo.CustomerMachineComponent", "CustomerId", "dbo.Customer");
  341. DropIndex("dbo.TransactionRecord", new[] { "TransactionId" });
  342. DropIndex("dbo.TransactionRecord", new[] { "MachineId" });
  343. DropIndex("dbo.TransactionRecord", "IX_1202_Issue_Report");
  344. DropIndex("dbo.PublishVersionFile", new[] { "UploadFileId" });
  345. DropIndex("dbo.PublishVersionFile", new[] { "PublishVersionId" });
  346. DropIndex("dbo.PublishVersion", new[] { "CustomerMachineComponentId" });
  347. DropIndex("dbo.MachineVersionFile", new[] { "UploadFileId" });
  348. DropIndex("dbo.MachineVersionFile", new[] { "MachineVersionId" });
  349. DropIndex("dbo.MachineVersion", new[] { "MachineId" });
  350. DropIndex("dbo.MachineVersion", new[] { "PublishVersionId" });
  351. DropIndex("dbo.Machine", new[] { "MachinePartId" });
  352. DropIndex("dbo.Machine", new[] { "MachineModelId" });
  353. DropIndex("dbo.Machine", new[] { "FW_AssignedMachineVersionId" });
  354. DropIndex("dbo.Machine", new[] { "CustomerId" });
  355. DropIndex("dbo.Machine", new[] { "ChargePointSerialNumber" });
  356. DropIndex("dbo.MachineComponent", new[] { "MachinePartId" });
  357. DropIndex("dbo.MachineComponent", new[] { "MachineModelId" });
  358. DropIndex("dbo.CustomerMachineComponent", new[] { "MachineComponentId" });
  359. DropIndex("dbo.CustomerMachineComponent", new[] { "CustomerId" });
  360. DropIndex("dbo.ApiLogEntry", new[] { "RequestTimestamp" });
  361. DropTable("dbo.TransactionRecord");
  362. DropTable("dbo.ServerMessage");
  363. DropTable("dbo.MachineOperateRecord");
  364. DropTable("dbo.MachineError");
  365. DropTable("dbo.MachineConfigures");
  366. DropTable("dbo.PublishVersionFile");
  367. DropTable("dbo.PublishVersion");
  368. DropTable("dbo.UploadFile");
  369. DropTable("dbo.MachineVersionFile");
  370. DropTable("dbo.MachineVersion");
  371. DropTable("dbo.Machine");
  372. DropTable("dbo.MachinePart");
  373. DropTable("dbo.MachineModel");
  374. DropTable("dbo.MachineComponent");
  375. DropTable("dbo.CustomerMachineComponent");
  376. DropTable("dbo.Customer");
  377. DropTable("dbo.ConnectorStatus");
  378. DropTable("dbo.ApiLogEntry");
  379. }
  380. }
  381. }