Welcome back.
I am so excited for this section because we're finally combining everything we know into one place by
the end of this, we have a unified understanding of how everything works and the world of web development.
We have our front end smart brain here with the sign in page.
And we have our app, Balton React.
We also have our server running on three thousand, listening to requests, but now we don't need this
database anymore.
We can create our own PostgreSQL database now.
And have the server interacting with it through school.
Updating everything and then responding to express back to the front end.
It's going to be so much fun.
I'm so excited, but before we actually start to coat anything, we have to design our database.
Let's create.
A database.
And we'll call it smart brain.
All right, perfect.
Now that we have our database created, I want you to think of these three separate things as their
own individual computers that when we deploy is going to be different parts.
We have our server living on a computer, we have our database leaving on a computer, and we can actually.
Connected to it.
And we also have our app in a separate computer as well.
So let's close this quickly and connect to our database, to our local host, and we called it Smart
Brain.
And there you go, but no tables yet to get started, as we did when we created our API design for our
server.
We really want to think about how our database would look.
And we're using relational database here because in my opinion and in moving forward, relational databases
are really, really good.
Although databases like Mongo DB are really easy to get started with and they're dynamic, you don't
have to think too much about when you're starting off.
I think relational databases offer a really strong way to think about how your app should be structured
and how everything and all the pieces come together.
It's a really, really powerful tool that I see the industry shifting back to more and more.
Whether you use PostgreSQL or Maisky well, or sequel light, all these databases are pretty much the
same.
They're super powerful and we're going to do the exact same thing with our app because we're not necessarily
storing information like LinkedIn or Facebook, where everything is a document model.
We have users that are interacting with each other.
But within our app, we can have different things.
We can have login information.
If we expand our app, we can have maybe information about the type of images that they've submitted.
Now, looking at what we've built, there's definitely a few things that we want to create.
If we go back to our database example here, we have our user stable, which we're going to have to
create.
But remember what I said about passwords in the way we store passwords.
We don't necessarily want to create a user object or a user table.
With all these columns, we want to separate things out and connect them through four keys.
So we're going to create a user stable and then a log in table.
And have those cables connected through perhaps the email field.
Let's go back to our gooey and create these tables now going to open up the KORIE.
Let's remove this from now our old query and let's create our users table.
As you remember, it's create table users.
I have brackets around here just so it's clean.
And within here, I'll say it is going to be serial and this will be our primary key.
We will also have name.
And the name will give it a variable character of a hundred, we'll just assume that nobody's name is
going to be more than one hundred characters, which again, I don't think we will.
Otherwise our database will give us an error.
We can also create a email field and this will be a text.
We also want to make sure that this is a unique email.
Otherwise we don't want to register the same user over and over.
And it cannot be not.
It must always be.
There because this is where we're going to use in our log-in table.
We also know that we want to entrées.
And the entries can really be a quite a big number if we have a really dedicated user, well, then
that person can keep submitting those photos.
So let's just do a large hint here.
Oops.
And instead of large, it's big.
And there you.
With big and we will also say that we want the default and this might be new for us, but default value
should be zero.
Unless we somehow insert with entries and a number, if we don't specify what we're inserting the number
with, it should be default to zero.
Finally, we also want to get the time that they joined our app and we can use a timestamp.
Data type for that and again, we want to make sure that this is not null either.
All right, let's run this and see if it works.
And I get an error at or near, and that's because I added a comma at the end here.
Let's try that again.
There you go.
If I refresh, we have our user stable, amazing, so we have the user stable, which we're going to
store.
All this information, and we also want to make sure that we store our login information, the email
and the hashes, because remember, we're never storing plaintext passwords.
I'm going to go back to the query.
Remove this and change it to.
Log in and this log in will now have an ID once again of cereal and the cereal data type will just increment,
it'll be a primary key.
And we'll have a column hash that has a variable character of a hundred once again, because we know
that B Crypt always gives us a certain length hash and it'll never be over one hundred characters not
no.
We absolutely need this information.
And then finally email, which will be the same as the users table.
And this email would be a text.
It must be unique and definitely not.
No.
All right, we got ourselves our tables designed, so now that we have these tables.
We understand what our data is going to look like, this is going to be a database that will persist
no matter if the server goes down, it's going to make sure that this data stays put.
Now that we have these three pieces running, we can start to work with the server, remove the database
variable and actually connect to our database.
I'm excited.
Show you how we're going to do that in the next video.