using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional
namespace PowderCoating.Infrastructure.Migrations
{
///
public partial class InitialCreate : Migration
{
///
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "AspNetRoles",
columns: table => new
{
Id = table.Column(type: "nvarchar(450)", nullable: false),
Name = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true),
NormalizedName = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true),
ConcurrencyStamp = table.Column(type: "nvarchar(max)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetRoles", x => x.Id);
});
migrationBuilder.CreateTable(
name: "AspNetUsers",
columns: table => new
{
Id = table.Column(type: "nvarchar(450)", nullable: false),
FirstName = table.Column(type: "nvarchar(max)", nullable: false),
LastName = table.Column(type: "nvarchar(max)", nullable: false),
EmployeeNumber = table.Column(type: "nvarchar(max)", nullable: true),
DateOfBirth = table.Column(type: "datetime2", nullable: true),
HireDate = table.Column(type: "datetime2", nullable: false),
TerminationDate = table.Column(type: "datetime2", nullable: true),
Address = table.Column(type: "nvarchar(max)", nullable: true),
City = table.Column(type: "nvarchar(max)", nullable: true),
State = table.Column(type: "nvarchar(max)", nullable: true),
ZipCode = table.Column(type: "nvarchar(max)", nullable: true),
Department = table.Column(type: "nvarchar(max)", nullable: true),
Position = table.Column(type: "nvarchar(max)", nullable: true),
HourlyRate = table.Column(type: "decimal(18,2)", nullable: false),
Theme = table.Column(type: "nvarchar(max)", nullable: true),
DateFormat = table.Column(type: "nvarchar(max)", nullable: true),
TimeZone = table.Column(type: "nvarchar(max)", nullable: true),
DashboardLayout = table.Column(type: "int", nullable: true),
IsActive = table.Column(type: "bit", nullable: false),
CanViewShopFloor = table.Column(type: "bit", nullable: false),
CanManageJobs = table.Column(type: "bit", nullable: false),
CanManageInventory = table.Column(type: "bit", nullable: false),
CanManageCustomers = table.Column(type: "bit", nullable: false),
CanCreateQuotes = table.Column(type: "bit", nullable: false),
CanApproveQuotes = table.Column(type: "bit", nullable: false),
ProfilePicturePath = table.Column(type: "nvarchar(max)", nullable: true),
Notes = table.Column(type: "nvarchar(max)", nullable: true),
CreatedAt = table.Column(type: "datetime2", nullable: false),
UpdatedAt = table.Column(type: "datetime2", nullable: true),
LastLoginDate = table.Column(type: "datetime2", nullable: true),
UserName = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true),
NormalizedUserName = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true),
Email = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true),
NormalizedEmail = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true),
EmailConfirmed = table.Column(type: "bit", nullable: false),
PasswordHash = table.Column(type: "nvarchar(max)", nullable: true),
SecurityStamp = table.Column(type: "nvarchar(max)", nullable: true),
ConcurrencyStamp = table.Column(type: "nvarchar(max)", nullable: true),
PhoneNumber = table.Column(type: "nvarchar(max)", nullable: true),
PhoneNumberConfirmed = table.Column(type: "bit", nullable: false),
TwoFactorEnabled = table.Column(type: "bit", nullable: false),
LockoutEnd = table.Column(type: "datetimeoffset", nullable: true),
LockoutEnabled = table.Column(type: "bit", nullable: false),
AccessFailedCount = table.Column(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUsers", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Equipment",
columns: table => new
{
Id = table.Column(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
EquipmentName = table.Column(type: "nvarchar(max)", nullable: false),
EquipmentNumber = table.Column(type: "nvarchar(max)", nullable: true),
EquipmentType = table.Column(type: "nvarchar(max)", nullable: false),
Manufacturer = table.Column(type: "nvarchar(max)", nullable: true),
Model = table.Column(type: "nvarchar(max)", nullable: true),
SerialNumber = table.Column(type: "nvarchar(max)", nullable: true),
PurchaseDate = table.Column(type: "datetime2", nullable: true),
PurchasePrice = table.Column(type: "decimal(18,2)", nullable: false),
WarrantyExpiration = table.Column(type: "datetime2", nullable: true),
Status = table.Column(type: "int", nullable: false),
Location = table.Column(type: "nvarchar(max)", nullable: true),
RecommendedMaintenanceIntervalDays = table.Column(type: "int", nullable: false),
LastMaintenanceDate = table.Column(type: "datetime2", nullable: true),
NextScheduledMaintenance = table.Column(type: "datetime2", nullable: true),
Notes = table.Column(type: "nvarchar(max)", nullable: true),
IsActive = table.Column(type: "bit", nullable: false),
CreatedAt = table.Column(type: "datetime2", nullable: false),
UpdatedAt = table.Column(type: "datetime2", nullable: true),
CreatedBy = table.Column(type: "nvarchar(max)", nullable: true),
UpdatedBy = table.Column(type: "nvarchar(max)", nullable: true),
IsDeleted = table.Column(type: "bit", nullable: false),
DeletedAt = table.Column(type: "datetime2", nullable: true),
DeletedBy = table.Column(type: "nvarchar(max)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Equipment", x => x.Id);
});
migrationBuilder.CreateTable(
name: "PricingTiers",
columns: table => new
{
Id = table.Column(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
TierName = table.Column(type: "nvarchar(max)", nullable: false),
Description = table.Column(type: "nvarchar(max)", nullable: true),
DiscountPercent = table.Column(type: "decimal(18,2)", nullable: false),
IsActive = table.Column(type: "bit", nullable: false),
CreatedAt = table.Column(type: "datetime2", nullable: false),
UpdatedAt = table.Column(type: "datetime2", nullable: true),
CreatedBy = table.Column(type: "nvarchar(max)", nullable: true),
UpdatedBy = table.Column(type: "nvarchar(max)", nullable: true),
IsDeleted = table.Column(type: "bit", nullable: false),
DeletedAt = table.Column(type: "datetime2", nullable: true),
DeletedBy = table.Column(type: "nvarchar(max)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_PricingTiers", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Suppliers",
columns: table => new
{
Id = table.Column(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
CompanyName = table.Column(type: "nvarchar(max)", nullable: false),
ContactName = table.Column(type: "nvarchar(max)", nullable: true),
Email = table.Column(type: "nvarchar(max)", nullable: true),
Phone = table.Column(type: "nvarchar(max)", nullable: true),
Address = table.Column(type: "nvarchar(max)", nullable: true),
City = table.Column(type: "nvarchar(max)", nullable: true),
State = table.Column(type: "nvarchar(max)", nullable: true),
ZipCode = table.Column(type: "nvarchar(max)", nullable: true),
Country = table.Column(type: "nvarchar(max)", nullable: true),
Website = table.Column(type: "nvarchar(max)", nullable: true),
Notes = table.Column(type: "nvarchar(max)", nullable: true),
IsActive = table.Column(type: "bit", nullable: false),
CreatedAt = table.Column(type: "datetime2", nullable: false),
UpdatedAt = table.Column(type: "datetime2", nullable: true),
CreatedBy = table.Column(type: "nvarchar(max)", nullable: true),
UpdatedBy = table.Column(type: "nvarchar(max)", nullable: true),
IsDeleted = table.Column(type: "bit", nullable: false),
DeletedAt = table.Column(type: "datetime2", nullable: true),
DeletedBy = table.Column(type: "nvarchar(max)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Suppliers", x => x.Id);
});
migrationBuilder.CreateTable(
name: "AspNetRoleClaims",
columns: table => new
{
Id = table.Column(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
RoleId = table.Column(type: "nvarchar(450)", nullable: false),
ClaimType = table.Column(type: "nvarchar(max)", nullable: true),
ClaimValue = table.Column(type: "nvarchar(max)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id);
table.ForeignKey(
name: "FK_AspNetRoleClaims_AspNetRoles_RoleId",
column: x => x.RoleId,
principalTable: "AspNetRoles",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "AspNetUserClaims",
columns: table => new
{
Id = table.Column(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
UserId = table.Column(type: "nvarchar(450)", nullable: false),
ClaimType = table.Column(type: "nvarchar(max)", nullable: true),
ClaimValue = table.Column(type: "nvarchar(max)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUserClaims", x => x.Id);
table.ForeignKey(
name: "FK_AspNetUserClaims_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "AspNetUserLogins",
columns: table => new
{
LoginProvider = table.Column(type: "nvarchar(450)", nullable: false),
ProviderKey = table.Column(type: "nvarchar(450)", nullable: false),
ProviderDisplayName = table.Column(type: "nvarchar(max)", nullable: true),
UserId = table.Column(type: "nvarchar(450)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey });
table.ForeignKey(
name: "FK_AspNetUserLogins_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "AspNetUserRoles",
columns: table => new
{
UserId = table.Column(type: "nvarchar(450)", nullable: false),
RoleId = table.Column(type: "nvarchar(450)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId });
table.ForeignKey(
name: "FK_AspNetUserRoles_AspNetRoles_RoleId",
column: x => x.RoleId,
principalTable: "AspNetRoles",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_AspNetUserRoles_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "AspNetUserTokens",
columns: table => new
{
UserId = table.Column(type: "nvarchar(450)", nullable: false),
LoginProvider = table.Column(type: "nvarchar(450)", nullable: false),
Name = table.Column(type: "nvarchar(450)", nullable: false),
Value = table.Column(type: "nvarchar(max)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name });
table.ForeignKey(
name: "FK_AspNetUserTokens_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "MaintenanceRecords",
columns: table => new
{
Id = table.Column(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
EquipmentId = table.Column(type: "int", nullable: false),
MaintenanceType = table.Column(type: "nvarchar(max)", nullable: false),
Status = table.Column(type: "int", nullable: false),
Priority = table.Column(type: "int", nullable: false),
ScheduledDate = table.Column(type: "datetime2", nullable: false),
CompletedDate = table.Column(type: "datetime2", nullable: true),
PerformedById = table.Column(type: "nvarchar(450)", nullable: true),
Description = table.Column(type: "nvarchar(max)", nullable: false),
WorkPerformed = table.Column(type: "nvarchar(max)", nullable: true),
PartsReplaced = table.Column(type: "nvarchar(max)", nullable: true),
LaborCost = table.Column(type: "decimal(18,2)", nullable: false),
PartsCost = table.Column(type: "decimal(18,2)", nullable: false),
TotalCost = table.Column(type: "decimal(18,2)", nullable: false),
DowntimeHours = table.Column(type: "decimal(18,2)", nullable: false),
Notes = table.Column(type: "nvarchar(max)", nullable: true),
TechnicianNotes = table.Column(type: "nvarchar(max)", nullable: true),
CreatedAt = table.Column(type: "datetime2", nullable: false),
UpdatedAt = table.Column(type: "datetime2", nullable: true),
CreatedBy = table.Column(type: "nvarchar(max)", nullable: true),
UpdatedBy = table.Column(type: "nvarchar(max)", nullable: true),
IsDeleted = table.Column(type: "bit", nullable: false),
DeletedAt = table.Column(type: "datetime2", nullable: true),
DeletedBy = table.Column(type: "nvarchar(max)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_MaintenanceRecords", x => x.Id);
table.ForeignKey(
name: "FK_MaintenanceRecords_AspNetUsers_PerformedById",
column: x => x.PerformedById,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.SetNull);
table.ForeignKey(
name: "FK_MaintenanceRecords_Equipment_EquipmentId",
column: x => x.EquipmentId,
principalTable: "Equipment",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "Customers",
columns: table => new
{
Id = table.Column(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
CompanyName = table.Column(type: "nvarchar(450)", nullable: false),
ContactFirstName = table.Column(type: "nvarchar(max)", nullable: true),
ContactLastName = table.Column(type: "nvarchar(max)", nullable: true),
Email = table.Column(type: "nvarchar(450)", nullable: false),
Phone = table.Column(type: "nvarchar(max)", nullable: true),
MobilePhone = table.Column(type: "nvarchar(max)", nullable: true),
Address = table.Column(type: "nvarchar(max)", nullable: true),
City = table.Column(type: "nvarchar(max)", nullable: true),
State = table.Column(type: "nvarchar(max)", nullable: true),
ZipCode = table.Column(type: "nvarchar(max)", nullable: true),
Country = table.Column(type: "nvarchar(max)", nullable: true),
IsCommercial = table.Column(type: "bit", nullable: false),
TaxId = table.Column(type: "nvarchar(max)", nullable: true),
CreditLimit = table.Column(type: "decimal(18,2)", nullable: false),
CurrentBalance = table.Column(type: "decimal(18,2)", nullable: false),
PaymentTerms = table.Column(type: "nvarchar(max)", nullable: true),
PricingTierId = table.Column(type: "int", nullable: true),
GeneralNotes = table.Column(type: "nvarchar(max)", nullable: true),
IsActive = table.Column(type: "bit", nullable: false),
LastContactDate = table.Column(type: "datetime2", nullable: true),
CreatedAt = table.Column(type: "datetime2", nullable: false),
UpdatedAt = table.Column(type: "datetime2", nullable: true),
CreatedBy = table.Column(type: "nvarchar(max)", nullable: true),
UpdatedBy = table.Column(type: "nvarchar(max)", nullable: true),
IsDeleted = table.Column(type: "bit", nullable: false),
DeletedAt = table.Column(type: "datetime2", nullable: true),
DeletedBy = table.Column(type: "nvarchar(max)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Customers", x => x.Id);
table.ForeignKey(
name: "FK_Customers_PricingTiers_PricingTierId",
column: x => x.PricingTierId,
principalTable: "PricingTiers",
principalColumn: "Id",
onDelete: ReferentialAction.SetNull);
});
migrationBuilder.CreateTable(
name: "InventoryItems",
columns: table => new
{
Id = table.Column(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
SKU = table.Column(type: "nvarchar(450)", nullable: false),
Name = table.Column(type: "nvarchar(max)", nullable: false),
Description = table.Column(type: "nvarchar(max)", nullable: true),
Category = table.Column(type: "nvarchar(max)", nullable: false),
ColorName = table.Column(type: "nvarchar(max)", nullable: true),
ColorCode = table.Column(type: "nvarchar(max)", nullable: true),
Finish = table.Column(type: "nvarchar(max)", nullable: true),
Manufacturer = table.Column(type: "nvarchar(max)", nullable: true),
ManufacturerPartNumber = table.Column(type: "nvarchar(max)", nullable: true),
QuantityOnHand = table.Column(type: "decimal(18,2)", nullable: false),
UnitOfMeasure = table.Column(type: "nvarchar(max)", nullable: false),
ReorderPoint = table.Column(type: "decimal(18,2)", nullable: false),
ReorderQuantity = table.Column(type: "decimal(18,2)", nullable: false),
MinimumStock = table.Column(type: "decimal(18,2)", nullable: false),
MaximumStock = table.Column(type: "decimal(18,2)", nullable: false),
UnitCost = table.Column(type: "decimal(18,2)", nullable: false),
AverageCost = table.Column(type: "decimal(18,2)", nullable: false),
LastPurchasePrice = table.Column(type: "decimal(18,2)", nullable: false),
LastPurchaseDate = table.Column(type: "datetime2", nullable: true),
PrimarySupplierId = table.Column(type: "int", nullable: true),
SupplierPartNumber = table.Column(type: "nvarchar(max)", nullable: true),
Location = table.Column(type: "nvarchar(max)", nullable: true),
Notes = table.Column(type: "nvarchar(max)", nullable: true),
IsActive = table.Column(type: "bit", nullable: false),
DiscontinuedDate = table.Column(type: "datetime2", nullable: true),
CreatedAt = table.Column(type: "datetime2", nullable: false),
UpdatedAt = table.Column(type: "datetime2", nullable: true),
CreatedBy = table.Column(type: "nvarchar(max)", nullable: true),
UpdatedBy = table.Column(type: "nvarchar(max)", nullable: true),
IsDeleted = table.Column(type: "bit", nullable: false),
DeletedAt = table.Column(type: "datetime2", nullable: true),
DeletedBy = table.Column(type: "nvarchar(max)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_InventoryItems", x => x.Id);
table.ForeignKey(
name: "FK_InventoryItems_Suppliers_PrimarySupplierId",
column: x => x.PrimarySupplierId,
principalTable: "Suppliers",
principalColumn: "Id",
onDelete: ReferentialAction.SetNull);
});
migrationBuilder.CreateTable(
name: "CustomerNotes",
columns: table => new
{
Id = table.Column(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
CustomerId = table.Column(type: "int", nullable: false),
Note = table.Column(type: "nvarchar(max)", nullable: false),
IsImportant = table.Column(type: "bit", nullable: false),
CreatedAt = table.Column(type: "datetime2", nullable: false),
UpdatedAt = table.Column(type: "datetime2", nullable: true),
CreatedBy = table.Column(type: "nvarchar(max)", nullable: true),
UpdatedBy = table.Column(type: "nvarchar(max)", nullable: true),
IsDeleted = table.Column(type: "bit", nullable: false),
DeletedAt = table.Column(type: "datetime2", nullable: true),
DeletedBy = table.Column(type: "nvarchar(max)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_CustomerNotes", x => x.Id);
table.ForeignKey(
name: "FK_CustomerNotes_Customers_CustomerId",
column: x => x.CustomerId,
principalTable: "Customers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Quotes",
columns: table => new
{
Id = table.Column(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
QuoteNumber = table.Column(type: "nvarchar(450)", nullable: false),
CustomerId = table.Column(type: "int", nullable: false),
PreparedById = table.Column(type: "nvarchar(450)", nullable: true),
Status = table.Column(type: "int", nullable: false),
IsCommercial = table.Column(type: "bit", nullable: false),
QuoteDate = table.Column(type: "datetime2", nullable: false),
ExpirationDate = table.Column(type: "datetime2", nullable: true),
SentDate = table.Column(type: "datetime2", nullable: true),
ApprovedDate = table.Column(type: "datetime2", nullable: true),
SubTotal = table.Column(type: "decimal(18,2)", nullable: false),
DiscountPercent = table.Column(type: "decimal(18,2)", nullable: false),
DiscountAmount = table.Column(type: "decimal(18,2)", nullable: false),
TaxPercent = table.Column(type: "decimal(18,2)", nullable: false),
TaxAmount = table.Column(type: "decimal(18,2)", nullable: false),
Total = table.Column(type: "decimal(18,2)", nullable: false),
Description = table.Column(type: "nvarchar(max)", nullable: true),
Terms = table.Column(type: "nvarchar(max)", nullable: true),
Notes = table.Column(type: "nvarchar(max)", nullable: true),
CustomerPO = table.Column(type: "nvarchar(max)", nullable: true),
AISuggestedPrice = table.Column(type: "decimal(18,2)", nullable: true),
AIPriceRationale = table.Column(type: "nvarchar(max)", nullable: true),
UsedAISuggestion = table.Column(type: "bit", nullable: false),
ConvertedToJobId = table.Column(type: "int", nullable: true),
ConvertedDate = table.Column(type: "datetime2", nullable: true),
CreatedAt = table.Column(type: "datetime2", nullable: false),
UpdatedAt = table.Column(type: "datetime2", nullable: true),
CreatedBy = table.Column(type: "nvarchar(max)", nullable: true),
UpdatedBy = table.Column(type: "nvarchar(max)", nullable: true),
IsDeleted = table.Column(type: "bit", nullable: false),
DeletedAt = table.Column(type: "datetime2", nullable: true),
DeletedBy = table.Column(type: "nvarchar(max)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Quotes", x => x.Id);
table.ForeignKey(
name: "FK_Quotes_AspNetUsers_PreparedById",
column: x => x.PreparedById,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.SetNull);
table.ForeignKey(
name: "FK_Quotes_Customers_CustomerId",
column: x => x.CustomerId,
principalTable: "Customers",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "InventoryTransactions",
columns: table => new
{
Id = table.Column(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
InventoryItemId = table.Column(type: "int", nullable: false),
TransactionType = table.Column(type: "int", nullable: false),
Quantity = table.Column(type: "decimal(18,2)", nullable: false),
UnitCost = table.Column