In this video, we’ll create the Sessions Schema step-by-step for our Job Portal App. Before I show the final code, I’ll challenge you to think and try building it yourself — this will help you truly understand how sessions work in databases. We’ll discuss what each field represents, how to define datatypes and methods, and why this schema is important for managing user sessions.
👉 Comment your schema version below and let’s see how close you get! ------------------------------------------------------------------------ 🚀 Boost Your Skills with these Pre-Requisite Videos:
⌛TIMELINE⏳ 0:00 — Intro to Sessions Schema in Job Portal App (drizzle orm mysql schema) 0:12 — How Session Table Looks Like (database structure visualization) 1:45 — Creating Session Schema Step-by-Step (drizzle orm example) 2:35 — Pause the Video and Try Yourself (hands-on coding challenge) 3:05 — Think Before You Code (practice challenge for schema design) 3:55 — Writing Session Schema with Field Names Only (schema skeleton) 5:15 — Add Datatypes and Methods in Session Fields (drizzle orm types) 6:15 — Complete Session Schema with All Methods (final version explained) 11:30 — If You Have Doubt, Comment Below (community interaction)
Welcome to NETJS Full Stack Project Job Portal Application
Today is Day 12 and we are going to see Session Schema Table
Let me tell you what it is
If you remember, we have already created the schema of the user
This schema takes the form of the table
If I show you how it looks in the table of the user
You will see something like this
We have ID, Name, Username
This is the same table that Drizzle is providing
You get the same table in Workbench in MySQL
You can check it out there
You can also check out the terminal like CLI
But Studio makes it easy
We have already seen the schema of the user
We have seen the syntax, data types, what happens, what doesn't happen
We have seen everything in that video
I have already updated the playlist
If you haven't checked it out yet
Please check it out
I would like to tell you again
For your benefit, we had said in the starting two videos
We will do the code later
But first we will understand
What we are going to get in the database
What are the data types
In the same way, I had told you that we will create the schema of the user
If I show you
Here we have the user schema over here
I have explained it in the episode 10
Then we saw what is Sessions
I have cleared your doubts in the theory
Today we will see
Once we know what Session actually is
Why don't we create a table
Now we will increase our speed
But we have to strengthen the foundation of the starting
First of all, if I tell you
I had told you in yesterday's video
What we are going to get
Let me zoom in
What we are going to get
When we talk about Sessions table
Sessions is very useful in authentication
If the user has already logged in
And if he has already logged in
Then the expiry date
Is it inside or outside the time frame
We need all those things here
Let's create Sessions
In this way
Obviously
What we will write here
MySQL table
Syntax is same
There is no difference in syntax
You just have to write the name of the fields
The fields inside the Sessions
You just have to write that
In those fields
Which data type should be there
Default, Timestamp
What is there
You have to mention there
We have already seen the users
I would like you to pause the video
Give some time
Think a little
What can happen in Sessions table
Think a little
Then see it again
If you think
I don't even remember the names of the fields
What should I think
I will do one thing
If you want
Pause the video and think
What can happen in Sessions table
I had cleared it in yesterday's video
If you still don't understand
That's not a problem
I am writing the names of the fields
You have to think
What is the data type of that field
Int, String, Boolean
Date and time
Not only data type
Do we have to default it
Do we have to pass null
Is it our primary key
Is it unique
There are many things
You have to think
If you think
If you write
Believe me
I don't want you to look at me
Give your input
See where I am standing
I mean
What you are seeing
First of all
The name of the table
Which will be visible on the database
That's your session
Now I am going to create
Session
I will get the id, name, username
Sorry, it's not
Session is here
I will get the id, username
I want you to work with me
I will give the comma id
Here we need
User id
To know which user
Session we are talking about
Then guys, what we need
We need a user agent
User agent is your server
It means
This is my device
It will have an address
You will get the details of my device
My browser
I have chrome on my computer
I have this gmail id
We know which system we are talking about
That's what user agent does
Not only system
The internet protocol
We check that
We have something called ip
We check your ip
Then the most important
Expires
Expires at
Perfect
It's very easy
Created and then updated
I have copied and pasted
I am giving you a chance
If you think it's not enough
Set a timer for 5 minutes
Think
What can be our id
This is my user id
What can be that
User agent
Research
Try
Please try
I request
I think you have tried
I will tell you one by one
If we talk about id
Our session id
Is not a numeric id
Multiple characters can be there
Different
Varchar is a safe option
You will know
When we generate
Numbers and alphabets can be there
And
We will write id
This id is
Through which
I will get session id
While coding
I will use this id
This is the id
Which will be stored in my database
You can see the difference
It's a deleted ad
If we see
It will be deleted
And saved
It's important to know
The difference
Once you give id
You can tell
The length
You can tell
I have told you about varchar
Even though you said 255
But your id is
12 characters
It will take only 12
Once it's done
It's important
To have a primary key
We made it like this
Sometimes we say no
But it's better
Now
My user id
No doubt it should be int only
Because user id will be in 123
And here
I will write user id
It should not be null
Now
It's important
If you are creating more than 2 tables
You can see
There is a field
Which I am using in other table
It means
In my users table
I am using the same id
I am using the same id in my sessions table
Where there is no primary key
It means
In my users table
There is a relation
Because of which
We are sharing the field
When you are working in sql
It's all about your relationship
All about your tables
You have to tell
The difference between
User id and primary key
What is the relation
You have to tell
Yes
I have referenced my user id
It's not my table
It's of another table
It's called users
And it has a field
It means
I am taking the reference of my id
And I am storing it here
That's all
There is one more thing
Yes
In case
This user deleted his account
But still
That session will be on my cookies
We want that
This id
If the user
Deletes his account
This session will be deleted
I don't have to manually delete
For that reason
We have a property called cascade
If we see the spelling
It should be on delete
And then value
Cascade
This line
On delete
And
If I show you
Our table
User id
It's a one to many relationship
We have already seen it
It's easy for us
If we didn't understand
If we didn't think
Now it's a user agent
It's a user agent
It's a browser
We keep it in text
We use snake case
It's this part
It shouldn't be null
IP address
IP before or IP basic
We do it here
Where is it
There is no data
What else
Length
We give length
Maximum
255
No issue
Not null
Expires at
It's very important
After how many days
After how many hours
We are dealing with time
Right
Whenever we talk about time
No need to write date or time
Go with timestamp
If it's automatic
Update or delete
It updates the value
Go here
In database
Not pascal, snake case
Expires at
Not
And then null
This is it
Our work is done
This is your session table
Which we have created
When we
It's coding
When we code
When we get data
When we store in database
I will tell you
These values
Where will I get this value
What will be the value of this IP
Where will I get it
How to reference user id
I know it's one to many
How to put value here
How do I know which session is of which user
How do I know
This id is not for kids
This id is very important
How do I generate session id
There are many things
Which will come here
Which we will see later
That's it for today
I hope you liked the video
I know video was short
But it was very important
Because playing with your brain
What can happen
That's it for today
I hope you liked the video
If you didn't check out previous video
Do it
If you have any doubt
Do comment
We are going step by step
It's taking time
But we are going in depth
If you liked the video
Do like and share
Our next target is 8 lakh subscribers
Please do it
See you in next video
Thank you so much