I have a sqlite3 database with 3 tables which has id
column as primary key, but has no created_at
or update_at
columns.
I want to use it in a Rails3 Applications. How can I properly convert it into a 'Rails database'?
I have a sqlite3 database with 3 tables which has id
column as primary key, but has no created_at
or update_at
columns.
I want to use it in a Rails3 Applications. How can I properly convert it into a 'Rails database'?
It sounds like you want a single rails app to access two different databases? You will probably need to do two things:
For the first item, you can follow this: Connecting Rails 3.1 with Multiple Databases
For the second item, if the tables don't follow the Railsy way of naming them, you can could create a model that looks something like this:
# app/models/foo.rb
class Foo < ActiveRecord::Base
establish_connection "your_sqlite_connection_name_#{Rails.env}"
self.table_name = "name_of_table_in_sqlite_db"
end
Write a migration to add those two fields the table(s) in question.
For instance,
Command line something like script/generate migration add_timestamps_to_user
Then edit the migration and put the two fields in there.
e.g.
def change
add_column :users, :created_at, :date
add_column :users, :updated_at, :date
end
Also, make sure that foreign keys are in the format othertablename_id and if not, consider renaming them with a rename_column
migration.