From 86e307ad86bd5956728c5ad96fe3a221263635a7 Mon Sep 17 00:00:00 2001 From: Camilo Date: Sun, 9 Mar 2025 12:54:56 -0300 Subject: [PATCH 1/5] From 44f181b36a2453085a5b76b3646476647ee68075 Mon Sep 17 00:00:00 2001 From: clsource Date: Mon, 10 Mar 2025 11:04:06 -0300 Subject: [PATCH 2/5] added brands schemas --- tololo/core/lib/brands.ex | 21 +++++++ tololo/core/lib/brands/branch.ex | 96 ++++++++++++++++++++++++++++++++ tololo/core/lib/brands/brand.ex | 92 ++++++++++++++++++++++++++++++ 3 files changed, 209 insertions(+) create mode 100644 tololo/core/lib/brands.ex create mode 100644 tololo/core/lib/brands/branch.ex create mode 100644 tololo/core/lib/brands/brand.ex diff --git a/tololo/core/lib/brands.ex b/tololo/core/lib/brands.ex new file mode 100644 index 0000000..49c47f7 --- /dev/null +++ b/tololo/core/lib/brands.ex @@ -0,0 +1,21 @@ +defmodule TololoCore.Brands do + @moduledoc """ + Store the Brand associated. + """ + + use Ash.Domain, + otp_app: :tololo, + extensions: [AshGraphql, AshAdmin.Domain], + validate_config_inclusion?: false + + admin do + show?(true) + show_resources(TololoCore.Brands.Brand) + show_resources(TololoCore.Brands.Branch) + end + + resources do + resource TololoCore.Brands.Brand + resource TololoCore.Brands.Branch + end +end diff --git a/tololo/core/lib/brands/branch.ex b/tololo/core/lib/brands/branch.ex new file mode 100644 index 0000000..456c13a --- /dev/null +++ b/tololo/core/lib/brands/branch.ex @@ -0,0 +1,96 @@ +defmodule TololoCore.Brands.Branch do + @moduledoc """ + Define the data fields for storing store branch information. + """ + + use Ash.Resource, + otp_app: :tololo, + domain: TololoCore.Brands, + extensions: [AshGraphql.Resource, AshAdmin.Resource], + data_layer: AshPostgres.DataLayer, + authorizers: [Ash.Policy.Authorizer], + notifiers: [TololoCore.Kafka.AshNotifier] + + use Gettext. backend: TololoCore.Gettext + alias Ash.Changeset + + graphql do + type :branch + queries do + get :get_branch, :read + end + + mutations do + end + end + + admin do + end + + postgres do + table "branches" + repo Tololo.Repo + + references do + end + end + + field_policies do + field_policy :* do + description "the rest of the fields don't require any special policies" + authorize_if always() + end + end + + code_interface do + define :create + define :update + end + + actions do + defaults [:read, :destroy, create: :*, update: :*] + end + + policies do + bypass always() do + description "admin has access to every action" + authorize_if actor_attribute_equals(:access_level, :admin) + end + + policy action_type(:read) do + description "read access is always allowed" + authorize_if always() + end + end + + attributes do + uuid_v7_primary_key :id + + attribute :address, :string do + allow_nil? false + sensitive? false + public? true + end + + attribute :latitude, :float do + allow_nil? false + sensitive? true + public? true + end + + attribute :longitude, :float do + allow_nil? false + sensitive? true + public? true + end + + timestamps() + end + + relationships do + belongs_to :brand, TololoCore.Brands.Brand do + public? true + end + end + +end \ No newline at end of file diff --git a/tololo/core/lib/brands/brand.ex b/tololo/core/lib/brands/brand.ex new file mode 100644 index 0000000..16cc41d --- /dev/null +++ b/tololo/core/lib/brands/brand.ex @@ -0,0 +1,92 @@ +defmodule TololoCore.Brands.Brand do + @moduledoc """ + Define the data fields for storing store brand information. + """ + + use Ash.Resource, + otp_app: :tololo, + domain: TololoCore.Brands, + extensions: [AshGraphql.Resource, AshAdmin.Resource], + data_layer: AshPostgres.DataLayer, + authorizers: [Ash.Policy.Authorizer], + notifiers: [TololoCore.Kafka.AshNotifier] + + use Gettext. backend: TololoCore.Gettext + alias Ash.Changeset + + graphql do + type :brand + queries do + get :get_brand, :read + end + + mutations do + end + end + + admin do + end + + postgres do + table "brands" + repo Tololo.Repo + + references do + end + end + + field_policies do + field_policy :* do + description "the rest of the fields don't require any special policies" + authorize_if always() + end + end + + code_interface do + define :create + define :update + end + + actions do + defaults [:read, :destroy, create: :*, update: :*] + end + + policies do + bypass always() do + description "admin has access to every action" + authorize_if actor_attribute_equals(:access_level, :admin) + end + + policy action_type(:read) do + description "read access is always allowed" + authorize_if always() + end + end + + attributes do + uuid_v7_primary_key :id + + attribute :name, :string do + allow_nil? false + sensitive? false + public? true + end + + # Define a Headquarters Tololo URL to obtain + # Common brand and products information + attribute :hq_url, :string do + allow_nil? true + sensitive? true + public? false + end + + timestamps() + end + + relationships do + has_one :branch, TololoCore.Brands.Branch do + public? true + end + end + +end \ No newline at end of file From 5684db4b78b195e98c5b1d790546b72f0c74146e Mon Sep 17 00:00:00 2001 From: Camilo Date: Mon, 10 Mar 2025 15:57:06 -0300 Subject: [PATCH 3/5] iAdded migrations --- devenv.lock | 12 +- tololo/config/config.exs | 1 + tololo/core/lib/brands.ex | 3 +- tololo/core/lib/brands/branch.ex | 2 +- tololo/core/lib/brands/brand.ex | 2 +- .../repo/migrations/20250310183831_brand.exs | 56 +++++++++ .../repo/branches/20250310183831.json | 108 ++++++++++++++++++ .../repo/brands/20250310183831.json | 69 +++++++++++ 8 files changed, 243 insertions(+), 10 deletions(-) create mode 100644 tololo/priv/repo/migrations/20250310183831_brand.exs create mode 100644 tololo/priv/resource_snapshots/repo/branches/20250310183831.json create mode 100644 tololo/priv/resource_snapshots/repo/brands/20250310183831.json diff --git a/devenv.lock b/devenv.lock index 4e80bfc..0bee3ea 100644 --- a/devenv.lock +++ b/devenv.lock @@ -3,10 +3,10 @@ "devenv": { "locked": { "dir": "src/modules", - "lastModified": 1736184348, + "lastModified": 1741348424, "owner": "cachix", "repo": "devenv", - "rev": "07219f00c633f756d1f0cc5bb6c4c311b5c4cb0d", + "rev": "8f8c96bb1e0c6a59a97592328dc61b9fdbe7474b", "type": "github" }, "original": { @@ -40,10 +40,10 @@ ] }, "locked": { - "lastModified": 1737465171, + "lastModified": 1741379162, "owner": "cachix", "repo": "git-hooks.nix", - "rev": "9364dc02281ce2d37a1f55b6e51f7c0f65a75f17", + "rev": "b5a62751225b2f62ff3147d0a334055ebadcd5cc", "type": "github" }, "original": { @@ -89,10 +89,10 @@ }, "nixpkgs-unstable": { "locked": { - "lastModified": 1736798957, + "lastModified": 1741513245, "owner": "NixOS", "repo": "nixpkgs", - "rev": "9abb87b552b7f55ac8916b6fc9e5cb486656a2f3", + "rev": "e3e32b642a31e6714ec1b712de8c91a3352ce7e1", "type": "github" }, "original": { diff --git a/tololo/config/config.exs b/tololo/config/config.exs index e2e8737..b3a0d7e 100644 --- a/tololo/config/config.exs +++ b/tololo/config/config.exs @@ -73,6 +73,7 @@ config :tololo, TololoCore.Deliveries, TololoCore.Products, TololoCore.Carts, + TololoCore.Brands, Tololo.Accounts, Tololo.Extensions.TelegramBot.Ash.Users ], diff --git a/tololo/core/lib/brands.ex b/tololo/core/lib/brands.ex index 49c47f7..a04aa63 100644 --- a/tololo/core/lib/brands.ex +++ b/tololo/core/lib/brands.ex @@ -10,8 +10,7 @@ defmodule TololoCore.Brands do admin do show?(true) - show_resources(TololoCore.Brands.Brand) - show_resources(TololoCore.Brands.Branch) + show_resources([TololoCore.Brands.Brand, TololoCore.Brands.Branch]) end resources do diff --git a/tololo/core/lib/brands/branch.ex b/tololo/core/lib/brands/branch.ex index 456c13a..46b1047 100644 --- a/tololo/core/lib/brands/branch.ex +++ b/tololo/core/lib/brands/branch.ex @@ -11,7 +11,7 @@ defmodule TololoCore.Brands.Branch do authorizers: [Ash.Policy.Authorizer], notifiers: [TololoCore.Kafka.AshNotifier] - use Gettext. backend: TololoCore.Gettext + use Gettext, backend: TololoCore.Gettext alias Ash.Changeset graphql do diff --git a/tololo/core/lib/brands/brand.ex b/tololo/core/lib/brands/brand.ex index 16cc41d..bc4917c 100644 --- a/tololo/core/lib/brands/brand.ex +++ b/tololo/core/lib/brands/brand.ex @@ -11,7 +11,7 @@ defmodule TololoCore.Brands.Brand do authorizers: [Ash.Policy.Authorizer], notifiers: [TololoCore.Kafka.AshNotifier] - use Gettext. backend: TololoCore.Gettext + use Gettext, backend: TololoCore.Gettext alias Ash.Changeset graphql do diff --git a/tololo/priv/repo/migrations/20250310183831_brand.exs b/tololo/priv/repo/migrations/20250310183831_brand.exs new file mode 100644 index 0000000..f8276ec --- /dev/null +++ b/tololo/priv/repo/migrations/20250310183831_brand.exs @@ -0,0 +1,56 @@ +defmodule Tololo.Repo.Migrations.Brand do + @moduledoc """ + Updates resources based on their most recent snapshots. + + This file was autogenerated with `mix ash_postgres.generate_migrations` + """ + + use Ecto.Migration + + def up do + create table(:brands, primary_key: false) do + add :id, :uuid, null: false, default: fragment("uuid_generate_v7()"), primary_key: true + add :name, :text, null: false + add :hq_url, :text + + add :inserted_at, :utc_datetime_usec, + null: false, + default: fragment("(now() AT TIME ZONE 'utc')") + + add :updated_at, :utc_datetime_usec, + null: false, + default: fragment("(now() AT TIME ZONE 'utc')") + end + + create table(:branches, primary_key: false) do + add :id, :uuid, null: false, default: fragment("uuid_generate_v7()"), primary_key: true + add :address, :text, null: false + add :latitude, :float, null: false + add :longitude, :float, null: false + + add :inserted_at, :utc_datetime_usec, + null: false, + default: fragment("(now() AT TIME ZONE 'utc')") + + add :updated_at, :utc_datetime_usec, + null: false, + default: fragment("(now() AT TIME ZONE 'utc')") + + add :brand_id, + references(:brands, + column: :id, + name: "branches_brand_id_fkey", + type: :uuid, + prefix: "public" + ) + end + end + + def down do + drop constraint(:branches, "branches_brand_id_fkey") + + drop table(:branches) + + drop table(:brands) + end +end diff --git a/tololo/priv/resource_snapshots/repo/branches/20250310183831.json b/tololo/priv/resource_snapshots/repo/branches/20250310183831.json new file mode 100644 index 0000000..6fe2080 --- /dev/null +++ b/tololo/priv/resource_snapshots/repo/branches/20250310183831.json @@ -0,0 +1,108 @@ +{ + "attributes": [ + { + "allow_nil?": false, + "default": "fragment(\"uuid_generate_v7()\")", + "generated?": false, + "primary_key?": true, + "references": null, + "size": null, + "source": "id", + "type": "uuid" + }, + { + "allow_nil?": false, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "address", + "type": "text" + }, + { + "allow_nil?": false, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "latitude", + "type": "float" + }, + { + "allow_nil?": false, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "longitude", + "type": "float" + }, + { + "allow_nil?": false, + "default": "fragment(\"(now() AT TIME ZONE 'utc')\")", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "inserted_at", + "type": "utc_datetime_usec" + }, + { + "allow_nil?": false, + "default": "fragment(\"(now() AT TIME ZONE 'utc')\")", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "updated_at", + "type": "utc_datetime_usec" + }, + { + "allow_nil?": true, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": { + "deferrable": false, + "destination_attribute": "id", + "destination_attribute_default": null, + "destination_attribute_generated": null, + "index?": false, + "match_type": null, + "match_with": null, + "multitenancy": { + "attribute": null, + "global": null, + "strategy": null + }, + "name": "branches_brand_id_fkey", + "on_delete": null, + "on_update": null, + "primary_key?": true, + "schema": "public", + "table": "brands" + }, + "size": null, + "source": "brand_id", + "type": "uuid" + } + ], + "base_filter": null, + "check_constraints": [], + "custom_indexes": [], + "custom_statements": [], + "has_create_action": true, + "hash": "EA65D55C98B74D845EF9858378BF5A6EB0707F43366BC1A528E6E272671F3FA6", + "identities": [], + "multitenancy": { + "attribute": null, + "global": null, + "strategy": null + }, + "repo": "Elixir.Tololo.Repo", + "schema": null, + "table": "branches" +} \ No newline at end of file diff --git a/tololo/priv/resource_snapshots/repo/brands/20250310183831.json b/tololo/priv/resource_snapshots/repo/brands/20250310183831.json new file mode 100644 index 0000000..e0b45a2 --- /dev/null +++ b/tololo/priv/resource_snapshots/repo/brands/20250310183831.json @@ -0,0 +1,69 @@ +{ + "attributes": [ + { + "allow_nil?": false, + "default": "fragment(\"uuid_generate_v7()\")", + "generated?": false, + "primary_key?": true, + "references": null, + "size": null, + "source": "id", + "type": "uuid" + }, + { + "allow_nil?": false, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "name", + "type": "text" + }, + { + "allow_nil?": true, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "hq_url", + "type": "text" + }, + { + "allow_nil?": false, + "default": "fragment(\"(now() AT TIME ZONE 'utc')\")", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "inserted_at", + "type": "utc_datetime_usec" + }, + { + "allow_nil?": false, + "default": "fragment(\"(now() AT TIME ZONE 'utc')\")", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "updated_at", + "type": "utc_datetime_usec" + } + ], + "base_filter": null, + "check_constraints": [], + "custom_indexes": [], + "custom_statements": [], + "has_create_action": true, + "hash": "0B24FBD23BFF3F08B324FD4667F0437E738D29E173C80F9CE6B8536C362F15EF", + "identities": [], + "multitenancy": { + "attribute": null, + "global": null, + "strategy": null + }, + "repo": "Elixir.Tololo.Repo", + "schema": null, + "table": "brands" +} \ No newline at end of file From b120ad86a48548c7369b6fa44eeccce65f76100b Mon Sep 17 00:00:00 2001 From: rekkice Date: Mon, 10 Mar 2025 16:13:15 -0300 Subject: [PATCH 4/5] chore: moved location and name to branch resource --- tololo/config/config.exs | 2 - tololo/core/lib/brands/branch.ex | 21 ++-- tololo/core/lib/brands/brand.ex | 8 +- tololo/core/lib/deliveries/delivery.ex | 19 +-- tololo/lib/tololo/application.ex | 14 ++- .../migrations/20250310194854_branch_name.exs | 21 ++++ .../repo/branches/20250310194854.json | 118 ++++++++++++++++++ 7 files changed, 181 insertions(+), 22 deletions(-) create mode 100644 tololo/priv/repo/migrations/20250310194854_branch_name.exs create mode 100644 tololo/priv/resource_snapshots/repo/branches/20250310194854.json diff --git a/tololo/config/config.exs b/tololo/config/config.exs index b3a0d7e..c5f632f 100644 --- a/tololo/config/config.exs +++ b/tololo/config/config.exs @@ -64,8 +64,6 @@ config :tololo, ], pubsub: Tololo.PubSub, geocoding_endpoint: "https://nominatim.openstreetmap.org/search", - business_name: "Sushi", - from_location: {-33.04534, -71.4447094}, # set to 0 to disable stale cleaner days_for_stale: 2, min_done_distance_meters: 50, diff --git a/tololo/core/lib/brands/branch.ex b/tololo/core/lib/brands/branch.ex index 46b1047..016b483 100644 --- a/tololo/core/lib/brands/branch.ex +++ b/tololo/core/lib/brands/branch.ex @@ -3,12 +3,12 @@ defmodule TololoCore.Brands.Branch do Define the data fields for storing store branch information. """ - use Ash.Resource, + use Ash.Resource, otp_app: :tololo, domain: TololoCore.Brands, extensions: [AshGraphql.Resource, AshAdmin.Resource], data_layer: AshPostgres.DataLayer, - authorizers: [Ash.Policy.Authorizer], + authorizers: [Ash.Policy.Authorizer], notifiers: [TololoCore.Kafka.AshNotifier] use Gettext, backend: TololoCore.Gettext @@ -16,6 +16,7 @@ defmodule TololoCore.Brands.Branch do graphql do type :branch + queries do get :get_branch, :read end @@ -45,6 +46,7 @@ defmodule TololoCore.Brands.Branch do code_interface do define :create define :update + define :read, get?: true end actions do @@ -66,21 +68,27 @@ defmodule TololoCore.Brands.Branch do attributes do uuid_v7_primary_key :id + attribute :name, :string do + allow_nil? false + sensitive? false + public? true + end + attribute :address, :string do allow_nil? false sensitive? false public? true end - + attribute :latitude, :float do allow_nil? false - sensitive? true + sensitive? false public? true end attribute :longitude, :float do allow_nil? false - sensitive? true + sensitive? false public? true end @@ -92,5 +100,4 @@ defmodule TololoCore.Brands.Branch do public? true end end - -end \ No newline at end of file +end diff --git a/tololo/core/lib/brands/brand.ex b/tololo/core/lib/brands/brand.ex index bc4917c..f5934e9 100644 --- a/tololo/core/lib/brands/brand.ex +++ b/tololo/core/lib/brands/brand.ex @@ -3,12 +3,12 @@ defmodule TololoCore.Brands.Brand do Define the data fields for storing store brand information. """ - use Ash.Resource, + use Ash.Resource, otp_app: :tololo, domain: TololoCore.Brands, extensions: [AshGraphql.Resource, AshAdmin.Resource], data_layer: AshPostgres.DataLayer, - authorizers: [Ash.Policy.Authorizer], + authorizers: [Ash.Policy.Authorizer], notifiers: [TololoCore.Kafka.AshNotifier] use Gettext, backend: TololoCore.Gettext @@ -16,6 +16,7 @@ defmodule TololoCore.Brands.Brand do graphql do type :brand + queries do get :get_brand, :read end @@ -88,5 +89,4 @@ defmodule TololoCore.Brands.Brand do public? true end end - -end \ No newline at end of file +end diff --git a/tololo/core/lib/deliveries/delivery.ex b/tololo/core/lib/deliveries/delivery.ex index 284fa3c..c4825e7 100644 --- a/tololo/core/lib/deliveries/delivery.ex +++ b/tololo/core/lib/deliveries/delivery.ex @@ -159,14 +159,17 @@ defmodule TololoCore.Deliveries.Delivery do :to_notes ] - change set_attribute( - :from_name, - Application.compile_env(:tololo, :business_name, "A business") - ) - - {lat, lng} = Application.compile_env(:tololo, :from_location, {0, 0}) - change set_attribute(:from_latitude, lat) - change set_attribute(:from_longitude, lng) + change fn changeset, _context -> + {lat, lng} = Application.get_env(:tololo, :from_location, {0, 0}) + name = Application.get_env(:tololo, :business_name, "A business") + + changeset + |> Ash.Changeset.change_attributes(%{ + from_name: name, + from_latitude: lat, + from_longitude: lng + }) + end end create :empty do diff --git a/tololo/lib/tololo/application.ex b/tololo/lib/tololo/application.ex index f7c6bdc..b3a1340 100644 --- a/tololo/lib/tololo/application.ex +++ b/tololo/lib/tololo/application.ex @@ -31,7 +31,8 @@ defmodule Tololo.Application do {Finch, name: Tololo.Finch}, TololoWeb.Endpoint, {AshAuthentication.Supervisor, [otp_app: :tololo]}, - TololoCore.Deliveries.StaleCleaner + TololoCore.Deliveries.StaleCleaner, + {Task, fn -> load_config() end} ] ++ extensions Tololo.GeocodingStore.init() @@ -49,4 +50,15 @@ defmodule Tololo.Application do TololoWeb.Endpoint.config_change(changed, removed) :ok end + + def load_config do + %{latitude: lat, longitude: lng, name: name} = + case TololoCore.Brands.Branch.read() do + {:ok, branch_config} -> branch_config + _ -> %{latitude: 0, longitude: 0, name: "A business"} + end + + Application.put_env(:tololo, :from_location, {lat, lng}) + Application.put_env(:tololo, :business_name, name) + end end diff --git a/tololo/priv/repo/migrations/20250310194854_branch_name.exs b/tololo/priv/repo/migrations/20250310194854_branch_name.exs new file mode 100644 index 0000000..5becdc0 --- /dev/null +++ b/tololo/priv/repo/migrations/20250310194854_branch_name.exs @@ -0,0 +1,21 @@ +defmodule Tololo.Repo.Migrations.BranchName do + @moduledoc """ + Updates resources based on their most recent snapshots. + + This file was autogenerated with `mix ash_postgres.generate_migrations` + """ + + use Ecto.Migration + + def up do + alter table(:branches) do + add :name, :text, null: false + end + end + + def down do + alter table(:branches) do + remove :name + end + end +end diff --git a/tololo/priv/resource_snapshots/repo/branches/20250310194854.json b/tololo/priv/resource_snapshots/repo/branches/20250310194854.json new file mode 100644 index 0000000..6d5e853 --- /dev/null +++ b/tololo/priv/resource_snapshots/repo/branches/20250310194854.json @@ -0,0 +1,118 @@ +{ + "attributes": [ + { + "allow_nil?": false, + "default": "fragment(\"uuid_generate_v7()\")", + "generated?": false, + "primary_key?": true, + "references": null, + "size": null, + "source": "id", + "type": "uuid" + }, + { + "allow_nil?": false, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "name", + "type": "text" + }, + { + "allow_nil?": false, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "address", + "type": "text" + }, + { + "allow_nil?": false, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "latitude", + "type": "float" + }, + { + "allow_nil?": false, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "longitude", + "type": "float" + }, + { + "allow_nil?": false, + "default": "fragment(\"(now() AT TIME ZONE 'utc')\")", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "inserted_at", + "type": "utc_datetime_usec" + }, + { + "allow_nil?": false, + "default": "fragment(\"(now() AT TIME ZONE 'utc')\")", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "updated_at", + "type": "utc_datetime_usec" + }, + { + "allow_nil?": true, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": { + "deferrable": false, + "destination_attribute": "id", + "destination_attribute_default": null, + "destination_attribute_generated": null, + "index?": false, + "match_type": null, + "match_with": null, + "multitenancy": { + "attribute": null, + "global": null, + "strategy": null + }, + "name": "branches_brand_id_fkey", + "on_delete": null, + "on_update": null, + "primary_key?": true, + "schema": "public", + "table": "brands" + }, + "size": null, + "source": "brand_id", + "type": "uuid" + } + ], + "base_filter": null, + "check_constraints": [], + "custom_indexes": [], + "custom_statements": [], + "has_create_action": true, + "hash": "1AB6D6B3B50E34A765B984442F0FE675B61D9E2BF912C2AB0BA2E664C37F3AC7", + "identities": [], + "multitenancy": { + "attribute": null, + "global": null, + "strategy": null + }, + "repo": "Elixir.Tololo.Repo", + "schema": null, + "table": "branches" +} \ No newline at end of file From f4bd23a1118d3792bc602caf508589cf5c0fb0ca Mon Sep 17 00:00:00 2001 From: rekkice Date: Mon, 10 Mar 2025 16:22:26 -0300 Subject: [PATCH 5/5] chore: updated example seeds with brand and branch --- tololo/priv/repo/example_seeds.exs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tololo/priv/repo/example_seeds.exs b/tololo/priv/repo/example_seeds.exs index e943298..f3d5aed 100644 --- a/tololo/priv/repo/example_seeds.exs +++ b/tololo/priv/repo/example_seeds.exs @@ -31,8 +31,29 @@ Enum.each(product_names, fn product_name -> product -> Repo.delete!(product) end + end) +old_brand = TololoCore.Brands.Brand |> Ash.read_one! +if old_brand, do: Repo.delete!(old_brand) + +old_branch = TololoCore.Brands.Branch |> Ash.read_one! +if old_branch, do: Repo.delete!(old_branch) + +brand = TololoCore.Brands.Brand.create!(%{name: "Sushi"}, authorize?: false) + +branch = + TololoCore.Brands.Branch.create!( + %{ + name: "Sushi Quilpué", + latitude: -33.04534, + longitude: -71.4447094, + brand_id: brand.id, + address: "Quilpué" + }, + authorize?: false + ) + set_prices = fn variants, values_combination, price -> values_combination = if is_list(values_combination), do: values_combination, else: [values_combination]