1. Select your Project
2. Edit config\database.yml
development:
database: SourceDatabaseName
3. Delete schema.db
4. Right-click and select Rake\db\schema\load which basically the same as typing into the Rails Shell
5. Edit config\database.yml
development:
database: ProjectDatabaseName
Nb. Assume that you had already create an empty database for your project
6. rake db:schema:load
That's it, when you check your project database, it is already populated with the Source Schema.
Chee Chong Hwa aka CCH, a Malaysian Chief Software Architect blogs on his experiences with Ruby on Rail running on Win2003 Server+Apache 2.26 environment since 2007. Flirted briefly with Ubuntu 9.04 in 2009. Since January 2017, now using RubyMine IDE/Notepad++ to work with Ruby 2.26 +Rails 5.01+Apache 2.4.23 + MySQL 5.7.14 on Windows 10 64-bits.
Showing posts with label Database. Show all posts
Showing posts with label Database. Show all posts
Wednesday, August 19, 2009
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 :-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
Updated on 4th November, 2007.
Wednesday, October 3, 2007
Using Interbase 2007 in Ruby on Rails Project
Joe McGlyn, Director of Product Management at CodeGear has shown the way to use Interbase 2007 in Ruby on Rails as follows :-
Assuming you already have a project, here are the basic steps to modifying a project to work with InterBase as the database...
1. Get the InterBase gem
gem install ibruby
Comments by CCH :
There are a few ways to do this
a) c:\instantrails\ruby\bin >gem install ibruby
b) In Aptana RadRails,
i) call up the Gems Manager from
Windows\show view\Ruby Gems
ii) Within the Gems Manager
- Click Install
- select ibruby Gem
You can then see the progress within the Console Tab
c) In 3rdRail, you can use the Project Commander
2. Get the Rails adapter (from the root dir of your rails app or from the project commander) script/plugin source http://ibruby.rubyforge.org/svn/rails_plugins/trunk/
script/plugin install ibrails_plugin
Comments by CCH
a) Shell to Command prompt and cd to root of your project folder
c:\project_name>ruby script/plugin source http://ibruby.rubyforge.org/svn/rails_plugins/trunk/
c:\project_name>ruby script/plugin install ibrails_plugin
b) Using Aptana Radrals,
i) select the Rails Plugins Tab
ii) select ibruby and click Go
Nb. If ibruby does not show in the list, revert to method (a) :-)
c) In 3rdRail, you can use the Project Commander
NOTE :
You will also need to add these two lines into your Rails
environment.rb file:
# ------ force InterBase support to be added to Rails
# ------ as Rails currently has no way of extending its db
# ------ support apart from a new Rails release!
require 'active_record'
require 'vendor/plugins/ibrails_plugin/lib/ibrails_plugin'
# ------
Ideally these two lines should appear after the line loading
boot.rb which typically looks like this:
require File.join(File.dirname(__FILE__), 'boot')
and before anything else gets done (particularly any
initialization)
3. Assuming you have IB installed, and have the default IB user/pwd enabled you're good to go.
It will even create the database file (within your project directory by default)
Known limitation:Indicies are limited to ~200 characters, depending on how they are composed. This is InterBase, not the integration.
Comments by CCH
Despite religously following the instructions from Joe McGlyn of CodeGear, I have not been able to overcome the barrier and error message
ie "database configuration specifies nonexistent interbase adapter"
You may want to read the thread "Using Interbase with RoR" started by Joe here borland.public.3rdrail.ide
Assuming you already have a project, here are the basic steps to modifying a project to work with InterBase as the database...
1. Get the InterBase gem
gem install ibruby
Comments by CCH :
There are a few ways to do this
a) c:\instantrails\ruby\bin >gem install ibruby
b) In Aptana RadRails,
i) call up the Gems Manager from
Windows\show view\Ruby Gems
ii) Within the Gems Manager
- Click Install
- select ibruby Gem
You can then see the progress within the Console Tab
c) In 3rdRail, you can use the Project Commander
2. Get the Rails adapter (from the root dir of your rails app or from the project commander) script/plugin source http://ibruby.rubyforge.org/svn/rails_plugins/trunk/
script/plugin install ibrails_plugin
Comments by CCH
a) Shell to Command prompt and cd to root of your project folder
c:\project_name>ruby script/plugin source http://ibruby.rubyforge.org/svn/rails_plugins/trunk/
c:\project_name>ruby script/plugin install ibrails_plugin
b) Using Aptana Radrals,
i) select the Rails Plugins Tab
ii) select ibruby and click Go
Nb. If ibruby does not show in the list, revert to method (a) :-)
c) In 3rdRail, you can use the Project Commander
NOTE :
You will also need to add these two lines into your Rails
environment.rb file:
# ------ force InterBase support to be added to Rails
# ------ as Rails currently has no way of extending its db
# ------ support apart from a new Rails release!
require 'active_record'
require 'vendor/plugins/ibrails_plugin/lib/ibrails_plugin'
# ------
Ideally these two lines should appear after the line loading
boot.rb which typically looks like this:
require File.join(File.dirname(__FILE__), 'boot')
and before anything else gets done (particularly any
initialization)
3. Assuming you have IB installed, and have the default IB user/pwd enabled you're good to go.
It will even create the database file (within your project directory by default)
Known limitation:Indicies are limited to ~200 characters, depending on how they are composed. This is InterBase, not the integration.
Comments by CCH
Despite religously following the instructions from Joe McGlyn of CodeGear, I have not been able to overcome the barrier and error message
ie "database configuration specifies nonexistent interbase adapter"
You may want to read the thread "Using Interbase with RoR" started by Joe here borland.public.3rdrail.ide
Subscribe to:
Posts (Atom)
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
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