Remove check for database in migrations [SCI-11213]

This commit is contained in:
Andrej 2024-10-22 09:41:24 +02:00
parent 501e5a920d
commit e3e340d977
8 changed files with 180 additions and 203 deletions

View file

@ -3,8 +3,6 @@ include DatabaseHelper
class AddPgTrgmSupport < ActiveRecord::Migration[4.2] class AddPgTrgmSupport < ActiveRecord::Migration[4.2]
def up def up
if db_adapter_is? "PostgreSQL" then
enable_extension :pg_trgm enable_extension :pg_trgm
end end
end
end end

View file

@ -12,7 +12,6 @@ class AddSearchQueryIndexes < ActiveRecord::Migration[4.2]
# Add GIST trigram indexes onto columns that check for # Add GIST trigram indexes onto columns that check for
# ILIKE %pattern% during search # ILIKE %pattern% during search
if db_adapter_is? "PostgreSQL" then
add_gist_index :projects, :name add_gist_index :projects, :name
add_gist_index :my_modules, :name add_gist_index :my_modules, :name
add_gist_index :my_module_groups, :name add_gist_index :my_module_groups, :name
@ -24,7 +23,6 @@ class AddSearchQueryIndexes < ActiveRecord::Migration[4.2]
remove_index :samples, :name remove_index :samples, :name
add_gist_index :samples, :name add_gist_index :samples, :name
end end
end
def down def down
remove_index :projects, :team_id remove_index :projects, :team_id
@ -34,7 +32,6 @@ class AddSearchQueryIndexes < ActiveRecord::Migration[4.2]
remove_index :user_projects, :project_id remove_index :user_projects, :project_id
remove_index :tags, :project_id remove_index :tags, :project_id
if db_adapter_is? "PostgreSQL" then
remove_index :projects, :name remove_index :projects, :name
remove_index :my_modules, :name remove_index :my_modules, :name
remove_index :my_module_groups, :name remove_index :my_module_groups, :name
@ -46,5 +43,4 @@ class AddSearchQueryIndexes < ActiveRecord::Migration[4.2]
remove_index :samples, :name remove_index :samples, :name
add_index :samples, :name add_index :samples, :name
end end
end
end end

View file

@ -3,8 +3,6 @@ include DatabaseHelper
class AddBtreeGistExtension < ActiveRecord::Migration[4.2] class AddBtreeGistExtension < ActiveRecord::Migration[4.2]
def up def up
if db_adapter_is? "PostgreSQL" then
enable_extension :btree_gist enable_extension :btree_gist
end end
end
end end

View file

@ -5,8 +5,6 @@ class AddTextSearchVectorToAssetTextData < ActiveRecord::Migration[4.2]
def change def change
add_column :asset_text_data, :data_vector, :tsvector add_column :asset_text_data, :data_vector, :tsvector
if db_adapter_is? "PostgreSQL" then
add_index :asset_text_data, :data_vector, using: "gin" add_index :asset_text_data, :data_vector, using: "gin"
end end
end
end end

View file

@ -5,8 +5,6 @@ class AddTextSearchVectorToTables < ActiveRecord::Migration[4.2]
def change def change
add_column :tables, :data_vector, :tsvector add_column :tables, :data_vector, :tsvector
if db_adapter_is? "PostgreSQL" then
add_index :tables, :data_vector, using: "gin" add_index :tables, :data_vector, using: "gin"
end end
end
end end

View file

@ -3,12 +3,10 @@ include DatabaseHelper
class GenerateTextSearchVectorForTableContents < ActiveRecord::Migration[4.2] class GenerateTextSearchVectorForTableContents < ActiveRecord::Migration[4.2]
def up def up
if db_adapter_is? "PostgreSQL" then
execute <<-SQL execute <<-SQL
UPDATE tables UPDATE tables
SET data_vector = SET data_vector =
to_tsvector(substring(encode(contents::bytea, 'escape'), 9)) to_tsvector(substring(encode(contents::bytea, 'escape'), 9))
SQL SQL
end end
end
end end

View file

@ -3,7 +3,6 @@ include DatabaseHelper
class UpdateIndexesForFasterSearch < ActiveRecord::Migration[4.2] class UpdateIndexesForFasterSearch < ActiveRecord::Migration[4.2]
def up def up
if db_adapter_is? 'PostgreSQL'
# Removing old indexes # Removing old indexes
if index_name_exists? :projects, :index_projects_on_name if index_name_exists? :projects, :index_projects_on_name
remove_index :projects, name: :index_projects_on_name remove_index :projects, name: :index_projects_on_name
@ -127,13 +126,11 @@ class UpdateIndexesForFasterSearch < ActiveRecord::Migration[4.2]
add_index :protocols, :protocol_type add_index :protocols, :protocol_type
add_index :checklists, :step_id add_index :checklists, :step_id
end end
end
def down def down
# remove_index :steps, :team_id # remove_index :steps, :team_id
# remove_column :steps, :team_id, :integer # remove_column :steps, :team_id, :integer
if db_adapter_is? 'PostgreSQL'
remove_index :projects, :name remove_index :projects, :name
remove_index :my_modules, :name remove_index :my_modules, :name
remove_index :my_modules, :description remove_index :my_modules, :description
@ -161,8 +158,6 @@ class UpdateIndexesForFasterSearch < ActiveRecord::Migration[4.2]
remove_index :comments, :type remove_index :comments, :type
remove_index :protocols, :protocol_type remove_index :protocols, :protocol_type
remove_index :checklists, :step_id remove_index :checklists, :step_id
execute('DROP FUNCTION IF EXISTS trim_html_tags(IN input TEXT);') execute('DROP FUNCTION IF EXISTS trim_html_tags(IN input TEXT);')
end end
end
end end

View file

@ -3,19 +3,15 @@ include DatabaseHelper
class AddSearchIndexesToRepositories < ActiveRecord::Migration[4.2] class AddSearchIndexesToRepositories < ActiveRecord::Migration[4.2]
def up def up
if db_adapter_is? 'PostgreSQL'
if index_exists?(:repository_rows, :name) if index_exists?(:repository_rows, :name)
remove_index :repository_rows, :name remove_index :repository_rows, :name
end end
add_gin_index_without_tags :repository_rows, :name add_gin_index_without_tags :repository_rows, :name
add_gin_index_without_tags :repository_text_values, :data add_gin_index_without_tags :repository_text_values, :data
end end
end
def down def down
if db_adapter_is? 'PostgreSQL'
remove_index :repository_rows, :name remove_index :repository_rows, :name
remove_index :repository_text_values, :data remove_index :repository_text_values, :data
end end
end
end end