Skip to content

Commit

Permalink
Add missing indexes to shifts
Browse files Browse the repository at this point in the history
  • Loading branch information
woarewe committed Apr 4, 2023
1 parent 224a218 commit 83827dc
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
8 changes: 8 additions & 0 deletions app/gateways/rest/api/organizations/shifts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,18 @@ def select_shifts(filters)
end

class Contract < Dry::Validation::Contract
MAX_PERIOD = 31

params do
required(:from).filled(:date_time)
required(:to).filled(:date_time)
end

rule(:from, :to) do
next if values[:to] - values[:from] > MAX_PERIOD.days

key(:period).failure(I18n.t!("rest.api.organizations.shifts.errors.long_period", period: MAX_PERIOD))
end
end

desc "Get organization shifts"
Expand Down
5 changes: 5 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
en:
rest:
api:
organizations:
shifts:
errors:
long_period: "The retrieving period should be <= %{period} days"
services:
authentication:
errors:
Expand Down
10 changes: 10 additions & 0 deletions db/migrate/20230404154936_add_indexes_to_shifts.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

class AddIndexesToShifts < ActiveRecord::Migration[7.0]
disable_ddl_transaction!

def change
add_index :shifts, [:start_at, :end_at], algorithm: :concurrently
add_index :shifts, :worker_id
end
end
17 changes: 16 additions & 1 deletion db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,20 @@ CREATE UNIQUE INDEX index_organizations_on_name ON public.organizations USING bt
CREATE UNIQUE INDEX index_shifts_on_external_id ON public.shifts USING btree (external_id);


--
-- Name: index_shifts_on_start_at_and_end_at; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX index_shifts_on_start_at_and_end_at ON public.shifts USING btree (start_at, end_at);


--
-- Name: index_shifts_on_worker_id; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX index_shifts_on_worker_id ON public.shifts USING btree (worker_id);


--
-- Name: index_workers_on_external_id; Type: INDEX; Schema: public; Owner: -
--
Expand Down Expand Up @@ -407,6 +421,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20230331212610'),
('20230401100644'),
('20230401124829'),
('20230401165334');
('20230401165334'),
('20230404154936');


0 comments on commit 83827dc

Please sign in to comment.