Sha256: b07196fba2e8a1611443bbf385b5b8a571ea1a0cb27f7893e67dcd1737ab34a6
Contents?: true
Size: 1.13 KB
Versions: 6
Compression:
Stored size: 1.13 KB
Contents
class ChangeModuleContextToTool < ActiveRecord::Migration def up add_column :bit_player_content_modules, :bit_player_tool_id, :integer BitPlayer::ContentModule.reset_column_information BitPlayer::ContentModule.all.each do |content_module| tool = BitPlayer::Tool.find_or_create_by_title(content_module.context) content_module.update!(bit_player_tool_id: tool.id) end change_column_null :bit_player_content_modules, :bit_player_tool_id, false remove_column :bit_player_content_modules, :context execute <<-SQL ALTER TABLE bit_player_content_modules ADD CONSTRAINT fk_content_modules_tools FOREIGN KEY (bit_player_tool_id) REFERENCES bit_player_tools(id) SQL end def down execute <<-SQL ALTER TABLE bit_player_content_modules DROP CONSTRAINT fk_content_modules_tools SQL add_column :bit_player_content_modules, :context, :string, null: false BitPlayer::ContentModule.all.each do |content_module| content_module.update(context: content_module.tool.title) end remove_column :bit_player_content_modules, :bit_player_tool_id end end
Version data entries
6 entries across 6 versions & 1 rubygems