|
1 | | -# Script for populating the database. You can run it as: |
2 | | -# |
3 | | -# mix run priv/repo/seeds.exs |
4 | | -# |
5 | | -# Inside the script, you can read and write to any of your |
6 | | -# repositories directly: |
7 | | -# |
8 | | -# AutoFinder.Repo.insert!(%AutoFinder.SomeSchema{}) |
9 | | -# |
10 | | -# We recommend using the bang functions (`insert!`, `update!` |
11 | | -# and so on) as they will fail if something goes wrong. |
| 1 | +alias AutoFinder.{Repo, UsedCars.UsedCar} |
| 2 | + |
| 3 | +car_selection = [ |
| 4 | + {"Acura", ~w(ILX TLX RLX RDX MDX NSX), 15_000..35_000}, |
| 5 | + {"Honda", ~w(Accord Civic CR-V Odyssey Passport), 10_000..25_000}, |
| 6 | + {"Nissan", ~w(GT-R 370Z Titan Leaf Sentra), 25_000..50_000}, |
| 7 | + {"Mazda", ~w(MX-5 CX-3 CX5 CX-9), 15_000..25_000}, |
| 8 | + {"Chevrolet", ~w(Camaro Corvette Colorado Silverado), 25_000..50_000}, |
| 9 | + {"Ford", ~w(Escape Explorer Mustang Focus), 15_000..25_000}, |
| 10 | + {"Audi", ~w(A4 Q3 A6 Q7 R8 S3 S4 RS5), 20_000..50_000}, |
| 11 | + {"BMW", ~w(M2 M3 M5 X4 X7), 20_000..50_000}, |
| 12 | + {"Subaru", ~w(Impreza Legacy Forester BRZ WRX), 15_000..25_000}, |
| 13 | + {"Porsche", ~w(Taycan Panamera MAcan Cayenne Carrera Cayman), 40_000..70_000}, |
| 14 | + {"Ferrari", ~w(812 F8 488 GTC4 Portofino), 150_000..250_000} |
| 15 | +] |
| 16 | + |
| 17 | +1..1_000 |
| 18 | +|> Enum.each(fn _ -> |
| 19 | + {make, models, price_range} = Enum.random(car_selection) |
| 20 | + model = Enum.random(models) |
| 21 | + price = Enum.random(price_range) |
| 22 | + year = Enum.random(2015..2020) |
| 23 | + mileage = Enum.random(10_000..60_000) |
| 24 | + |
| 25 | + %UsedCar{} |
| 26 | + |> UsedCar.changeset(%{make: make, model: model, price: price, year: year, mileage: mileage}) |
| 27 | + |> Repo.insert!() |
| 28 | +end) |
0 commit comments