Skip to content

Commit f2f98cc

Browse files
committed
backup
1 parent d379564 commit f2f98cc

File tree

3 files changed

+16
-34
lines changed

3 files changed

+16
-34
lines changed

lib/sanbase/menu/menus.ex

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -121,19 +121,19 @@ defmodule Sanbase.Menus do
121121
)
122122
end
123123
end)
124-
|> Ecto.Multi.run(
125-
:get_menu_with_preloads,
126-
fn _repo, %{create_menu: menu, maybe_create_menu_item: menu_or_nil} ->
127-
# If the menu was created as a sub-menu, then the `maybe_create_menu_item` step
128-
# has already returned the menu with preloads. Otherwise, we need to preload it here.
129-
case menu_or_nil do
130-
%Menu{} = m -> {:ok, m}
131-
nil -> get_menu(menu.id, user_id)
132-
end
133-
end
134-
)
124+
# |> Ecto.Multi.run(
125+
# :get_menu_with_preloads,
126+
# fn _repo, %{create_menu: menu, maybe_create_menu_item: menu_or_nil} ->
127+
# # If the menu was created as a sub-menu, then the `maybe_create_menu_item` step
128+
# # has already returned the menu with preloads. Otherwise, we need to preload it here.
129+
# case menu_or_nil do
130+
# %Menu{} = m -> {:ok, m}
131+
# nil -> get_menu(menu.id, user_id)
132+
# end
133+
# end
134+
# )
135135
|> Repo.transaction()
136-
|> process_transaction_result(:get_menu_with_preloads)
136+
|> process_transaction_result(:create_menu)
137137
end
138138

139139
@doc ~s"""

priv/repo/migrations/20231110093800_create_menus_table.exs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ defmodule Sanbase.Repo.Migrations.CreatesMenusTable do
22
use Ecto.Migration
33

44
def change do
5+
# Create menus table
56
create table(:menus) do
67
add(:name, :string)
78
add(:description, :string)
89

9-
add(:parent_id, references(:menus, on_delete: :delete_all))
10+
add(:parent_id, references(:menus, on_delete: :nilify_all))
1011

1112
add(:user_id, references(:users, on_delete: :delete_all))
1213

@@ -15,12 +16,9 @@ defmodule Sanbase.Repo.Migrations.CreatesMenusTable do
1516
timestamps()
1617
end
1718

18-
# When searching for all sub-menus of a menu, the `where` clause will
19-
# find these submenus by the root_parent_id, hence the index. The
20-
# parent_id is used only to build the hierarchy after that.
21-
create(index(:menus, [:root_parent_id]))
2219
create(index(:menus, [:user_id]))
2320

21+
# Create menu_items table
2422
create table(:menu_items) do
2523
add(:parent_id, references(:menus, on_delete: :delete_all))
2624

priv/repo/structure.sql

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2062,7 +2062,6 @@ CREATE TABLE public.menus (
20622062
name character varying(255),
20632063
description character varying(255),
20642064
parent_id bigint,
2065-
root_parent_id bigint,
20662065
user_id bigint,
20672066
is_global boolean DEFAULT false,
20682067
inserted_at timestamp without time zone NOT NULL,
@@ -6735,13 +6734,6 @@ CREATE UNIQUE INDEX list_items_user_list_id_project_id_index ON public.list_item
67356734
CREATE UNIQUE INDEX market_segments_name_index ON public.market_segments USING btree (name);
67366735

67376736

6738-
--
6739-
-- Name: menus_root_parent_id_index; Type: INDEX; Schema: public; Owner: -
6740-
--
6741-
6742-
CREATE INDEX menus_root_parent_id_index ON public.menus USING btree (root_parent_id);
6743-
6744-
67456737
--
67466738
-- Name: menus_user_id_index; Type: INDEX; Schema: public; Owner: -
67476739
--
@@ -7922,15 +7914,7 @@ ALTER TABLE ONLY public.menu_items
79227914
--
79237915

79247916
ALTER TABLE ONLY public.menus
7925-
ADD CONSTRAINT menus_parent_id_fkey FOREIGN KEY (parent_id) REFERENCES public.menus(id) ON DELETE CASCADE;
7926-
7927-
7928-
--
7929-
-- Name: menus menus_root_parent_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
7930-
--
7931-
7932-
ALTER TABLE ONLY public.menus
7933-
ADD CONSTRAINT menus_root_parent_id_fkey FOREIGN KEY (root_parent_id) REFERENCES public.menus(id) ON DELETE CASCADE;
7917+
ADD CONSTRAINT menus_parent_id_fkey FOREIGN KEY (parent_id) REFERENCES public.menus(id) ON DELETE SET NULL;
79347918

79357919

79367920
--

0 commit comments

Comments
 (0)