Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

CreateFuelEntry.swift 4.9 KiB

3 лет назад
​
3 лет назад
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
3 лет назад
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 лет назад
​
​
​
​
​
​
​
​
​
​
​
​
​
2 недель назад
​
​
​
​
​
​
​
​
​
​
​
​
​
2 недель назад
​
2 недель назад
​
​
​
​
​
​
​
​
2 недель назад
​
​
​
2 недель назад
​
2 недель назад
​
​
​
1 месяц назад
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. //
  2. // File.swift
  3. //
  4. //
  5. // Created by Bill Ryckman on 4/26/23.
  6. //
  7. import Vapor
  8. import Fluent
  9. struct CreateFuelEntry: AsyncMigration {
  10. func prepare(on database: Database) async throws {
  11. try await database.schema("fuel_entries")
  12. .id()
  13. .field("timestamp", .datetime)
  14. .field("user_id", .string)
  15. .field("gps_location", .string)
  16. .field("image", .string)
  17. .field("product", .string)
  18. .field("make", .string)
  19. .field("model", .string)
  20. .field("serial_number", .string)
  21. .field("tank_id", .string)
  22. .field("fuel_amount", .double)
  23. .field("fuel_type", .string)
  24. .field("is_override", .bool)
  25. .create()
  26. }
  27. func revert(on database: Database) async throws {
  28. try await database.schema("fuel_entries").delete()
  29. }
  30. }
  31. struct AddLatitudeAndLongitudeAndRemoveGpsLocationAndImage: AsyncMigration {
  32. func prepare(on database: Database) async throws {
  33. try await database.schema("fuel_entries")
  34. .field("latitude", .double)
  35. .field("longitude", .double)
  36. .deleteField("gps_location")
  37. .deleteField("image")
  38. .update()
  39. }
  40. func revert(on database: Database) async throws {
  41. try await database.schema("fuel_entries")
  42. .deleteField("latitude")
  43. .deleteField("longitude")
  44. .field("gps_location", .string)
  45. .field("image", .string)
  46. .update()
  47. }
  48. }
  49. struct AddImageBackIn: AsyncMigration {
  50. func prepare(on database: Database) async throws {
  51. try await database.schema("fuel_entries")
  52. .field("image", .string)
  53. .update()
  54. }
  55. func revert(on database: Database) async throws {
  56. try await database.schema("fuel_entries")
  57. .deleteField("image")
  58. .update()
  59. }
  60. }
  61. struct StoreImageDataInDatabase: AsyncMigration {
  62. func prepare(on database: Database) async throws {
  63. try await database.schema("fuel_entries")
  64. .deleteField("image")
  65. .field("image", .data)
  66. .update()
  67. }
  68. func revert(on database: Database) async throws {
  69. try await database.schema("fuel_entries")
  70. .deleteField("image")
  71. .field("image", .string)
  72. .update()
  73. }
  74. }
  75. struct AddDownloadedBool: AsyncMigration {
  76. func prepare(on database: Database) async throws {
  77. try await database.schema("fuel_entries")
  78. .field("downloaded", .bool)
  79. .update()
  80. }
  81. func revert(on database: Database) async throws {
  82. try await database.schema("fuel_entries")
  83. .deleteField("downloaded")
  84. .update()
  85. }
  86. }
  87. struct AddUniqueIDFiled: AsyncMigration {
  88. func prepare(on database: Database) async throws {
  89. try await database.schema("fuel_entries")
  90. .field("unique_id", .uuid)
  91. .update()
  92. }
  93. func revert(on database: Database) async throws {
  94. try await database.schema("fuel_entries")
  95. .deleteField("unique_id")
  96. .update()
  97. }
  98. }
  99. struct ChangeUniqueIDFiled: AsyncMigration {
  100. func prepare(on database: Database) async throws {
  101. do {
  102. try await database.schema("fuel_entries")
  103. .deleteField("unique_id")
  104. .field("unique_id", .string)
  105. .update()
  106. } catch {
  107. throw error
  108. }
  109. }
  110. func revert(on database: Database) async throws {
  111. try await database.schema("fuel_entries")
  112. .deleteField("unique_id")
  113. .field("unique_id", .uuid)
  114. .update()
  115. }
  116. }
  117. struct AddAppVersion: AsyncMigration {
  118. func prepare(on database: Database) async throws {
  119. try await database.schema("fuel_entries")
  120. .field("app_version", .string)
  121. .update()
  122. }
  123. func revert(on database: Database) async throws {
  124. try await database.schema("fuel_entries")
  125. .deleteField("app_version")
  126. .update()
  127. }
  128. }
  129. struct AddLoadDateAndPullDate: AsyncMigration {
  130. func prepare(on database: Database) async throws {
  131. try await database.schema("fuel_entries")
  132. .field("loadDate", .datetime)
  133. .field("pullDate", .datetime)
  134. .update()
  135. }
  136. func revert(on database: Database) async throws {
  137. try await database.schema("fuel_entries")
  138. .deleteField("loadDate")
  139. .deleteField("pullDate")
  140. .update()
  141. }
  142. }
  143. struct AddDeviceSerial: AsyncMigration {
  144. func prepare(on database: Database) async throws {
  145. try await database.schema("fuel_entries")
  146. .field("tablet_serial", .string)
  147. .update()
  148. }
  149. func revert(on database: Database) async throws {
  150. try await database.schema("fuel_entries")
  151. .deleteField("tablet_serial")
  152. .update()
  153. }
  154. }