1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
5 require './db/migrate/20161213172944_full_text_search_indexes'
7 class PropertiesToJsonb < ActiveRecord::Migration[4.2]
9 @@tables_columns = [["nodes", "properties"],
11 ["container_requests", "properties"],
12 ["links", "properties"]]
15 @@tables_columns.each do |table, column|
16 # Drop the FT index before changing column type to avoid
17 # "PG::DatatypeMismatch: ERROR: COALESCE types jsonb and text
19 ActiveRecord::Base.connection.execute "DROP INDEX IF EXISTS #{table}_full_text_search_idx"
20 ActiveRecord::Base.connection.execute "ALTER TABLE #{table} ALTER COLUMN #{column} TYPE jsonb USING #{column}::jsonb"
21 ActiveRecord::Base.connection.execute "CREATE INDEX #{table}_index_on_#{column} ON #{table} USING gin (#{column})"
23 FullTextSearchIndexes.new.replace_index("container_requests")
27 @@tables_columns.each do |table, column|
28 ActiveRecord::Base.connection.execute "DROP INDEX IF EXISTS #{table}_index_on_#{column}"
29 ActiveRecord::Base.connection.execute "ALTER TABLE #{table} ALTER COLUMN #{column} TYPE text"