You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20191201192510_convert_to_args.rb 510B

123456789101112131415
  1. class ConvertToArgs < ActiveRecord::Migration[5.2]
  2. def self.up
  3. add_column :analyses, :args, :jsonb, after: :host
  4. Analysis.all.each { |a| a.update! args: { port: a.port }.compact }
  5. add_index :analyses, %i[service host args], unique: true
  6. remove_column :analyses, :port
  7. end
  8. def self.down
  9. add_column :analyses, :port, :integer
  10. Analysis.all.each { |a| a.update! port: a.args }
  11. remove_column :analyses, :args
  12. add_index :analyses, %i[service host port], unique: true
  13. end
  14. end