diff --git a/Sources/Alchemy/SQL/Database/Seeding/Seeder.swift b/Sources/Alchemy/SQL/Database/Seeding/Seeder.swift index da7411be..a49c4cda 100644 --- a/Sources/Alchemy/SQL/Database/Seeding/Seeder.swift +++ b/Sources/Alchemy/SQL/Database/Seeding/Seeder.swift @@ -23,6 +23,14 @@ extension Seedable where Self: Model { return try await rows.insertReturnAll() } + + public static func randomOrSeed() async throws -> Self { + guard let random = try await random() else { + return try await seed() + } + + return random + } } extension Faker {