Skip to content

Commit

Permalink
also need to deal with extended metadata and template attributes #1648
Browse files Browse the repository at this point in the history
  • Loading branch information
stuzart committed Nov 14, 2023
1 parent 7ab85fa commit 1072900
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
1 change: 1 addition & 0 deletions app/models/sample_controlled_vocab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class SampleControlledVocab < ApplicationRecord
dependent: :destroy
has_many :sample_attributes, inverse_of: :sample_controlled_vocab
has_many :extended_metadata_attributes, inverse_of: :sample_controlled_vocab
has_many :template_attributes, inverse_of: :sample_controlled_vocab

has_many :sample_types, through: :sample_attributes
has_many :samples, through: :sample_types
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class AddAllowCvFreeTextToAttributes < ActiveRecord::Migration[6.1]
def change
add_column :sample_attributes, :allow_cv_free_text, :boolean, default: false
add_column :template_attributes, :allow_cv_free_text, :boolean, default: false
add_column :extended_metadata_attributes, :allow_cv_free_text, :boolean, default: false
end
end

This file was deleted.

18 changes: 15 additions & 3 deletions db/migrate/20231114110917_remove_custom_input_from_cv.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
class RemoveCustomInputFromCv < ActiveRecord::Migration[6.1]
def up
# Move to SampleAttribute first, for CV's without associated attributes the information will be lost
controlled_vocabs = SampleControlledVocab.where(custom_input: true).includes(:sample_attributes).select{|cv| cv.sample_attributes.any?}
# Move to Attribute first, for CV's without associated attributes the information will be lost
controlled_vocabs = SampleControlledVocab.where(custom_input: true).includes(:sample_attributes, :extended_metadata_attributes, :template_attributes)
controlled_vocabs.each do |controlled_vocab|
controlled_vocab.sample_attributes.update_all(allow_cv_free_text: true)
controlled_vocab.extended_metadata_attributes.update_all(allow_cv_free_text: true)
controlled_vocab.template_attributes.update_all(allow_cv_free_text: true)
end
remove_column :sample_controlled_vocabs, :custom_input
end
Expand All @@ -12,7 +14,17 @@ def down
add_column :sample_controlled_vocabs, :custom_input, :boolean, default: false

# will only restore CV's that had attributes associated
attributes = SampleAttribute.where(allow_cv_free_text: true).includes(:sample_controlled_vocab)
attributes = SampleAttribute.where(allow_cv_free_text: true)
attributes.each do |attr|
attr.sample_controlled_vocab&.update_column(:custom_input, :true)
end

attributes = ExtendedMetadataAttribute.where(allow_cv_free_text: true)
attributes.each do |attr|
attr.sample_controlled_vocab&.update_column(:custom_input, :true)
end

attributes = TemplateAttribute.where(allow_cv_free_text: true)
attributes.each do |attr|
attr.sample_controlled_vocab&.update_column(:custom_input, :true)
end
Expand Down
2 changes: 2 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,7 @@
t.text "description"
t.string "label"
t.integer "linked_extended_metadata_type_id"
t.boolean "allow_cv_free_text", default: false
t.index ["extended_metadata_type_id"], name: "index_extended_metadata_attributes_on_extended_metadata_type_id"
t.index ["sample_attribute_type_id"], name: "index_extended_metadata_attributes_on_sample_attribute_type_id"
t.index ["sample_controlled_vocab_id"], name: "index_extended_metadata_attributes_on_sample_cv_id"
Expand Down Expand Up @@ -2095,6 +2096,7 @@
t.boolean "is_title", default: false
t.integer "isa_tag_id"
t.string "pid"
t.boolean "allow_cv_free_text", default: false
t.index ["template_id", "title"], name: "index_template_id_asset_id_title"
end

Expand Down

0 comments on commit 1072900

Please sign in to comment.