artists: convert other_names to array (#3987).

This commit is contained in:
evazion
2018-11-14 15:54:51 -06:00
parent 741462ae68
commit 41ff05c121
10 changed files with 60 additions and 53 deletions

View File

@@ -0,0 +1,23 @@
class ChangeOtherNamesToArrayOnArtists < ActiveRecord::Migration[5.2]
def up
Artist.without_timeout do
remove_index :artists, name: "index_artists_on_other_names_trgm"
change_column :artists, :other_names, "text[]", using: "array_remove(regexp_split_to_array(other_names, '\\s+'), '')", default: "{}"
add_index :artists, :other_names, using: :gin
remove_column :artists, :other_names_index
execute "DROP TRIGGER trigger_artists_on_update ON artists"
end
end
def down
Artist.without_timeout do
remove_index :artists, :other_names
change_column :artists, :other_names, "text", using: "array_to_string(other_names, ' ')", default: nil
add_index :artists, :other_names, name: "index_artists_on_other_names_trgm", using: :gin, opclass: :gin_trgm_ops
add_column :artists, :other_names_index, :tsvector
execute "CREATE TRIGGER trigger_artists_on_update BEFORE INSERT OR UPDATE ON artists FOR EACH ROW EXECUTE PROCEDURE tsvector_update_trigger('other_names_index', 'public.danbooru', 'other_names')"
end
end
end