I'm trying to design a database for supporting a multi-step registration flow. The registration flow goes like this: the user logs in via OAuth (which creates a session and user), then they're asked to complete the registration by providing a name and username. What is the best way to capture this in the database?
Should I just make a single user table with nullable name
and username
columns?:
CREATE TABLE users ( id UUID PRIMARY KEY, name TEXT, username TEXT ); CREATE TABLE sessions ( id TEXT PRIMARY KEY, user_id UUID NOT NULL REFERENCES users (id), expires_at TIMESTAMPTZ NOT NULL );
Or should I separate the profile information into a separate table like this:
CREATE TABLE users ( id UUID PRIMARY KEY, profile_id UUID ); CREATE TABLE profiles ( id UUID PRIMARY KEY, name TEXT NOT NULL, username TEXT NOT NULL ); ALTER TABLE users ADD FOREIGN KEY (profile_id) REFERENCES profiles (id); CREATE TABLE sessions ( id TEXT PRIMARY KEY, user_id UUID NOT NULL REFERENCES users (id), expires_at TIMESTAMPTZ NOT NULL );
I feel that one advantage here is that I can simply check if the profile_id
column is null or not to determine if the user has completed the registration process. But I'm not sure if this a good idea.
Any opinions of this? What's the conventional way of going about this?