20200701155000_BusinessModel.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. using System;
  2. using Microsoft.EntityFrameworkCore.Metadata;
  3. using Microsoft.EntityFrameworkCore.Migrations;
  4. namespace GreenTree.Strohrmann.ERP.Domain.Migrations
  5. {
  6. public partial class BusinessModel : Migration
  7. {
  8. protected override void Up(MigrationBuilder migrationBuilder)
  9. {
  10. migrationBuilder.CreateTable(
  11. name: "EmployeeDegrees",
  12. columns: table => new
  13. {
  14. Id = table.Column<int>(nullable: false)
  15. .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
  16. Name = table.Column<string>(nullable: false),
  17. Value = table.Column<decimal>(nullable: false),
  18. Order = table.Column<int>(nullable: false)
  19. },
  20. constraints: table =>
  21. {
  22. table.PrimaryKey("PK_EmployeeDegrees", x => x.Id);
  23. });
  24. migrationBuilder.CreateTable(
  25. name: "Suppliers",
  26. columns: table => new
  27. {
  28. Id = table.Column<int>(nullable: false)
  29. .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
  30. Name = table.Column<string>(nullable: false),
  31. Description = table.Column<string>(nullable: true),
  32. Address = table.Column<string>(nullable: false),
  33. Town = table.Column<string>(nullable: false),
  34. ZipCode = table.Column<string>(nullable: false),
  35. Country = table.Column<string>(nullable: false),
  36. PhoneFirst = table.Column<string>(nullable: true),
  37. PhoneSecond = table.Column<string>(nullable: true),
  38. MailFirst = table.Column<string>(nullable: true),
  39. MailSecond = table.Column<string>(nullable: true),
  40. Comment = table.Column<string>(nullable: true)
  41. },
  42. constraints: table =>
  43. {
  44. table.PrimaryKey("PK_Suppliers", x => x.Id);
  45. });
  46. migrationBuilder.CreateTable(
  47. name: "Taxes",
  48. columns: table => new
  49. {
  50. Id = table.Column<int>(nullable: false)
  51. .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
  52. Name = table.Column<string>(nullable: false),
  53. ShortName = table.Column<string>(nullable: false),
  54. Value = table.Column<decimal>(nullable: false)
  55. },
  56. constraints: table =>
  57. {
  58. table.PrimaryKey("PK_Taxes", x => x.Id);
  59. });
  60. migrationBuilder.CreateTable(
  61. name: "Units",
  62. columns: table => new
  63. {
  64. Id = table.Column<int>(nullable: false)
  65. .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
  66. Name = table.Column<string>(nullable: false),
  67. ShortName = table.Column<string>(nullable: false),
  68. Description = table.Column<string>(nullable: true)
  69. },
  70. constraints: table =>
  71. {
  72. table.PrimaryKey("PK_Units", x => x.Id);
  73. });
  74. migrationBuilder.CreateTable(
  75. name: "Employees",
  76. columns: table => new
  77. {
  78. Id = table.Column<int>(nullable: false)
  79. .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
  80. Firstname = table.Column<string>(nullable: false),
  81. Lastname = table.Column<string>(nullable: false),
  82. MailAddress = table.Column<string>(nullable: true),
  83. Birthdate = table.Column<DateTime>(nullable: true),
  84. EmployeeDegreeId = table.Column<int>(nullable: false)
  85. },
  86. constraints: table =>
  87. {
  88. table.PrimaryKey("PK_Employees", x => x.Id);
  89. table.ForeignKey(
  90. name: "FK_Employees_EmployeeDegrees_EmployeeDegreeId",
  91. column: x => x.EmployeeDegreeId,
  92. principalTable: "EmployeeDegrees",
  93. principalColumn: "Id",
  94. onDelete: ReferentialAction.Restrict);
  95. });
  96. migrationBuilder.CreateTable(
  97. name: "Customers",
  98. columns: table => new
  99. {
  100. Id = table.Column<int>(nullable: false)
  101. .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
  102. Firstname = table.Column<string>(nullable: false),
  103. Lastname = table.Column<string>(nullable: false),
  104. CompanyName = table.Column<string>(nullable: true),
  105. Address = table.Column<string>(nullable: false),
  106. Town = table.Column<string>(nullable: false),
  107. ZipCode = table.Column<string>(nullable: false),
  108. Country = table.Column<string>(nullable: false),
  109. TaxId = table.Column<int>(nullable: false)
  110. },
  111. constraints: table =>
  112. {
  113. table.PrimaryKey("PK_Customers", x => x.Id);
  114. table.ForeignKey(
  115. name: "FK_Customers_Taxes_TaxId",
  116. column: x => x.TaxId,
  117. principalTable: "Taxes",
  118. principalColumn: "Id",
  119. onDelete: ReferentialAction.Restrict);
  120. });
  121. migrationBuilder.CreateTable(
  122. name: "Materials",
  123. columns: table => new
  124. {
  125. Id = table.Column<int>(nullable: false)
  126. .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
  127. Name = table.Column<string>(nullable: false),
  128. ItemNumber = table.Column<string>(nullable: false),
  129. Description = table.Column<string>(nullable: false),
  130. NetValue = table.Column<decimal>(nullable: false),
  131. Height = table.Column<decimal>(nullable: false),
  132. Width = table.Column<decimal>(nullable: false),
  133. Depth = table.Column<decimal>(nullable: false),
  134. DefaultUnitId = table.Column<int>(nullable: false),
  135. SupplierId = table.Column<int>(nullable: false)
  136. },
  137. constraints: table =>
  138. {
  139. table.PrimaryKey("PK_Materials", x => x.Id);
  140. table.ForeignKey(
  141. name: "FK_Materials_Units_DefaultUnitId",
  142. column: x => x.DefaultUnitId,
  143. principalTable: "Units",
  144. principalColumn: "Id",
  145. onDelete: ReferentialAction.Restrict);
  146. table.ForeignKey(
  147. name: "FK_Materials_Suppliers_SupplierId",
  148. column: x => x.SupplierId,
  149. principalTable: "Suppliers",
  150. principalColumn: "Id",
  151. onDelete: ReferentialAction.Restrict);
  152. });
  153. migrationBuilder.CreateTable(
  154. name: "Crafts",
  155. columns: table => new
  156. {
  157. Id = table.Column<int>(nullable: false)
  158. .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
  159. Name = table.Column<string>(nullable: false),
  160. CreationDate = table.Column<DateTime>(nullable: false),
  161. CustomerId = table.Column<int>(nullable: false)
  162. },
  163. constraints: table =>
  164. {
  165. table.PrimaryKey("PK_Crafts", x => x.Id);
  166. table.ForeignKey(
  167. name: "FK_Crafts_Customers_CustomerId",
  168. column: x => x.CustomerId,
  169. principalTable: "Customers",
  170. principalColumn: "Id",
  171. onDelete: ReferentialAction.Restrict);
  172. });
  173. migrationBuilder.CreateTable(
  174. name: "CraftEmployees",
  175. columns: table => new
  176. {
  177. CraftId = table.Column<int>(nullable: false),
  178. EmployeeId = table.Column<int>(nullable: false),
  179. Amount = table.Column<decimal>(nullable: false)
  180. },
  181. constraints: table =>
  182. {
  183. table.PrimaryKey("PK_CraftEmployees", x => new { x.CraftId, x.EmployeeId });
  184. table.ForeignKey(
  185. name: "FK_CraftEmployees_Crafts_CraftId",
  186. column: x => x.CraftId,
  187. principalTable: "Crafts",
  188. principalColumn: "Id",
  189. onDelete: ReferentialAction.Cascade);
  190. table.ForeignKey(
  191. name: "FK_CraftEmployees_Employees_EmployeeId",
  192. column: x => x.EmployeeId,
  193. principalTable: "Employees",
  194. principalColumn: "Id",
  195. onDelete: ReferentialAction.Cascade);
  196. });
  197. migrationBuilder.CreateTable(
  198. name: "CraftMaterials",
  199. columns: table => new
  200. {
  201. CraftId = table.Column<int>(nullable: false),
  202. MaterialId = table.Column<int>(nullable: false),
  203. Amount = table.Column<decimal>(nullable: false)
  204. },
  205. constraints: table =>
  206. {
  207. table.PrimaryKey("PK_CraftMaterials", x => new { x.CraftId, x.MaterialId });
  208. table.ForeignKey(
  209. name: "FK_CraftMaterials_Crafts_CraftId",
  210. column: x => x.CraftId,
  211. principalTable: "Crafts",
  212. principalColumn: "Id",
  213. onDelete: ReferentialAction.Cascade);
  214. table.ForeignKey(
  215. name: "FK_CraftMaterials_Materials_MaterialId",
  216. column: x => x.MaterialId,
  217. principalTable: "Materials",
  218. principalColumn: "Id",
  219. onDelete: ReferentialAction.Cascade);
  220. });
  221. migrationBuilder.InsertData(
  222. table: "Taxes",
  223. columns: new[] { "Id", "Name", "ShortName", "Value" },
  224. values: new object[,]
  225. {
  226. { 1, "Deutschland Umsatzsteuer", "Umst. (19%)", 0.19m },
  227. { 2, "Deutschland Umsatzsteuer 2020", "Umst. (16%) 2020", 0.16m }
  228. });
  229. migrationBuilder.InsertData(
  230. table: "Units",
  231. columns: new[] { "Id", "Description", "Name", "ShortName" },
  232. values: new object[,]
  233. {
  234. { 1, "Angabe in Einheit Meter", "Meter", "m" },
  235. { 2, "Angabe in Einheit Quadratmeter", "Quadratmeter", "m²" },
  236. { 3, "Angabe in Einheit Kubikmeter", "Kubikmeter", "m³" },
  237. { 4, "Angabe in Einheit Liter", "Liter", "l" },
  238. { 5, "Angabe in Stückzahl", "Stück", "Stck." },
  239. { 6, "Angabe in Stückzahl", "Kilogramm", "Kg" },
  240. { 7, "Angabe in Zeitstunden", "Stunden", "Std." }
  241. });
  242. migrationBuilder.CreateIndex(
  243. name: "IX_CraftEmployees_EmployeeId",
  244. table: "CraftEmployees",
  245. column: "EmployeeId");
  246. migrationBuilder.CreateIndex(
  247. name: "IX_CraftMaterials_MaterialId",
  248. table: "CraftMaterials",
  249. column: "MaterialId");
  250. migrationBuilder.CreateIndex(
  251. name: "IX_Crafts_CustomerId",
  252. table: "Crafts",
  253. column: "CustomerId");
  254. migrationBuilder.CreateIndex(
  255. name: "IX_Customers_TaxId",
  256. table: "Customers",
  257. column: "TaxId");
  258. migrationBuilder.CreateIndex(
  259. name: "IX_Employees_EmployeeDegreeId",
  260. table: "Employees",
  261. column: "EmployeeDegreeId");
  262. migrationBuilder.CreateIndex(
  263. name: "IX_Materials_DefaultUnitId",
  264. table: "Materials",
  265. column: "DefaultUnitId");
  266. migrationBuilder.CreateIndex(
  267. name: "IX_Materials_SupplierId",
  268. table: "Materials",
  269. column: "SupplierId");
  270. }
  271. protected override void Down(MigrationBuilder migrationBuilder)
  272. {
  273. migrationBuilder.DropTable(
  274. name: "CraftEmployees");
  275. migrationBuilder.DropTable(
  276. name: "CraftMaterials");
  277. migrationBuilder.DropTable(
  278. name: "Employees");
  279. migrationBuilder.DropTable(
  280. name: "Crafts");
  281. migrationBuilder.DropTable(
  282. name: "Materials");
  283. migrationBuilder.DropTable(
  284. name: "EmployeeDegrees");
  285. migrationBuilder.DropTable(
  286. name: "Customers");
  287. migrationBuilder.DropTable(
  288. name: "Units");
  289. migrationBuilder.DropTable(
  290. name: "Suppliers");
  291. migrationBuilder.DropTable(
  292. name: "Taxes");
  293. }
  294. }
  295. }