M .gitignore => .gitignore +3 -0
@@ 35,3 35,6 @@ npm-debug.log
/priv/static/uploads/
**/*.DS_STORE
+
+*.db
+*.db-*
M config/dev.exs => config/dev.exs +3 -6
@@ 2,12 2,9 @@ import Config
# Configure your database
config :galley, Galley.Repo,
- username: "tees",
- password: "postgres",
- hostname: "localhost",
- database: "galley_dev",
- show_sensitive_data_on_connection_error: true,
- pool_size: 10
+ database: Path.expand("../galleydata_dev.db", Path.dirname(__ENV__.file)),
+ pool_size: 5,
+ show_sensitive_data_on_connection_error: true
# For development, we disable any cache and enable
# debugging and code reloading.
M config/runtime.exs => config/runtime.exs +3 -3
@@ 14,10 14,10 @@ end
if config_env() == :prod do
database_url =
- System.get_env("DATABASE_URL") ||
+ System.get_env("DATABASE_PATH") ||
raise """
- environment variable DATABASE_URL is missing.
- For example: ecto://USER:PASS@HOST/DATABASE
+ environment variable DATABASE_PATH is missing.
+ For example: /etc/galley/galleydata_prod.db
"""
maybe_ipv6 = if System.get_env("ECTO_IPV6"), do: [:inet6], else: []
M config/test.exs => config/test.exs +3 -6
@@ 9,12 9,9 @@ config :bcrypt_elixir, :log_rounds, 1
# to provide built-in test partitioning in CI environment.
# Run `mix help test` for more information.
config :galley, Galley.Repo,
- username: "postgres",
- password: "postgres",
- hostname: "localhost",
- database: "galley_test#{System.get_env("MIX_TEST_PARTITION")}",
- pool: Ecto.Adapters.SQL.Sandbox,
- pool_size: 10
+ database: Path.expand("../galleydata_dev.db", Path.dirname(__ENV__.file)),
+ pool_size: 5
+ show_sensitive_data_on_connection_error: true,
# We don't run a server during test. If one is required,
# you can enable the server option below.
M lib/galley/recipes.ex => lib/galley/recipes.ex +3 -3
@@ 7,7 7,7 @@ defmodule Galley.Recipes do
alias Galley.Repo
alias Ecto.Multi
- alias Galley.Recipes.{Recipe, Tag, RecipeTag, Ingredient}
+ alias Galley.Recipes.{Recipe, Tag, Ingredient}
@doc """
Returns the list of recipes.
@@ 29,7 29,7 @@ defmodule Galley.Recipes do
def search_recipes(%{"filter" => filter, "query" => search_query, "tags" => tags}, user_id) do
s_conditions =
if search_query !== "",
- do: dynamic([r], ilike(r.title, ^"%#{search_query}%")),
+ do: dynamic([r], like(r.title, ^"%#{search_query}%")),
else: true
f_conditions =
@@ 204,7 204,7 @@ defmodule Galley.Recipes do
# get just recipe ids
select: recipe_tags.recipe_id,
# remove duplicate ids
- distinct: recipe_tags.recipe_id
+ group_by: recipe_tags.recipe_id
Repo.all(q)
end
M lib/galley/repo.ex => lib/galley/repo.ex +1 -1
@@ 1,5 1,5 @@
defmodule Galley.Repo do
use Ecto.Repo,
otp_app: :galley,
- adapter: Ecto.Adapters.Postgres
+ adapter: Ecto.Adapters.SQLite3
end
M mix.exs => mix.exs +2 -1
@@ 37,7 37,8 @@ defmodule Galley.MixProject do
{:phoenix, "~> 1.6.6"},
{:phoenix_ecto, "~> 4.4"},
{:ecto_sql, "~> 3.6"},
- {:postgrex, ">= 0.0.0"},
+ # {:postgrex, ">= 0.0.0"},
+ {:ecto_sqlite3, ">= 0.0.0"},
{:phoenix_html, "~> 3.0"},
{:phoenix_live_reload, "~> 1.2", only: :dev},
{:phoenix_live_view, "~> 0.17.9"},
M mix.lock => mix.lock +2 -0
@@ 10,8 10,10 @@
"decimal": {:hex, :decimal, "2.0.0", "a78296e617b0f5dd4c6caf57c714431347912ffb1d0842e998e9792b5642d697", [:mix], [], "hexpm", "34666e9c55dea81013e77d9d87370fe6cb6291d1ef32f46a1600230b1d44f577"},
"ecto": {:hex, :ecto, "3.7.2", "44c034f88e1980754983cc4400585970b4206841f6f3780967a65a9150ef09a8", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "a600da5772d1c31abbf06f3e4a1ffb150e74ed3e2aa92ff3cee95901657a874e"},
"ecto_sql": {:hex, :ecto_sql, "3.7.2", "55c60aa3a06168912abf145c6df38b0295c34118c3624cf7a6977cd6ce043081", [:mix], [{:db_connection, "~> 2.2", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.7.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.4.0 or ~> 0.5.0 or ~> 0.6.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.15.0 or ~> 0.16.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", "3c218ea62f305dcaef0b915fb56583195e7b91c91dcfb006ba1f669bfacbff2a"},
+ "ecto_sqlite3": {:hex, :ecto_sqlite3, "0.7.5", "b11bb3b1acc42e347c79eb3de0a1c8cb85d97b53dedd6e2c6981ccfe1db6c638", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:ecto, "~> 3.7", [hex: :ecto, repo: "hexpm", optional: false]}, {:ecto_sql, "~> 3.7", [hex: :ecto_sql, repo: "hexpm", optional: false]}, {:exqlite, "~> 0.9", [hex: :exqlite, repo: "hexpm", optional: false]}], "hexpm", "66ebe8b8580fb4c6bf3fac7f5e2622f382563833024bbbbc333d655d61fe6b8d"},
"elixir_make": {:hex, :elixir_make, "0.6.3", "bc07d53221216838d79e03a8019d0839786703129599e9619f4ab74c8c096eac", [:mix], [], "hexpm", "f5cbd651c5678bcaabdbb7857658ee106b12509cd976c2c2fca99688e1daf716"},
"esbuild": {:hex, :esbuild, "0.4.0", "9f17db148aead4cf1e6e6a584214357287a93407b5fb51a031f122b61385d4c2", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}], "hexpm", "b61e4e6b92ffe45e4ee4755a22de6211a67c67987dc02afb35a425a0add1d447"},
+ "exqlite": {:hex, :exqlite, "0.11.1", "f485df105551f1509eda2fd4f79985dcc0cb75a9c7901c7f579c94e8df0a9f9d", [:make, :mix], [{:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "375939c98e54702582bb2c31c4dbbcf1e779b16f9fdc7566fdb7e2c6dacab542"},
"file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"},
"floki": {:hex, :floki, "0.32.1", "dfe3b8db3b793939c264e6f785bca01753d17318d144bd44b407fb3493acaa87", [:mix], [{:html_entities, "~> 0.5.0", [hex: :html_entities, repo: "hexpm", optional: false]}], "hexpm", "d4b91c713e4a784a3f7b1e3cc016eefc619f6b1c3898464222867cafd3c681a3"},
"gettext": {:hex, :gettext, "0.19.1", "564953fd21f29358e68b91634799d9d26989f8d039d7512622efb3c3b1c97892", [:mix], [], "hexpm", "10c656c0912b8299adba9b061c06947511e3f109ab0d18b44a866a4498e77222"},
M priv/repo/migrations/20220403173134_create_users_auth_tables.exs => priv/repo/migrations/20220403173134_create_users_auth_tables.exs +0 -2
@@ 2,8 2,6 @@ defmodule Galley.Repo.Migrations.CreateUsersAuthTables do
use Ecto.Migration
def change do
- execute "CREATE EXTENSION IF NOT EXISTS citext", ""
-
create table(:users) do
add :email, :citext, null: false
add :hashed_password, :string, null: false
M priv/repo/migrations/20220420202834_add_uploaded_images_to_recipes.exs => priv/repo/migrations/20220420202834_add_uploaded_images_to_recipes.exs +1 -1
@@ 3,7 3,7 @@ defmodule Galley.Repo.Migrations.AddUploadedImagesToRecipes do
def change do
alter table(:recipes) do
- add :uploaded_images, {:array, :string}, default: []
+ add :uploaded_images, {:array, :map}, default: []
end
end
end
D priv/repo/migrations/20220422013409_change_uploaded_images_recipes_to_map.exs => priv/repo/migrations/20220422013409_change_uploaded_images_recipes_to_map.exs +0 -11
@@ 1,11 0,0 @@
-defmodule Galley.Repo.Migrations.ChangeUploadedImagesRecipesToMap do
- use Ecto.Migration
-
- def change do
- alter table(:recipes) do
- remove :uploaded_images
- # couldn't convert to the below so I just remove the column.
- add :uploaded_images, {:array, :map}, default: []
- end
- end
-end
M priv/repo/seeds.exs => priv/repo/seeds.exs +122 -0
@@ 9,3 9,125 @@
#
# We recommend using the bang functions (`insert!`, `update!`
# and so on) as they will fail if something goes wrong.
+#
+
+Galley.Accounts.register_user(%{
+ email: "weakty@theiceshelf.com",
+ username: "weakty",
+ password: "password1234"
+})
+
+user = Galley.Accounts.get_user_by_email("weakty@theiceshelf.com")
+
+## === Recipe ==================================================================
+
+y = Galley.Recipes.insert_recipe(
+ user,
+ %{
+ "ingredients" => %{
+ "0" => %{
+ "ingredient" => "coconut oil",
+ "measurement" => "tbsp",
+ "quantity" => "1",
+ "temp_id" => "1c6gb"
+ },
+ "1" => %{
+ "ingredient" => "mixed fresh vegetables",
+ "measurement" => "cups",
+ "quantity" => "4",
+ "temp_id" => "2c6gb"
+ },
+ "2" => %{
+ "ingredient" => "Red lentils (uncooked)",
+ "measurement" => "cup",
+ "quantity" => "1/2",
+ "temp_id" => "3c6gb"
+ },
+ "3" => %{
+ "ingredient" => "water",
+ "measurement" => "cup",
+ "quantity" => "1/2",
+ "temp_id" => "4c6gb"
+ },
+ "4" => %{
+ "ingredient" => "diced tomato",
+ "measurement" => "oz",
+ "quantity" => "14",
+ "temp_id" => "5c6gb"
+ },
+ "5" => %{
+ "ingredient" => "coconut milk",
+ "measurement" => "oz",
+ "quantity" => "14",
+ "temp_id" => "6c6gb"
+ },
+ "6" => %{
+ "ingredient" => "garlic powder",
+ "measurement" => "tsp",
+ "quantity" => "1.5",
+ "temp_id" => "7c6gb"
+ },
+ "7" => %{
+ "ingredient" => "minced onion",
+ "measurement" => "tsp",
+ "quantity" => "1.5",
+ "temp_id" => "8c6gb"
+ },
+ "8" => %{
+ "ingredient" => "curry powder",
+ "measurement" => "tbsp",
+ "quantity" => "1",
+ "temp_id" => "9c6gb"
+ },
+ "9" => %{
+ "ingredient" => "sea salt",
+ "measurement" => "tsp",
+ "quantity" => "1",
+ "temp_id" => "L16gb"
+ },
+ "10" => %{
+ "ingredient" => "pepper",
+ "measurement" => "pinch",
+ "quantity" => "1",
+ "temp_id" => "L96gb"
+ }
+ },
+ "notes" => "",
+ "source" => "https://ohsheglows.com/2017/07/21/8-minute-pantry-dal-two-ways/",
+ "steps" => %{
+ "0" => %{
+ "instruction" => "Melt coconut oil in a large pot.",
+ "temp_id" => "qI0-E"
+ },
+ "1" => %{
+ "instruction" =>
+ "Peel (if necessary) and dice vegetables into 1/2 inch pieces. Add to pot and stir.",
+ "temp_id" => "qI0-D"
+ },
+ "2" => %{
+ "instruction" =>
+ "Add the rest of the ingredients (coconut milk, diced tomato, garlic powder, minced onion, curry powder lentils).",
+ "temp_id" => "qI1-D"
+ },
+ "3" => %{
+ "instruction" => "Bring to a boil and the reduce heat to medium.",
+ "temp_id" => "qI2-D"
+ },
+ "4" => %{
+ "instruction" =>
+ "Cook for 18-30 minutes. Stir and taste frequently. Remove from heat when vegetables are tender.",
+ "temp_id" => "qI3-D",
+ "timer" => %{"hour" => "0", "minute" => "18"}
+ },
+ "5" => %{
+ "instruction" => "Serve over rice. Optional: Garnish with cilantro and lime.",
+ "temp_id" => "qI4-D"
+ }
+ },
+ "tags" => "",
+ "time" => %{"hour" => "0", "minute" => "0"},
+ "title" => "Pantry Dahl",
+ "uploaded_images" => [],
+ "yields" => "4 servings"
+ }
+)