Here is example of migration from my RoR application. It is intranet
application that is deployed in many locations (many clients)  so
needs to be repeated at every server.

class WatchdogTimerField < ActiveRecord::Migration
  def self.up
    #add columns to various tables
    add_column :alarm_descriptors, :watchdog_timer, :integer, :default
=> 0, :null => false
 
add_column :alarm_descriptors, :watchdog_timer_unit, :integer, :default
=> 1, :null => false
    add_column :rtu_descriptors, :watchdog_time, :integer, :default =>
0, :null => false
    #update data in added column:
    RtuDescriptor.reset_column_information
    for rtu in RtuDescriptor.find(:all)
      rtu.update_attribute('watchdog_time', Time.now().to_i)
    end
  end

  def self.down
    remove_column :alarm_descriptors, :watchdog_timer
    remove_column :alarm_descriptors, :watchdog_timer_unit
    remove_column :rtu_descriptors, :watchdog_time
  end
end

#######################

another example, more complicated - includes logic to update data in
existing database, fixing possible errors:

class AddRelationsToClient < ActiveRecord::Migration
  def self.up
    klient = Client.find(:first)
    klient ||= Client.create(   :name => 'blah blah',
                                :activation_date => Time.now(),
                                :unit_cost => 0.0,
                                :html_title => '<img src=/images/
logo.gif width=134 height=132 border=0><p>Welcome to ...!</p>',
                                :sms_limit => 0)
    add_column :rtu_groups, :client_id, :integer, :default => 0, :null
=> false
    add_column :user_groups, :client_id, :integer, :default =>
0, :null => false
    remove_column :users, :link
    remove_column :user_groups, :credit
    RtuGroup.update_all :client_id => klient.id
    UserGroup.update_all :client_id => klient.id
  end

  def self.down
    remove_column :rtu_groups, :client_id
    remove_column :user_groups, :client_id
  end
end


On Jul 8, 9:25 am, mdipierro <mdipie...@cs.depaul.edu> wrote:
> 1. I agree that RoR migrations are more powerful but web2py can update
> the data too. Can you provide an example of something you can do in
> RoR migrations that you believe cannot be done in web2py?
>
> 2. That is a major philosophical difference. Most people including me
> believe that a proper mapping between database tables and object in a
> programming language is not possible. Any attempt to do it necessarily
> imposes limitations on what you do or forces you to introduce an
> unnatural syntax. That is way they have an ORM and we have a DAL. In
> practice this is syntactical difference more than a functional one.
> They say
>
>   record.is_logged()
>
> we say
>
>   is_logged(record)
>
> The rails syntax can easily be implemented on top of web2py and I do
> not completely exclude it will be supported in the new DAL (without
> going to a full ORM).
>
> Massimo
>
> On Jul 8, 12:03 am, SergeyPo <ser...@zarealye.com> wrote:
>
>
>
> > I like web2py and prefer it over RoR but two things I am missing:
> > 1. migrations (RoR migrations are really more powerful, you write the
> > script that not only changes database scheme but also can update data,
> > you have full control etc.)
> > 2. models (web2py model layer is purely database layer which you use
> > by ORM, in RoR models are classes that run on top of ORM and let you
> > program custom methods; e.g. for class 'Users' you can develop methods
> > 'is_logged', 'is_admin', 'dont_destroy_admin' etc etc.)
>
> > Many-to-many relations that are supported by many frameworks are
> > actually a drawback and Rails have already changed original concept to
> > 'belongs ... through' which is actually a manual table definition for
> > many-to-many relations; so in web2py you just define  a table with all
> > necessary fields for your particular situation.
>
> > And the biggest advantage of web2py is Python language. It's by far
> > more mature than Ruby and have so many libraries available that you
> > hardly have to develop any system level task,  you just script the
> > behavior you need in terms of domain area of your application. I mean,
> > if you want to use statistics you use scipy, you need pdf - reportlab,
> > networking - no problem, AI - no problem. Web2py makes it easy to
> > install libraries and distribute/deploy with your apps.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to