Skip to content
Snippets Groups Projects
Select Git revision
  • ac21a02135f1efb67b17c836d1543e4e56c1acb5
  • master default
  • uiUpdates
  • 1.0.0
4 results

20170109140000_add_resource_fields.rb

Blame
  • 20170109140000_add_resource_fields.rb 1.54 KiB
    require 'active_record'
    require 'models/resource'
    require 'models/resource_class'
    require 'models/resource_field'
    require 'models/resource_field_data'
    
    class AddResourceFields < ActiveRecord::Migration
      def up
        # add a table to hold the various "classes" of resources
        create_table :resource_classes do |t|
          t.string :name
        end
    
        # add a table to hold the various types of fields that get attached to resources
        create_table :resource_fields do |t|
          t.string :field_name
          t.integer :resource_class_id
        end
    
        # add a table to contain the actual data
        create_table :resource_field_data do |t|
          t.integer :resource_id
          t.integer :resource_field_id
          t.string :data
        end
    
        # add a column to the resource table to reference its class if it exists
        add_column :resources, :resource_class_id, :integer
    
        # we seem to have a random column with no use
        remove_column :resources, :resource_type
    
        # add a column to reservations for just extraneous details
        add_column :reservations, :details, :text
    
        # move all model data, for NIS resources, into this new arch.
        # create a class
        ResourceClass.reset_column_information
        ResourceField.reset_column_information
        ResourceFieldData.reset_column_information
        tool_class = ResourceClass.create(
          :name => 'Innovation Studio Tool'
        )
    
        # add model as a field to this class
        model_field = tool_class.resource_fields.create(
          :field_name => 'Model'
        )
    
        # lastly, drop the column
        remove_column :resources, :model
      end
    end