Showing posts with label Migration. Show all posts
Showing posts with label Migration. Show all posts

Sunday, August 23, 2009

Migration : Migrating an Application from Rails 1.2.5 to Rails 2.3.3

Since Nov 2007, I had a Rails 1.2 e-CRM application running on Windows Server 2003 and powered by Apache 2 and a pack of Mongrels web servers.

A couple of weeks ago, I discovered Ubuntu 9.04 and decided to migrate the e-CRM to Rails 2.3.3 running on Ubuntu 9.04.

What have I achieved thus far ?

1. Installing Rails 2.3.3 on Ubuntu 9.04
2. Installing Mongrel, Capistrano, Passenger and Apache on Ubuntu 9.04.
3. Installing Aptana Radrails on Ubuntu 9.04
4. Since Aptana Radrails was slow, I then installed Eclipse Ganymade (3.4.2) and managed to install the latest Aptana Radrails .1.30 as a plugin to Eclipse

When I attempted to run e-CRM on Rails 1.2, I ran into a number of incompatibilities including the need to update the following Rails Plugins

1. active_scaffold
2. active_scaffold_export
3. active_scaffold_tools (still unable to get a version compatible with Rails 2.3.3)
4. role_requirement
5. use restful_authentication instead of acts_as_authenticated
6. record_select
7. acts_as_audited

Then after wasting a couple of days, I discovered that Ubunti 9.04 being a Linux distro is case-sensitive and I had to pay attention to renaming the images files in the public\images folder.

Also, I used this script (command line) to auto-convert my rhtml files to html.erb as recommended for Rails 2.x

for f in $(find . -name '*.rhtml') ; do c=$(dirname $f)/$(basename $f .rhtml).html.erb ; mv $f $c ; done

Why the need to change rhtml to html.erb ?

Apparently in Rails 2.x, it’s been revealed that the .rhtml and .rxml file extensions will be deprecated in favor of .erb and .builder, respectively.
Why such a change – well, .rhtml files are not strictly html files. They are generic embedded ruby files that can be used for email templates, csv files, vcards etc… .erb is just a more generic, accurate extension for the file type. The same goes for .rxml – it can be used for more than just xml files. Think of all the rss feeds you’ve written with rxml files. Now you can stop being tied down by the limited .rxml file extension and can start using .builder.
FYI, the ‘old’ extensions won’t be fully deprecated until Rails 3.0.


BTW, this site was also useful reference in my quest to upgrade from Rails 1.2 to 2.3.3

Some additional plugins needed by active_scaffold include

a) in_place_editing - git://github.com/rails/in_place_editing.git
b) render_component


More to come...

Saturday, October 13, 2007

Migration : Upgrading Rails from 1.2.3 to 1.2.5

Being adventurous having my first Rails appplication in production since August 2007, I read about the impending Rails 2.0 release. As I understand it, there was to be a 1.2.4 release and it was supposed to be mostly made up of security fixes and deprecation notices that will help you prepare for Rails 2.0.

Being cautious, I froze Rails 1.2.3 into the Vendor Directory using rake:freeze:gems.

Then I gem install rails --include-dependencies

Surprise...Surprise, the update is to Rails 1.2.5 !

D:\Aptana_Workspace\crm4web>gem install rails --include-dependencies
Need to update 22 gems from http://gems.rubyforge.org
......................
complete
Successfully installed rails-1.2.5
Successfully installed activesupport-1.4.4
Successfully installed activerecord-1.15.5
Successfully installed actionpack-1.13.5
Successfully installed actionmailer-1.3.5
Successfully installed actionwebservice-1.2.5
Installing ri documentation for activesupport-1.4.4...
Installing ri documentation for activerecord-1.15.5...
Installing ri documentation for actionpack-1.13.5...
Installing ri documentation for actionmailer-1.3.5...
Installing ri documentation for actionwebservice-1.2.5...
Installing RDoc documentation for activesupport-1.4.4...
Installing RDoc documentation for activerecord-1.15.5...
Installing RDoc documentation for actionpack-1.13.5...
Installing RDoc documentation for actionmailer-1.3.5...
Installing RDoc documentation for actionwebservice-1.2.5...

Result :
Tested on a blank project (Radrails+Windows 2003 server) created using Rails 1.2.3
Can display the Std index.htm but on clicking the "About Your Application's Environment", the following error message was shown

"Routing Error, no route found to match /rails/info/properties with (:method :Get)

I then created a new project under Rails 1.25 and on clicking the "About Your Application's Environment"

About your application’s environment
Ruby version 1.8.6 (i386-mswin32)
RubyGems version 0.9.2
Rails version 1.2.5
Active Record version 1.15.5
Action Pack version 1.13.5
Action Web Service version 1.2.5
Action Mailer version 1.3.5
Active Support version 1.4.4
Application root D:/Aptana_Workspace/test-125
Environment development
Database adapter mysql

Worried about the impact on my Production Apps, I committed to SVN, unfroze and ran the app under Rails 1.2.5 and voila no problems :-)

BTW, I was just just informed of this link :-
http://weblog.rubyonrails.org/2007/10/12/rails-1-2-5-maintenance-release

which recommends as follows :-

To upgrade, `
gem install rails`,
set RAILS_GEM_VERSION to ‘1.2.5’ in config/environment.rb, and
`rake rails:update:configs`.

Updated on 18th October 2007

An example of a deprecation woud be
record_type => record.type.name

which will genenerate a
warning: Object#type is deprecated; use Object#class

Solution : record_type => record.class.name

Thursday, October 11, 2007

Advanced Rails : Moving an Existing Database to a Rails Application

Assuming that you have an existing application that you wish to rewrite in Rails, how would you prepare your database schema so that you can take advantage of the magick of db:migrate ?

Well, I had to do exactly that when I decided to rewrite an existing 200+tables CRM solution into e-CRM, a Rails application. This is what I did :-

a) Pluralize all the table names

Tip: One legacy table was named customer. To pluralize it to customers whilst retaing the data, I use CREATE TABLE customers SELECT * FROM customer for MySQL

b) Add an id field (auto-increment, integer) to every table

c) Add created_at, updated_at in every table to take advantage of Rails automatic updating of these fields without a single line of code

d) Added another magic column ie lock_version (must default to 0) to invoke optimistic locking

e) To support a belongs_to relationship, add belongs_to_tablename

f) Create a schema_info table with just 1 field ie Version, Integer and add a single record with the value=1

g) Use Rake db:schema:dump to create a schema.rb based on the underlying database schema . See following snapshot of Radrails in action
h) Create an empty migration file say 001_migrate2mysql and copy the contents to the Self.Up Method as shown in the Radrails snapshot as follows :-

That's it !
Updated on 4th November, 2007.

Welcome to Rails.. Rails... Rails !

In 1995, I started the popular Clipper...Clipper... Clipper website (no blogs then) which was very popular and linked by virtually every Clipper-related site. When I switched to Windows via Delphi in 1997, I started the Delphi... Delphi... Delphi site. In June 2007, I discovered Ruby on Rails and no prize for guessing what I am gonna name this blog. which I started on 2nd October 2007.

As at 10th June 2010, we have 13,364 unique visitors from more than 84 countries such as Angola, Andorra, Argentina, Australia, Austria, Algeria,Barbados, Bosnia and Herzogovina, Belgium, Brazil, Bulgaria, Bangladesh, Belarus, Bolivia, Chile, Cambodia, Cape Vede, Canada, China, Colombia, Costa Rica, Croatia, Cyprus, Czech Republic, Denmark, Egypt, Estonia, Finland, France, Guadeloupe, Guatemala, Germany, Greece, Hong Kong, Hungary, India, Indonesia, Ireland, Israel, Italy, Japan, Kenya, Korea, Lithuania, Latvia, Malaysia, Mexico, Macao, Netherlands, Nepal, Norway, New Zealand, Oman, Panama, Peru, Poland, Portugal,Paraguay , Philippines, Romania, Russian Federation, Saudi Arabia, Singapore, Spain, Slovakia, Slovenia, Serbia, South Korea, Slovenia, South Africa, Spain, Switzerland, Sri Lanka, Sweden, Taiwan, Thailand, Turkey, United Arab Emirates, Ukraine, USA, UK, Venezuela, Vietnam

CCH
10th June 2010, 19:42