-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
23 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,22 @@ | ||
# Script for populating the database. You can run it as: | ||
# | ||
# mix run priv/repo/seeds.exs | ||
# | ||
# Inside the script, you can read and write to any of your | ||
# repositories directly: | ||
# | ||
# Pento.Repo.insert!(%Pento.SomeSchema{}) | ||
# | ||
# We recommend using the bang functions (`insert!`, `update!` | ||
# and so on) as they will fail if something goes wrong. | ||
defmodule Seeder do | ||
alias Pento.Catalog | ||
alias FakerElixir.{Number, Lorem, Name} | ||
|
||
alias Pento.Catalog | ||
def run do | ||
if Catalog.list_products() |> Enum.empty?() do | ||
Enum.each(1..6, fn _ -> | ||
attrs = %{ | ||
name: Name.name(), | ||
description: Lorem.sentence(), | ||
sku: Number.digits(5), | ||
unit_price: Number.decimal(2) | ||
} | ||
|
||
products = [ | ||
%{ | ||
name: "Chess", | ||
description: "The classic game of chess", | ||
sku: 5_678_901, | ||
unit_price: 10 | ||
}, | ||
%{ | ||
name: "Tic-Tac-Toe", | ||
description: "The game of cats and dogs", | ||
sku: 11_121_314, | ||
unit_price: 3.00 | ||
}, | ||
%{ | ||
name: "Table Tennis", | ||
description: "Bat and ball back and forth. Don't miss!", | ||
sku: 15_222_324, | ||
unit_price: 12.00 | ||
} | ||
] | ||
Catalog.create_product(attrs) | ||
|> IO.inspect(label: "Product created:") | ||
end) | ||
end | ||
end | ||
end | ||
|
||
Enum.each(products, fn product -> | ||
Catalog.create_product(product) | ||
end) | ||
Seeder.run() |