Database design help

Hi, I’m coding a little application to make couples profile. The
problem is I just don’t know how to create my databases so that their
are no bottlenecks and that I can have a relation. The way I see it is
that their would be a user database and a profile database and they
would link 2 to 1. Is this the right way? In the user db I would store
their userid and some session info, should I use their userid as
primary key?

DB Scheme
User1—
|—Profile
User2—

User DB
-userid (primary key?)
-profileid
-session info
-timestamp

Profile DB
-personnal info

Any help would be appreciated,
thanks’ in advance.

Rails’ convention is that every ActiveRecord object is identified by
an ‘id’ column (auto-incrementing, int primary key) and foreign keys
are named <other_table>_id. The nice thing about following the
conventions is that it greatly simplifies your coding (in some cases
eliminating code!). So your model would look something like this:

create_table :users do |t|
t.integer :profile_id
t.string :crypted_password
… etc …
end

class User < ActiveRecord::Base
belongs_to :profile
end

create_table :profiles do |t|
… personal info …
end

class Profile < ActiveRecord::Base
has_many :users
end

With those migrations and classes you do not need to specify the name
of the primary key (assumed to be id… and written into the
create_table migration for you). You also don’t need to tell the
has_many macro the name of the foreign key to use when looking up
users (or the User objects which Profile to file) since it’s assumed
to be profile_id.