File tree Expand file tree Collapse file tree 3 files changed +16
-34
lines changed Expand file tree Collapse file tree 3 files changed +16
-34
lines changed Original file line number Diff line number Diff line change @@ -121,19 +121,19 @@ defmodule Sanbase.Menus do
121
121
)
122
122
end
123
123
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
+ # )
135
135
|> Repo . transaction ( )
136
- |> process_transaction_result ( :get_menu_with_preloads )
136
+ |> process_transaction_result ( :create_menu )
137
137
end
138
138
139
139
@ doc ~s"""
Original file line number Diff line number Diff line change @@ -2,11 +2,12 @@ defmodule Sanbase.Repo.Migrations.CreatesMenusTable do
2
2
use Ecto.Migration
3
3
4
4
def change do
5
+ # Create menus table
5
6
create table ( :menus ) do
6
7
add ( :name , :string )
7
8
add ( :description , :string )
8
9
9
- add ( :parent_id , references ( :menus , on_delete: :delete_all ) )
10
+ add ( :parent_id , references ( :menus , on_delete: :nilify_all ) )
10
11
11
12
add ( :user_id , references ( :users , on_delete: :delete_all ) )
12
13
@@ -15,12 +16,9 @@ defmodule Sanbase.Repo.Migrations.CreatesMenusTable do
15
16
timestamps ( )
16
17
end
17
18
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 ] ) )
22
19
create ( index ( :menus , [ :user_id ] ) )
23
20
21
+ # Create menu_items table
24
22
create table ( :menu_items ) do
25
23
add ( :parent_id , references ( :menus , on_delete: :delete_all ) )
26
24
Original file line number Diff line number Diff line change @@ -2062,7 +2062,6 @@ CREATE TABLE public.menus (
2062
2062
name character varying (255 ),
2063
2063
description character varying (255 ),
2064
2064
parent_id bigint ,
2065
- root_parent_id bigint ,
2066
2065
user_id bigint ,
2067
2066
is_global boolean DEFAULT false,
2068
2067
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
6735
6734
CREATE UNIQUE INDEX market_segments_name_index ON public .market_segments USING btree (name);
6736
6735
6737
6736
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
-
6745
6737
--
6746
6738
-- Name: menus_user_id_index; Type: INDEX; Schema: public; Owner: -
6747
6739
--
@@ -7922,15 +7914,7 @@ ALTER TABLE ONLY public.menu_items
7922
7914
--
7923
7915
7924
7916
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 ;
7934
7918
7935
7919
7936
7920
--
You can’t perform that action at this time.
0 commit comments