Files
openfoodnetwork/db/migrate/20120327000652_migrate_tokenized_permissions.rb
Andrew Spinks cd1938a74e spree install.
2012-03-27 11:06:49 +11:00

25 lines
761 B
Ruby

class MigrateTokenizedPermissions < ActiveRecord::Migration
def concat(str1, str2)
dbtype = Rails.configuration.database_configuration[Rails.env]['adapter'].to_sym
case dbtype
when :mysql, :mysql2
"CONCAT(#{str1}, #{str2})"
when :sqlserver
"(#{str1} + #{str2})"
else
"(#{str1} || #{str2})"
end
end
def up
execute "UPDATE spree_tokenized_permissions SET permissable_type = #{concat("'Spree::'", "permissable_type")}" +
" WHERE permissable_type NOT LIKE 'Spree::%' AND permissable_type IS NOT NULL"
end
def down
execute "UPDATE spree_tokenized_permissions SET permissable_type = REPLACE(permissable_type, 'Spree::', '')" +
" WHERE permissable_type LIKE 'Spree::%'"
end
end