blob: ac8ecb9b68cb0fe6929b94590ad607c01a7e6635 (
plain)
| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 | class InsertDefaultOrganisation < ActiveRecord::Migration
  class Organisation  < ApplicationModel
    attr_accessor :name
  end
  def up
    organisation = Organisation.find_or_create_by!(:name => "Chouette")
    Referential.where(  :organisation_id => nil).each do |r|
      r.update_attributes :organisation_id => organisation.id
    end
    User.where(  :organisation_id => nil).each do |r|
      r.update_attributes :organisation_id => organisation.id
    end
  end
  def down
    organisations = Organisation.where( :name => "Chouette")
    organisations.first.destroy unless organisations.empty?
  end
end
 |