mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-26 09:42:46 +08:00
Fix indices [SCI-5829]
This commit is contained in:
parent
879cf5081d
commit
eaa713f5b8
4 changed files with 53 additions and 5 deletions
|
@ -43,6 +43,8 @@ module SearchableModel
|
|||
(attrs.map.with_index do |a, i|
|
||||
if %w(repository_rows.id repository_number_values.data).include?(a)
|
||||
"((#{a})::text) #{like} :t#{i} OR "
|
||||
elsif a == "('EX' || id)"
|
||||
"('EX' || id) #{like} :t#{i} OR "
|
||||
else
|
||||
col = options[:at_search].to_s == 'true' ? "lower(#{a})": a
|
||||
"(trim_html_tags(#{col})) #{like} :t#{i} OR "
|
||||
|
@ -67,6 +69,8 @@ module SearchableModel
|
|||
(attrs.map.with_index do |a, i|
|
||||
if %w(repository_rows.id repository_number_values.data).include?(a)
|
||||
"((#{a})::text) #{like} ANY (array[:t#{i}]) OR "
|
||||
elsif a == "('EX' || id)"
|
||||
"('EX' || id) #{like} :t#{i} OR "
|
||||
else
|
||||
"(trim_html_tags(#{a})) #{like} ANY (array[:t#{i}]) OR "
|
||||
end
|
||||
|
@ -86,6 +90,8 @@ module SearchableModel
|
|||
(attrs.map.with_index do |a, i|
|
||||
if %w(repository_rows.id repository_number_values.data).include?(a)
|
||||
"((#{a})::text) #{like} :t#{i} OR "
|
||||
elsif a == "('EX' || id)"
|
||||
"('EX' || id) #{like} :t#{i} OR "
|
||||
else
|
||||
"(trim_html_tags(#{a})) #{like} :t#{i} OR "
|
||||
end
|
||||
|
|
|
@ -1,7 +1,15 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddCodeIndexToExperiments < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
add_index :experiments, "('EX' || id)", name: 'index_experiments_on_experiment_code', unique: true
|
||||
def up
|
||||
ActiveRecord::Base.connection.execute(
|
||||
"CREATE INDEX index_experiments_on_experiment_code ON experiments using gin (('EX'::text || id) gin_trgm_ops);"
|
||||
)
|
||||
end
|
||||
|
||||
def down
|
||||
ActiveRecord::Base.connection.execute(
|
||||
'DROP INDEX index_experiments_on_experiment_code;'
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
26
db/migrate/20210622101238_fix_experiment_indices.rb
Normal file
26
db/migrate/20210622101238_fix_experiment_indices.rb
Normal file
|
@ -0,0 +1,26 @@
|
|||
class FixExperimentIndices < ActiveRecord::Migration[6.1]
|
||||
def up
|
||||
remove_index :experiments, name: 'index_experiments_on_name', column: 'name'
|
||||
|
||||
|
||||
ActiveRecord::Base.connection.execute(
|
||||
"CREATE INDEX index_experiments_on_name ON experiments using gin (trim_html_tags(name) gin_trgm_ops);"
|
||||
)
|
||||
|
||||
ActiveRecord::Base.connection.execute(
|
||||
"CREATE INDEX index_experiments_on_description ON experiments using gin (trim_html_tags(description) gin_trgm_ops);"
|
||||
)
|
||||
end
|
||||
|
||||
def down
|
||||
ActiveRecord::Base.connection.execute(
|
||||
'DROP INDEX index_experiments_on_name;'
|
||||
)
|
||||
|
||||
ActiveRecord::Base.connection.execute(
|
||||
'DROP INDEX index_experiments_on_description;'
|
||||
)
|
||||
|
||||
add_index :experiments, :name
|
||||
end
|
||||
end
|
|
@ -4349,11 +4349,18 @@ CREATE INDEX index_experiments_on_archived_by_id ON public.experiments USING btr
|
|||
CREATE INDEX index_experiments_on_created_by_id ON public.experiments USING btree (created_by_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_experiments_on_description; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_experiments_on_description ON public.experiments USING gin (public.trim_html_tags(description) public.gin_trgm_ops);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_experiments_on_experiment_code; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE UNIQUE INDEX index_experiments_on_experiment_code ON public.experiments USING btree ((('EX'::text || id)));
|
||||
CREATE INDEX index_experiments_on_experiment_code ON public.experiments USING gin ((('EX'::text || id)) public.gin_trgm_ops);
|
||||
|
||||
|
||||
--
|
||||
|
@ -4367,7 +4374,7 @@ CREATE INDEX index_experiments_on_last_modified_by_id ON public.experiments USIN
|
|||
-- Name: index_experiments_on_name; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_experiments_on_name ON public.experiments USING btree (name);
|
||||
CREATE INDEX index_experiments_on_name ON public.experiments USING gin (public.trim_html_tags((name)::text) public.gin_trgm_ops);
|
||||
|
||||
|
||||
--
|
||||
|
@ -7243,6 +7250,7 @@ INSERT INTO "schema_migrations" (version) VALUES
|
|||
('20210407143303'),
|
||||
('20210410100006'),
|
||||
('20210506125657'),
|
||||
('20210618104853');
|
||||
('20210618104853'),
|
||||
('20210622101238');
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue