It should actually just look like this:

class AddEnvironmentToHosts < ActiveRecord::Migration
   def self.up
     add_column :hosts, :environment, :string
   end

   def self.down
     remove_column :hosts, :environment
   end
end

The conditional code was for doing a bulk update on all the tables.

-Blake

On Jul 7, 2008, at 3:52 AM, Frank Sweetser wrote:

>
> I haven't done much with rails migrations, but shouldn't the  
> "unless" in
> self.down be an "if"?
>
> Thom May wrote:
>> ---
>> .../rails/database/002_add_environment_to_host.rb  |   13 ++++++++++ 
>> +++
>> 1 files changed, 13 insertions(+), 0 deletions(-)
>> create mode 100644 lib/puppet/rails/database/ 
>> 002_add_environment_to_host.rb
>>
>> diff --git a/lib/puppet/rails/database/ 
>> 002_add_environment_to_host.rb b/lib/puppet/rails/database/ 
>> 002_add_environment_to_host.rb
>> new file mode 100644
>> index 0000000..712265a
>> --- /dev/null
>> +++ b/lib/puppet/rails/database/002_add_environment_to_host.rb
>> @@ -0,0 +1,13 @@
>> +class AddEnvironmentToHost < ActiveRecord::Migration
>> +    def self.up
>> +        unless  
>> ActiveRecord::Base.connection.columns("hosts").collect {|c|  
>> c.name}.include?("created_at")
>> +            add_column :hosts, :environment, :string
>> +        end
>> +    end
>> +
>> +    def self.down
>> +        unless  
>> ActiveRecord::Base.connection.columns("hosts").collect {|c|  
>> c.name}.include?("created_at")
>> +            remove_column :hosts, :environment
>> +        end
>> +    end
>> +end
>
>
> -- 
> Frank Sweetser fs at wpi.edu  |  For every problem, there is a  
> solution that
> WPI Senior Network Engineer   |  is simple, elegant, and wrong. - HL  
> Mencken
>    GPG fingerprint = 6174 1257 129E 0D21 D8D4  E8A3 8E39 29E3 E2E8  
> 8CEC
>
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to