diff --git a/mix.exs b/mix.exs index 956a919..7def2c3 100644 --- a/mix.exs +++ b/mix.exs @@ -51,7 +51,8 @@ defmodule Pento.MixProject do {:jason, "~> 1.2"}, {:dns_cluster, "~> 0.1.1"}, {:plug_cowboy, "~> 2.5"}, - {:pow, "~> 1.0.35"} + {:pow, "~> 1.0.35"}, + {:faker_elixir_octopus, "~> 1.0"} ] end diff --git a/mix.lock b/mix.lock index e2869e2..f2ddda4 100644 --- a/mix.lock +++ b/mix.lock @@ -10,6 +10,8 @@ "ecto_sql": {:hex, :ecto_sql, "3.11.1", "e9abf28ae27ef3916b43545f9578b4750956ccea444853606472089e7d169470", [:mix], [{:db_connection, "~> 2.4.1 or ~> 2.5", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.11.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.6.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.16.0 or ~> 0.17.0 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1 or ~> 2.2", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "ce14063ab3514424276e7e360108ad6c2308f6d88164a076aac8a387e1fea634"}, "esbuild": {:hex, :esbuild, "0.8.1", "0cbf919f0eccb136d2eeef0df49c4acf55336de864e63594adcea3814f3edf41", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "25fc876a67c13cb0a776e7b5d7974851556baeda2085296c14ab48555ea7560f"}, "expo": {:hex, :expo, "0.5.1", "249e826a897cac48f591deba863b26c16682b43711dd15ee86b92f25eafd96d9", [:mix], [], "hexpm", "68a4233b0658a3d12ee00d27d37d856b1ba48607e7ce20fd376958d0ba6ce92b"}, + "faker": {:hex, :faker, "0.17.0", "671019d0652f63aefd8723b72167ecdb284baf7d47ad3a82a15e9b8a6df5d1fa", [:mix], [], "hexpm", "a7d4ad84a93fd25c5f5303510753789fc2433ff241bf3b4144d3f6f291658a6a"}, + "faker_elixir_octopus": {:hex, :faker_elixir_octopus, "1.0.2", "9895a5cbd08ba47ec70aa04dd91077ff57abe6e49239e853c5f6969e106ce997", [:mix], [], "hexpm", "a332fd3c5c633c87e15f262109a5f141b3e2dd08324df71d2591ef918f20789d"}, "file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"}, "finch": {:hex, :finch, "0.17.0", "17d06e1d44d891d20dbd437335eebe844e2426a0cd7e3a3e220b461127c73f70", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: false]}, {:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.3", [hex: :mint, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.4 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_pool, "~> 0.2.6 or ~> 1.0", [hex: :nimble_pool, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "8d014a661bb6a437263d4b5abf0bcbd3cf0deb26b1e8596f2a271d22e48934c7"}, "floki": {:hex, :floki, "0.35.2", "87f8c75ed8654b9635b311774308b2760b47e9a579dabf2e4d5f1e1d42c39e0b", [:mix], [], "hexpm", "6b05289a8e9eac475f644f09c2e4ba7e19201fd002b89c28c1293e7bd16773d9"}, diff --git a/priv/repo/migrations/20240210162636_create_products.exs b/priv/repo/migrations/20240210162636_create_products.exs deleted file mode 100644 index 22f9488..0000000 --- a/priv/repo/migrations/20240210162636_create_products.exs +++ /dev/null @@ -1,16 +0,0 @@ -defmodule Pento.Repo.Migrations.CreateProducts do - use Ecto.Migration - - def change do - create table(:products) do - add :name, :string - add :description, :string - add :unit_price, :float - add :sku, :integer - - timestamps(type: :utc_datetime) - end - - create unique_index(:products, [:sku]) - end -end diff --git a/priv/repo/seeds.exs b/priv/repo/seeds.exs index 91feb23..8d5faf6 100644 --- a/priv/repo/seeds.exs +++ b/priv/repo/seeds.exs @@ -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()