You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20230729134748_Category.cs 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. using System;
  2. using Microsoft.EntityFrameworkCore.Migrations;
  3. namespace Karsha_Site.Persistance.Migrations
  4. {
  5. public partial class Category : Migration
  6. {
  7. protected override void Up(MigrationBuilder migrationBuilder)
  8. {
  9. migrationBuilder.CreateTable(
  10. name: "Categories",
  11. columns: table => new
  12. {
  13. ID = table.Column<int>(type: "int", nullable: false)
  14. .Annotation("SqlServer:Identity", "1, 1"),
  15. Title = table.Column<string>(type: "nvarchar(max)", nullable: true),
  16. Image = table.Column<string>(type: "nvarchar(max)", nullable: true),
  17. ParentCategoryID = table.Column<int>(type: "int", nullable: true),
  18. InsertTime = table.Column<DateTime>(type: "datetime2", nullable: false),
  19. UpdateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
  20. IsRemoved = table.Column<bool>(type: "bit", nullable: false),
  21. RemoveTime = table.Column<DateTime>(type: "datetime2", nullable: true)
  22. },
  23. constraints: table =>
  24. {
  25. table.PrimaryKey("PK_Categories", x => x.ID);
  26. table.ForeignKey(
  27. name: "FK_Categories_Categories_ParentCategoryID",
  28. column: x => x.ParentCategoryID,
  29. principalTable: "Categories",
  30. principalColumn: "ID",
  31. onDelete: ReferentialAction.Restrict);
  32. });
  33. migrationBuilder.CreateTable(
  34. name: "Products",
  35. columns: table => new
  36. {
  37. ID = table.Column<int>(type: "int", nullable: false)
  38. .Annotation("SqlServer:Identity", "1, 1"),
  39. Name = table.Column<string>(type: "nvarchar(max)", nullable: true),
  40. Brand = table.Column<string>(type: "nvarchar(max)", nullable: true),
  41. Description = table.Column<string>(type: "nvarchar(max)", nullable: true),
  42. Price = table.Column<int>(type: "int", nullable: false),
  43. Inventory = table.Column<int>(type: "int", nullable: false),
  44. Displayed = table.Column<bool>(type: "bit", nullable: false),
  45. ViewCount = table.Column<int>(type: "int", nullable: false),
  46. CategoryID = table.Column<int>(type: "int", nullable: false),
  47. InsertTime = table.Column<DateTime>(type: "datetime2", nullable: false),
  48. UpdateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
  49. IsRemoved = table.Column<bool>(type: "bit", nullable: false),
  50. RemoveTime = table.Column<DateTime>(type: "datetime2", nullable: true)
  51. },
  52. constraints: table =>
  53. {
  54. table.PrimaryKey("PK_Products", x => x.ID);
  55. table.ForeignKey(
  56. name: "FK_Products_Categories_CategoryID",
  57. column: x => x.CategoryID,
  58. principalTable: "Categories",
  59. principalColumn: "ID",
  60. onDelete: ReferentialAction.Cascade);
  61. });
  62. migrationBuilder.CreateTable(
  63. name: "ProductFeatures",
  64. columns: table => new
  65. {
  66. ID = table.Column<int>(type: "int", nullable: false)
  67. .Annotation("SqlServer:Identity", "1, 1"),
  68. ProductID = table.Column<int>(type: "int", nullable: false),
  69. DisplayName = table.Column<string>(type: "nvarchar(max)", nullable: true),
  70. Value = table.Column<string>(type: "nvarchar(max)", nullable: true),
  71. InsertTime = table.Column<DateTime>(type: "datetime2", nullable: false),
  72. UpdateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
  73. IsRemoved = table.Column<bool>(type: "bit", nullable: false),
  74. RemoveTime = table.Column<DateTime>(type: "datetime2", nullable: true)
  75. },
  76. constraints: table =>
  77. {
  78. table.PrimaryKey("PK_ProductFeatures", x => x.ID);
  79. table.ForeignKey(
  80. name: "FK_ProductFeatures_Products_ProductID",
  81. column: x => x.ProductID,
  82. principalTable: "Products",
  83. principalColumn: "ID",
  84. onDelete: ReferentialAction.Cascade);
  85. });
  86. migrationBuilder.CreateTable(
  87. name: "ProductImages",
  88. columns: table => new
  89. {
  90. ID = table.Column<int>(type: "int", nullable: false)
  91. .Annotation("SqlServer:Identity", "1, 1"),
  92. ProductID = table.Column<int>(type: "int", nullable: false),
  93. Src = table.Column<string>(type: "nvarchar(max)", nullable: true),
  94. InsertTime = table.Column<DateTime>(type: "datetime2", nullable: false),
  95. UpdateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
  96. IsRemoved = table.Column<bool>(type: "bit", nullable: false),
  97. RemoveTime = table.Column<DateTime>(type: "datetime2", nullable: true)
  98. },
  99. constraints: table =>
  100. {
  101. table.PrimaryKey("PK_ProductImages", x => x.ID);
  102. table.ForeignKey(
  103. name: "FK_ProductImages_Products_ProductID",
  104. column: x => x.ProductID,
  105. principalTable: "Products",
  106. principalColumn: "ID",
  107. onDelete: ReferentialAction.Cascade);
  108. });
  109. migrationBuilder.CreateIndex(
  110. name: "IX_Categories_ParentCategoryID",
  111. table: "Categories",
  112. column: "ParentCategoryID");
  113. migrationBuilder.CreateIndex(
  114. name: "IX_ProductFeatures_ProductID",
  115. table: "ProductFeatures",
  116. column: "ProductID");
  117. migrationBuilder.CreateIndex(
  118. name: "IX_ProductImages_ProductID",
  119. table: "ProductImages",
  120. column: "ProductID");
  121. migrationBuilder.CreateIndex(
  122. name: "IX_Products_CategoryID",
  123. table: "Products",
  124. column: "CategoryID");
  125. }
  126. protected override void Down(MigrationBuilder migrationBuilder)
  127. {
  128. migrationBuilder.DropTable(
  129. name: "ProductFeatures");
  130. migrationBuilder.DropTable(
  131. name: "ProductImages");
  132. migrationBuilder.DropTable(
  133. name: "Products");
  134. migrationBuilder.DropTable(
  135. name: "Categories");
  136. }
  137. }
  138. }