Skip to content

Commit

Permalink
Fix the add menu_type migration
Browse files Browse the repository at this point in the history
This migration fails being rolled back because change_column is not reversible. Using `change_column_null` resolves that issue. Also it does not make sense to write into a column we delete any way.
  • Loading branch information
tvdeyen committed Jun 4, 2020
1 parent 9f18b95 commit daa78e3
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions db/migrate/20200511113603_add_menu_type_to_alchemy_nodes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ def self.root_for(node)
end
end

def change
def up
add_column :alchemy_nodes, :menu_type, :string
LocalNode.all.each do |node|
root = LocalNode.root_for(node)
menu_type = root.name.parameterize.underscore
node.update(menu_type: menu_type)
end
change_column :alchemy_nodes, :menu_type, :string, null: false
change_column_null :alchemy_nodes, :menu_type, false
end

def down
remove_column :alchemy_nodes, :menu_type
end
end

0 comments on commit daa78e3

Please sign in to comment.