feat: Adds script to generate database seeded values and removes old mock storage.

This commit is contained in:
2025-01-16 21:00:27 -05:00
parent 09b46f672a
commit e1d07008a1
16 changed files with 399 additions and 535 deletions

View File

@@ -60,6 +60,46 @@ public extension Employee {
}
}
#if DEBUG
//
// public extension Employee {
//
// static func generateMocks(count: Int = 10) -> [Self] {
// @Dependency(\.date.now) var now
// @Dependency(\.uuid) var uuid
//
// var output = [Self]()
//
// for _ in 0 ... count {
// output.append(.init(
// id: uuid(),
// active: Bool.random(),
// createdAt: now,
// firstName: RandomNames.firstNames.randomElement()!,
// lastName: RandomNames.lastNames.randomElement()!,
// updatedAt: now
// ))
// }
//
// return output
// }
// }
public extension Employee.Create {
static func generateMocks(count: Int = 5) -> [Self] {
(0 ... count).reduce(into: [Self]()) { array, _ in
array.append(.init(
firstName: RandomNames.firstNames.randomElement()! + String(RandomNames.characterString.randomElement()!),
lastName: RandomNames.lastNames.randomElement()! + String(RandomNames.characterString.randomElement()!),
active: Bool.random()
))
}
}
}
#endif
// public extension Employee {
// static var mocks: [Self] {
// [

View File

@@ -0,0 +1,150 @@
#if DEBUG
enum RandomNames {
static let characterString = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
// Static variables for first names
static let firstNames: [String] = [
"Oliver",
"Emma",
"Liam",
"Ava",
"Noah",
"Sophia",
"Elijah",
"Isabella",
"James",
"Mia",
"Benjamin",
"Charlotte",
"Lucas",
"Amelia",
"Henry",
"Harper",
"Alexander",
"Evelyn",
"William",
"Abigail"
]
// Static variables for last names
static let lastNames: [String] = [
"Smith",
"Johnson",
"Brown",
"Williams",
"Jones",
"Garcia",
"Martinez",
"Davis",
"Rodriguez",
"Martins",
"Hernandez",
"Lopez",
"Gonzalez",
"Wilson",
"Anderson",
"Thomas",
"Taylor",
"Moore",
"Jackson",
"Martin"
]
// Static variables for user names
static let userNames: [String] = [
"CoolCat123",
"FastFrog99",
"SunnySky",
"RocketRider",
"PixelPanda",
"ShadowNinja",
"ThunderWolf",
"GoldenEagle",
"SilverFox",
"MightyBear",
"IronLion",
"BlueTiger",
"FirePhoenix",
"CrystalDragon",
"NeonKnight",
"ElectricZebra",
"MagicUnicorn",
"StealthShark",
"GalaxyRanger",
"CosmicTurtle"
]
// Static variables for city names
static let cityNames: [String] = [
"Springfield",
"Rivertown",
"Sunnyvale",
"Lakeside",
"Hillcrest",
"Oakwood",
"Mapleton",
"Pinehill",
"Brookfield",
"Riverbend",
"Clearwater",
"Greystone",
"Westhaven",
"Eastwood",
"Silverlake",
"Goldenfield",
"Highland",
"Cedarville",
"Willowbrook",
"Fairview"
]
// Static variables for company names
static let companyNames: [String] = [
"TechNova",
"GreenLeaf Co.",
"Skyline Ventures",
"Pioneer Systems",
"Quantum Dynamics",
"Blue Horizon",
"NextGen Solutions",
"Summit Enterprises",
"FutureWorks",
"BrightPath",
"Eclipse Innovations",
"Golden Gate Technologies",
"Silverline Corp.",
"Vertex Industries",
"DynamicEdge",
"CrestPoint",
"EcoSphere",
"PrimeSource",
"InfinityTech",
"TrueNorth Inc."
]
// Static variables for fake emails
static let emails: [String] = [
"oliver.smith@example.com",
"emma.johnson@example.org",
"liam.brown@example.net",
"ava.williams@example.com",
"noah.jones@example.org",
"sophia.garcia@example.net",
"elijah.martinez@example.com",
"isabella.davis@example.org",
"james.rodriguez@example.net",
"mia.martins@example.com",
"benjamin.hernandez@example.org",
"charlotte.lopez@example.net",
"lucas.gonzalez@example.com",
"amelia.wilson@example.org",
"henry.anderson@example.net",
"harper.thomas@example.com",
"alexander.taylor@example.org",
"evelyn.moore@example.net",
"william.jackson@example.com",
"abigail.martin@example.org"
]
}
#endif

View File

@@ -72,3 +72,57 @@ public extension PurchaseOrder {
}
}
#if DEBUG
// public extension PurchaseOrder {
// static func generateMocks(
// count: Int = 50,
// employees: [Employee],
// users: [User],
// vendorBranches: [VendorBranch]
// ) -> [Self] {
// @Dependency(\.date.now) var now
// @Dependency(\.uuid) var uuid
//
// var output = [Self]()
//
// for id in 0 ... count {
// output.append(.init(
// id: id,
// workOrder: Int.random(in: 0 ... 100),
// materials: "Some thing",
// customer: "\(RandomNames.firstNames.randomElement()!) \(RandomNames.lastNames.randomElement()!)",
// truckStock: Bool.random(),
// createdBy: users.randomElement()!,
// createdFor: employees.randomElement()!,
// vendorBranch: vendorBranches.randomElement()!,
// createdAt: now,
// updatedAt: now
// ))
// }
//
// return output
// }
// }
public extension PurchaseOrder.Create {
static func generateMocks(
count: Int = 50,
employees: [Employee],
vendorBranches: [VendorBranch]
) -> [Self] {
precondition(employees.count > 0)
precondition(vendorBranches.count > 0)
return (0 ... count).reduce(into: [Self]()) { array, _ in
array.append(.init(
materials: "Some materials",
customer: "\(RandomNames.firstNames.randomElement()!) \(RandomNames.lastNames.randomElement()!)",
createdForID: employees.randomElement()!.id,
vendorBranchID: vendorBranches.randomElement()!.id
))
}
}
}
#endif

View File

@@ -84,12 +84,18 @@ public extension User {
}
// public extension User {
// static var mocks: [Self] {
// [
// .init(email: "blob@test.com", username: "blob"),
// .init(email: "blob-jr@test.com", username: "blob-jr"),
// .init(email: "blob-sr@test.com", username: "blob-sr")
// ]
// }
// }
#if DEBUG
public extension User.Create {
static func generateMocks(count: Int = 5) -> [Self] {
(0 ... count).reduce(into: [Self]()) { array, _ in
array.append(.init(
username: RandomNames.userNames.randomElement()! + String(RandomNames.characterString.randomElement()!),
email: String(RandomNames.characterString.randomElement()!) + RandomNames.emails.randomElement()!,
password: "super-secret",
confirmPassword: "super-secret"
))
}
}
}
#endif

View File

@@ -41,3 +41,40 @@ public extension Vendor {
}
}
}
#if DEBUG
//
// public extension Vendor {
//
// static func generateMocks(count: Int = 20) -> [Self] {
// @Dependency(\.date.now) var now
// @Dependency(\.uuid) var uuid
//
// var output = [Self]()
//
// for _ in 0 ... count {
// output.append(.init(
// id: uuid(),
// name: RandomNames.companyNames.randomElement()!,
// branches: nil,
// createdAt: now,
// updatedAt: now
// ))
// }
//
// return output
// }
// }
public extension Vendor.Create {
static func generateMocks(count: Int = 5) -> [Self] {
(0 ... count).reduce(into: [Self]()) { array, _ in
array.append(.init(
name: RandomNames.companyNames.randomElement()! + String(RandomNames.characterString.randomElement()!)
))
}
}
}
#endif

View File

@@ -42,3 +42,41 @@ public extension VendorBranch {
}
}
}
#if DEBUG
// public extension VendorBranch {
//
// static func generateMocks(countPerVendor: Int = 3, vendors: [Vendor]) -> [Self] {
// @Dependency(\.date.now) var now
// @Dependency(\.uuid) var uuid
//
// var output = [Self]()
//
// for vendor in vendors {
// for _ in 0 ... countPerVendor {
// output.append(.init(
// id: uuid(),
// name: RandomNames.cityNames.randomElement()!,
// vendorID: vendor.id,
// createdAt: now,
// updatedAt: now
// ))
// }
// }
//
// return output
// }
// }
public extension VendorBranch.Create {
static func generateMocks(countPerVendor: Int = 3, vendors: [Vendor]) -> [Self] {
return vendors.reduce(into: [Self]()) { output, vendor in
output = (0 ... countPerVendor).reduce(into: output) { array, _ in
array.append(.init(name: RandomNames.cityNames.randomElement()!, vendorID: vendor.id))
}
}
}
}
#endif