From e4d5e4991c659bcd917dee50c0f936814ba342f8 Mon Sep 17 00:00:00 2001 From: SepsiLaszlo Date: Wed, 22 Jul 2020 19:26:39 +0200 Subject: [PATCH] Create unique keys --- app/models/entry_request.rb | 3 +- app/models/point_detail.rb | 4 +++ app/models/point_history.rb | 4 +++ app/models/post.rb | 3 +- ...200722171738_add_index_to_entry_request.rb | 5 +++ ...0200722171937_add_index_to_point_detail.rb | 5 +++ .../20200722172424_add_index_to_post.rb | 5 +++ ...200722173131_add_index_to_point_history.rb | 5 +++ db/structure.sql | 34 ++++++++++++++++++- 9 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20200722171738_add_index_to_entry_request.rb create mode 100644 db/migrate/20200722171937_add_index_to_point_detail.rb create mode 100644 db/migrate/20200722172424_add_index_to_post.rb create mode 100644 db/migrate/20200722173131_add_index_to_point_history.rb diff --git a/app/models/entry_request.rb b/app/models/entry_request.rb index a99da3a4..0935c083 100644 --- a/app/models/entry_request.rb +++ b/app/models/entry_request.rb @@ -10,7 +10,8 @@ # # Indexes # -# bel_tipus_idx (entry_type) +# bel_tipus_idx (entry_type) +# index_entry_requests_on_evaluation_id_and_user_id (evaluation_id,user_id) UNIQUE # # Foreign Keys # diff --git a/app/models/point_detail.rb b/app/models/point_detail.rb index 11bbab3b..d80db083 100644 --- a/app/models/point_detail.rb +++ b/app/models/point_detail.rb @@ -7,6 +7,10 @@ # point_request_id :integer # principle_id :integer # +# Indexes +# +# index_point_details_on_principle_id_and_point_request_id (principle_id,point_request_id) UNIQUE +# # Foreign Keys # # fk_rails_... (point_request_id => point_requests.id) diff --git a/app/models/point_history.rb b/app/models/point_history.rb index dd8edeee..bffda356 100644 --- a/app/models/point_history.rb +++ b/app/models/point_history.rb @@ -7,6 +7,10 @@ # semester :string(9) not null # user_id :bigint not null # +# Indexes +# +# index_point_histories_on_user_id_and_semester (user_id,semester) UNIQUE +# # Foreign Keys # # point_history_usr_id_fkey (user_id => users.id) diff --git a/app/models/post.rb b/app/models/post.rb index 15c356ce..84c1430e 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -8,7 +8,8 @@ # # Indexes # -# poszt_fk_idx (membership_id) +# index_posts_on_membership_id_and_post_type_id (membership_id,post_type_id) UNIQUE +# poszt_fk_idx (membership_id) # # Foreign Keys # diff --git a/db/migrate/20200722171738_add_index_to_entry_request.rb b/db/migrate/20200722171738_add_index_to_entry_request.rb new file mode 100644 index 00000000..dc65b228 --- /dev/null +++ b/db/migrate/20200722171738_add_index_to_entry_request.rb @@ -0,0 +1,5 @@ +class AddIndexToEntryRequest < ActiveRecord::Migration[5.0] + def change + add_index :entry_requests, [:evaluation_id, :user_id], unique: true + end +end diff --git a/db/migrate/20200722171937_add_index_to_point_detail.rb b/db/migrate/20200722171937_add_index_to_point_detail.rb new file mode 100644 index 00000000..dd966841 --- /dev/null +++ b/db/migrate/20200722171937_add_index_to_point_detail.rb @@ -0,0 +1,5 @@ +class AddIndexToPointDetail < ActiveRecord::Migration[5.0] + def change + add_index :point_details, [:principle_id, :point_request_id], unique: true + end +end diff --git a/db/migrate/20200722172424_add_index_to_post.rb b/db/migrate/20200722172424_add_index_to_post.rb new file mode 100644 index 00000000..80a5f064 --- /dev/null +++ b/db/migrate/20200722172424_add_index_to_post.rb @@ -0,0 +1,5 @@ +class AddIndexToPost < ActiveRecord::Migration[5.0] + def change + add_index :posts, [:membership_id, :post_type_id], unique: true + end +end diff --git a/db/migrate/20200722173131_add_index_to_point_history.rb b/db/migrate/20200722173131_add_index_to_point_history.rb new file mode 100644 index 00000000..6dc40eda --- /dev/null +++ b/db/migrate/20200722173131_add_index_to_point_history.rb @@ -0,0 +1,5 @@ +class AddIndexToPointHistory < ActiveRecord::Migration[5.0] + def change + add_index :point_histories, [:user_id, :semester], unique: true + end +end diff --git a/db/structure.sql b/db/structure.sql index 9d092994..52084253 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -1099,6 +1099,13 @@ CREATE INDEX idx_groups_grp_name ON public.groups USING btree (name); CREATE INDEX idx_groups_grp_type ON public.groups USING btree (grp_type); +-- +-- Name: index_entry_requests_on_evaluation_id_and_user_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE UNIQUE INDEX index_entry_requests_on_evaluation_id_and_user_id ON public.entry_requests USING btree (evaluation_id, user_id); + + -- -- Name: index_notifications_on_group_owner_id; Type: INDEX; Schema: public; Owner: - -- @@ -1148,6 +1155,20 @@ CREATE INDEX index_point_detail_comments_on_point_detail_id ON public.point_deta CREATE INDEX index_point_detail_comments_on_user_id ON public.point_detail_comments USING btree (user_id); +-- +-- Name: index_point_details_on_principle_id_and_point_request_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE UNIQUE INDEX index_point_details_on_principle_id_and_point_request_id ON public.point_details USING btree (principle_id, point_request_id); + + +-- +-- Name: index_point_histories_on_user_id_and_semester; Type: INDEX; Schema: public; Owner: - +-- + +CREATE UNIQUE INDEX index_point_histories_on_user_id_and_semester ON public.point_histories USING btree (user_id, semester); + + -- -- Name: index_point_requests_on_evaluation_id_and_user_id; Type: INDEX; Schema: public; Owner: - -- @@ -1155,6 +1176,13 @@ CREATE INDEX index_point_detail_comments_on_user_id ON public.point_detail_comme CREATE UNIQUE INDEX index_point_requests_on_evaluation_id_and_user_id ON public.point_requests USING btree (evaluation_id, user_id); +-- +-- Name: index_posts_on_membership_id_and_post_type_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE UNIQUE INDEX index_posts_on_membership_id_and_post_type_id ON public.posts USING btree (membership_id, post_type_id); + + -- -- Name: index_subscriptions_on_key; Type: INDEX; Schema: public; Owner: - -- @@ -1490,6 +1518,10 @@ INSERT INTO "schema_migrations" (version) VALUES ('20200127202810'), ('20200204185955'), ('20200611204210'), -('20200722112521'); +('20200722112521'), +('20200722171738'), +('20200722171937'), +('20200722172424'), +('20200722173131');