using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable #pragma warning disable CA1814 // Prefer jagged arrays over multidimensional namespace Imprink.Infrastructure.Migrations { /// public partial class InitialSetup : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "Categories", columns: table => new { Id = table.Column(type: "uniqueidentifier", nullable: false, defaultValueSql: "NEWID()"), Name = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: false), Description = table.Column(type: "nvarchar(2000)", maxLength: 2000, nullable: false), ImageUrl = table.Column(type: "nvarchar(500)", maxLength: 500, nullable: true), SortOrder = table.Column(type: "int", nullable: false, defaultValue: 0), IsActive = table.Column(type: "bit", nullable: false, defaultValue: true), ParentCategoryId = table.Column(type: "uniqueidentifier", nullable: true), CreatedAt = table.Column(type: "datetime2", nullable: true), ModifiedAt = table.Column(type: "datetime2", nullable: true, defaultValueSql: "GETUTCDATE()"), CreatedBy = table.Column(type: "nvarchar(450)", maxLength: 450, nullable: true), ModifiedBy = table.Column(type: "nvarchar(450)", maxLength: 450, nullable: true) }, constraints: table => { table.PrimaryKey("PK_Categories", x => x.Id); table.ForeignKey( name: "FK_Categories_Categories_ParentCategoryId", column: x => x.ParentCategoryId, principalTable: "Categories", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "OrderStatuses", columns: table => new { Id = table.Column(type: "int", nullable: false), Name = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false) }, constraints: table => { table.PrimaryKey("PK_OrderStatuses", x => x.Id); }); migrationBuilder.CreateTable( name: "Roles", columns: table => new { Id = table.Column(type: "uniqueidentifier", nullable: false), RoleName = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false) }, constraints: table => { table.PrimaryKey("PK_Roles", x => x.Id); }); migrationBuilder.CreateTable( name: "ShippingStatuses", columns: table => new { Id = table.Column(type: "int", nullable: false), Name = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false) }, constraints: table => { table.PrimaryKey("PK_ShippingStatuses", x => x.Id); }); migrationBuilder.CreateTable( name: "Users", columns: table => new { Id = table.Column(type: "nvarchar(450)", maxLength: 450, nullable: false), Name = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false), Nickname = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false), Email = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: false), EmailVerified = table.Column(type: "bit", maxLength: 100, nullable: false), FirstName = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: true), LastName = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: true), PhoneNumber = table.Column(type: "nvarchar(20)", maxLength: 20, nullable: true), IsActive = table.Column(type: "bit", nullable: false, defaultValue: true) }, constraints: table => { table.PrimaryKey("PK_Users", x => x.Id); }); migrationBuilder.CreateTable( name: "Products", columns: table => new { Id = table.Column(type: "uniqueidentifier", nullable: false, defaultValueSql: "NEWID()"), Name = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: false), Description = table.Column(type: "nvarchar(2000)", maxLength: 2000, nullable: true), BasePrice = table.Column(type: "decimal(18,2)", nullable: false), IsCustomizable = table.Column(type: "bit", nullable: false, defaultValue: false), IsActive = table.Column(type: "bit", nullable: false, defaultValue: true), ImageUrl = table.Column(type: "nvarchar(500)", maxLength: 500, nullable: true), CategoryId = table.Column(type: "uniqueidentifier", nullable: true), CreatedAt = table.Column(type: "datetime2", nullable: true), ModifiedAt = table.Column(type: "datetime2", nullable: true, defaultValueSql: "GETUTCDATE()"), CreatedBy = table.Column(type: "nvarchar(450)", maxLength: 450, nullable: true), ModifiedBy = table.Column(type: "nvarchar(450)", maxLength: 450, nullable: true) }, constraints: table => { table.PrimaryKey("PK_Products", x => x.Id); table.ForeignKey( name: "FK_Products_Categories_CategoryId", column: x => x.CategoryId, principalTable: "Categories", principalColumn: "Id", onDelete: ReferentialAction.SetNull); }); migrationBuilder.CreateTable( name: "Addresses", columns: table => new { Id = table.Column(type: "uniqueidentifier", nullable: false, defaultValueSql: "NEWID()"), UserId = table.Column(type: "nvarchar(450)", maxLength: 450, nullable: false), AddressType = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false), Street = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: false), City = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false), State = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false), PostalCode = table.Column(type: "nvarchar(20)", maxLength: 20, nullable: false), Country = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false), IsDefault = table.Column(type: "bit", nullable: false, defaultValue: false), IsActive = table.Column(type: "bit", nullable: false, defaultValue: true), CreatedAt = table.Column(type: "datetime2", nullable: false), ModifiedAt = table.Column(type: "datetime2", nullable: false, defaultValueSql: "GETUTCDATE()"), CreatedBy = table.Column(type: "nvarchar(450)", maxLength: 450, nullable: false), ModifiedBy = table.Column(type: "nvarchar(450)", maxLength: 450, nullable: false) }, constraints: table => { table.PrimaryKey("PK_Addresses", x => x.Id); table.ForeignKey( name: "FK_Addresses_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Orders", columns: table => new { Id = table.Column(type: "uniqueidentifier", nullable: false, defaultValueSql: "NEWID()"), UserId = table.Column(type: "nvarchar(450)", maxLength: 450, nullable: false), OrderDate = table.Column(type: "datetime2", nullable: false), TotalPrice = table.Column(type: "decimal(18,2)", nullable: false), OrderStatusId = table.Column(type: "int", nullable: false), ShippingStatusId = table.Column(type: "int", nullable: false), OrderNumber = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false), Notes = table.Column(type: "nvarchar(1000)", maxLength: 1000, nullable: false), CreatedAt = table.Column(type: "datetime2", nullable: false), ModifiedAt = table.Column(type: "datetime2", nullable: false, defaultValueSql: "GETUTCDATE()"), CreatedBy = table.Column(type: "nvarchar(450)", maxLength: 450, nullable: false), ModifiedBy = table.Column(type: "nvarchar(450)", maxLength: 450, nullable: false) }, constraints: table => { table.PrimaryKey("PK_Orders", x => x.Id); table.ForeignKey( name: "FK_Orders_OrderStatuses_OrderStatusId", column: x => x.OrderStatusId, principalTable: "OrderStatuses", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_Orders_ShippingStatuses_ShippingStatusId", column: x => x.ShippingStatusId, principalTable: "ShippingStatuses", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_Orders_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "UserRole", columns: table => new { UserId = table.Column(type: "nvarchar(450)", maxLength: 450, nullable: false), RoleId = table.Column(type: "uniqueidentifier", nullable: false) }, constraints: table => { table.PrimaryKey("PK_UserRole", x => new { x.UserId, x.RoleId }); table.ForeignKey( name: "FK_UserRole_Roles_RoleId", column: x => x.RoleId, principalTable: "Roles", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_UserRole_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "ProductVariants", columns: table => new { Id = table.Column(type: "uniqueidentifier", nullable: false, defaultValueSql: "NEWID()"), ProductId = table.Column(type: "uniqueidentifier", nullable: false), Size = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false), Color = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: true), Price = table.Column(type: "decimal(18,2)", nullable: false), ImageUrl = table.Column(type: "nvarchar(500)", maxLength: 500, nullable: true), Sku = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false), StockQuantity = table.Column(type: "int", nullable: false, defaultValue: 0), IsActive = table.Column(type: "bit", nullable: false, defaultValue: true), CreatedAt = table.Column(type: "datetime2", nullable: true), ModifiedAt = table.Column(type: "datetime2", nullable: true, defaultValueSql: "GETUTCDATE()"), CreatedBy = table.Column(type: "nvarchar(450)", maxLength: 450, nullable: true), ModifiedBy = table.Column(type: "nvarchar(450)", maxLength: 450, nullable: true) }, constraints: table => { table.PrimaryKey("PK_ProductVariants", x => x.Id); table.ForeignKey( name: "FK_ProductVariants_Products_ProductId", column: x => x.ProductId, principalTable: "Products", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "OrderAddresses", columns: table => new { Id = table.Column(type: "uniqueidentifier", nullable: false, defaultValueSql: "NEWID()"), OrderId = table.Column(type: "uniqueidentifier", nullable: false), Street = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: false), City = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false), State = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false), PostalCode = table.Column(type: "nvarchar(20)", maxLength: 20, nullable: false), Country = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false), CreatedAt = table.Column(type: "datetime2", nullable: false), ModifiedAt = table.Column(type: "datetime2", nullable: false, defaultValueSql: "GETUTCDATE()"), CreatedBy = table.Column(type: "nvarchar(450)", maxLength: 450, nullable: false), ModifiedBy = table.Column(type: "nvarchar(450)", maxLength: 450, nullable: false) }, constraints: table => { table.PrimaryKey("PK_OrderAddresses", x => x.Id); table.ForeignKey( name: "FK_OrderAddresses_Orders_OrderId", column: x => x.OrderId, principalTable: "Orders", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "OrderItems", columns: table => new { Id = table.Column(type: "uniqueidentifier", nullable: false, defaultValueSql: "NEWID()"), OrderId = table.Column(type: "uniqueidentifier", nullable: false), ProductId = table.Column(type: "uniqueidentifier", nullable: false), ProductVariantId = table.Column(type: "uniqueidentifier", nullable: true), Quantity = table.Column(type: "int", nullable: false, defaultValue: 1), UnitPrice = table.Column(type: "decimal(18,2)", nullable: false), TotalPrice = table.Column(type: "decimal(18,2)", nullable: false), CustomizationImageUrl = table.Column(type: "nvarchar(500)", maxLength: 500, nullable: false), CustomizationDescription = table.Column(type: "nvarchar(2000)", maxLength: 2000, nullable: false), CreatedAt = table.Column(type: "datetime2", nullable: false), ModifiedAt = table.Column(type: "datetime2", nullable: false, defaultValueSql: "GETUTCDATE()"), CreatedBy = table.Column(type: "nvarchar(450)", maxLength: 450, nullable: false), ModifiedBy = table.Column(type: "nvarchar(450)", maxLength: 450, nullable: false) }, constraints: table => { table.PrimaryKey("PK_OrderItems", x => x.Id); table.ForeignKey( name: "FK_OrderItems_Orders_OrderId", column: x => x.OrderId, principalTable: "Orders", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_OrderItems_ProductVariants_ProductVariantId", column: x => x.ProductVariantId, principalTable: "ProductVariants", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_OrderItems_Products_ProductId", column: x => x.ProductId, principalTable: "Products", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.InsertData( table: "Categories", columns: new[] { "Id", "CreatedAt", "CreatedBy", "Description", "ImageUrl", "IsActive", "ModifiedAt", "ModifiedBy", "Name", "ParentCategoryId", "SortOrder" }, values: new object[,] { { new Guid("11111111-1111-1111-1111-111111111111"), new DateTime(2025, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc), "system@printbase.com", "Textile and fabric-based products", null, true, new DateTime(2025, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc), "system@printbase.com", "Textile", null, 1 }, { new Guid("22222222-2222-2222-2222-222222222222"), new DateTime(2025, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc), "system@printbase.com", "Products for hard surface printing", null, true, new DateTime(2025, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc), "system@printbase.com", "Hard Surfaces", null, 2 }, { new Guid("33333333-3333-3333-3333-333333333333"), new DateTime(2025, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc), "system@printbase.com", "Paper-based printing products", null, true, new DateTime(2025, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc), "system@printbase.com", "Paper", null, 3 } }); migrationBuilder.InsertData( table: "OrderStatuses", columns: new[] { "Id", "Name" }, values: new object[,] { { 0, "Pending" }, { 1, "Processing" }, { 2, "Completed" }, { 3, "Cancelled" } }); migrationBuilder.InsertData( table: "Roles", columns: new[] { "Id", "RoleName" }, values: new object[,] { { new Guid("22222222-2222-2222-2222-222222222222"), "Merchant" }, { new Guid("33333333-3333-3333-3333-333333333333"), "Admin" } }); migrationBuilder.InsertData( table: "ShippingStatuses", columns: new[] { "Id", "Name" }, values: new object[,] { { 0, "Prepping" }, { 1, "Packaging" }, { 2, "Shipped" }, { 3, "Delivered" } }); migrationBuilder.CreateIndex( name: "IX_Address_CreatedAt", table: "Addresses", column: "CreatedAt"); migrationBuilder.CreateIndex( name: "IX_Address_CreatedBy", table: "Addresses", column: "CreatedBy"); migrationBuilder.CreateIndex( name: "IX_Address_ModifiedAt", table: "Addresses", column: "ModifiedAt"); migrationBuilder.CreateIndex( name: "IX_Address_User_Default", table: "Addresses", columns: new[] { "UserId", "IsDefault" }); migrationBuilder.CreateIndex( name: "IX_Address_User_Type", table: "Addresses", columns: new[] { "UserId", "AddressType" }); migrationBuilder.CreateIndex( name: "IX_Address_UserId", table: "Addresses", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_Category_Active_SortOrder", table: "Categories", columns: new[] { "IsActive", "SortOrder" }); migrationBuilder.CreateIndex( name: "IX_Category_CreatedAt", table: "Categories", column: "CreatedAt"); migrationBuilder.CreateIndex( name: "IX_Category_CreatedBy", table: "Categories", column: "CreatedBy"); migrationBuilder.CreateIndex( name: "IX_Category_IsActive", table: "Categories", column: "IsActive"); migrationBuilder.CreateIndex( name: "IX_Category_ModifiedAt", table: "Categories", column: "ModifiedAt"); migrationBuilder.CreateIndex( name: "IX_Category_Name", table: "Categories", column: "Name"); migrationBuilder.CreateIndex( name: "IX_Category_Parent_SortOrder", table: "Categories", columns: new[] { "ParentCategoryId", "SortOrder" }); migrationBuilder.CreateIndex( name: "IX_Category_ParentCategoryId", table: "Categories", column: "ParentCategoryId"); migrationBuilder.CreateIndex( name: "IX_OrderAddress_CreatedAt", table: "OrderAddresses", column: "CreatedAt"); migrationBuilder.CreateIndex( name: "IX_OrderAddress_CreatedBy", table: "OrderAddresses", column: "CreatedBy"); migrationBuilder.CreateIndex( name: "IX_OrderAddress_ModifiedAt", table: "OrderAddresses", column: "ModifiedAt"); migrationBuilder.CreateIndex( name: "IX_OrderAddress_OrderId", table: "OrderAddresses", column: "OrderId", unique: true); migrationBuilder.CreateIndex( name: "IX_OrderItem_CreatedAt", table: "OrderItems", column: "CreatedAt"); migrationBuilder.CreateIndex( name: "IX_OrderItem_CreatedBy", table: "OrderItems", column: "CreatedBy"); migrationBuilder.CreateIndex( name: "IX_OrderItem_ModifiedAt", table: "OrderItems", column: "ModifiedAt"); migrationBuilder.CreateIndex( name: "IX_OrderItem_Order_Product", table: "OrderItems", columns: new[] { "OrderId", "ProductId" }); migrationBuilder.CreateIndex( name: "IX_OrderItem_OrderId", table: "OrderItems", column: "OrderId"); migrationBuilder.CreateIndex( name: "IX_OrderItem_ProductId", table: "OrderItems", column: "ProductId"); migrationBuilder.CreateIndex( name: "IX_OrderItem_ProductVariantId", table: "OrderItems", column: "ProductVariantId"); migrationBuilder.CreateIndex( name: "IX_Order_CreatedAt", table: "Orders", column: "CreatedAt"); migrationBuilder.CreateIndex( name: "IX_Order_CreatedBy", table: "Orders", column: "CreatedBy"); migrationBuilder.CreateIndex( name: "IX_Order_ModifiedAt", table: "Orders", column: "ModifiedAt"); migrationBuilder.CreateIndex( name: "IX_Order_OrderDate", table: "Orders", column: "OrderDate"); migrationBuilder.CreateIndex( name: "IX_Order_OrderNumber", table: "Orders", column: "OrderNumber", unique: true); migrationBuilder.CreateIndex( name: "IX_Order_OrderStatusId", table: "Orders", column: "OrderStatusId"); migrationBuilder.CreateIndex( name: "IX_Order_ShippingStatusId", table: "Orders", column: "ShippingStatusId"); migrationBuilder.CreateIndex( name: "IX_Order_User_Date", table: "Orders", columns: new[] { "UserId", "OrderDate" }); migrationBuilder.CreateIndex( name: "IX_Order_UserId", table: "Orders", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_OrderStatus_Name", table: "OrderStatuses", column: "Name", unique: true); migrationBuilder.CreateIndex( name: "IX_Product_Active_Customizable", table: "Products", columns: new[] { "IsActive", "IsCustomizable" }); migrationBuilder.CreateIndex( name: "IX_Product_Category_Active", table: "Products", columns: new[] { "CategoryId", "IsActive" }); migrationBuilder.CreateIndex( name: "IX_Product_CategoryId", table: "Products", column: "CategoryId"); migrationBuilder.CreateIndex( name: "IX_Product_CreatedAt", table: "Products", column: "CreatedAt"); migrationBuilder.CreateIndex( name: "IX_Product_CreatedBy", table: "Products", column: "CreatedBy"); migrationBuilder.CreateIndex( name: "IX_Product_IsActive", table: "Products", column: "IsActive"); migrationBuilder.CreateIndex( name: "IX_Product_IsCustomizable", table: "Products", column: "IsCustomizable"); migrationBuilder.CreateIndex( name: "IX_Product_ModifiedAt", table: "Products", column: "ModifiedAt"); migrationBuilder.CreateIndex( name: "IX_Product_Name", table: "Products", column: "Name"); migrationBuilder.CreateIndex( name: "IX_ProductVariant_CreatedAt", table: "ProductVariants", column: "CreatedAt"); migrationBuilder.CreateIndex( name: "IX_ProductVariant_CreatedBy", table: "ProductVariants", column: "CreatedBy"); migrationBuilder.CreateIndex( name: "IX_ProductVariant_IsActive", table: "ProductVariants", column: "IsActive"); migrationBuilder.CreateIndex( name: "IX_ProductVariant_ModifiedAt", table: "ProductVariants", column: "ModifiedAt"); migrationBuilder.CreateIndex( name: "IX_ProductVariant_Product_Size_Color", table: "ProductVariants", columns: new[] { "ProductId", "Size", "Color" }, unique: true, filter: "[Color] IS NOT NULL"); migrationBuilder.CreateIndex( name: "IX_ProductVariant_ProductId", table: "ProductVariants", column: "ProductId"); migrationBuilder.CreateIndex( name: "IX_ProductVariant_SKU", table: "ProductVariants", column: "Sku", unique: true); migrationBuilder.CreateIndex( name: "IX_Role_RoleName", table: "Roles", column: "RoleName", unique: true); migrationBuilder.CreateIndex( name: "IX_ShippingStatus_Name", table: "ShippingStatuses", column: "Name", unique: true); migrationBuilder.CreateIndex( name: "IX_UserRole_RoleId", table: "UserRole", column: "RoleId"); migrationBuilder.CreateIndex( name: "IX_UserRole_UserId", table: "UserRole", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_User_Email", table: "Users", column: "Email", unique: true); migrationBuilder.CreateIndex( name: "IX_User_IsActive", table: "Users", column: "IsActive"); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "Addresses"); migrationBuilder.DropTable( name: "OrderAddresses"); migrationBuilder.DropTable( name: "OrderItems"); migrationBuilder.DropTable( name: "UserRole"); migrationBuilder.DropTable( name: "Orders"); migrationBuilder.DropTable( name: "ProductVariants"); migrationBuilder.DropTable( name: "Roles"); migrationBuilder.DropTable( name: "OrderStatuses"); migrationBuilder.DropTable( name: "ShippingStatuses"); migrationBuilder.DropTable( name: "Users"); migrationBuilder.DropTable( name: "Products"); migrationBuilder.DropTable( name: "Categories"); } } }