Welcome back.
We left off with Todd unable to register to our app because our backend server is not connected to any
database.
Luckily for us Heroku also has postgreSQL..
If I go to my dashboard here and let's go to personal and in this corner we have data. We click on data
and it says hey looks like you don't have any data stores yet and we have Heroku postgres Redis
and Kafka but postgres is what we need right.
So let's create one and we can just log in with the same credentials the same thing that we had for
our server and we can simply just install Heroku postgres and look at that.
It already knows which application we want to install it to. So let's click on that click continue.
And now we just pick the hobby dev which is free.
We click on provision.
There you go.
It says the addon Heroku postgres has been successfully installed.
Check out the documentation to get started.
That's awesome to hear.
Let's open it up and once again they have amazing documentation of how we can set up everything.
So looking at here the first thing we want to run is Heroku addons to make sure that we actually have
it.
Let's go back to our server.
I'm going to clear this and run Heroku addons and make this a little bit bigger.
All right we have Heroku postgres.
That's great.
If we actually scroll down we see that we can run the CLI with Heroku PG info.
So let's do that.
I want to say Heroku PG info and I'll show that yep this is our postgres and we can connect to
it by running PG psql just like we did on our laptop.
Let's do that.
I'm going to say Heroku PG PSQL
and look af that - we're in our database.
So let's recreate the database that we had originally.
We can simply go back to our PSQL because PSQL is smart enough to remember our commands.
And if we go to Query. There you go we have our create table commands ready.
So let's create a login table.
Perfect and let's create a the user tables well or a users table I'll copy this go back to Heroku and
create table let's do backslash d to make sure that the tables are there.
All right.
We have our tables and you see that the owner is well something completely different than my laptop.
But there's one more key thing that we need to fix.
Now we have our tables
but my connection on my server is still referring to my local host.
How can I change this.
If we exit out of this by doing backslash Q And we do again Heroku PG info
we have the add on which might be the URL but a better way for us to do this is to actually
run Heroku add ons.
Yeah it's the exact same one.
This is the URLl that they provide for us.
So let's try this.
If I do this postgres within this URL this database URL in here.
Will it work? Let's find out.
I'm going to once again Git add.
So we have to commit the changes.
And I will say updating database
git push Hiroko master.
All right.
It's deployed.
Let's go back to our app and see if it works now.
We have Todd at gmail dot com.
I click register.
We still get an error here if we go to a console here and actually network and click register again we have
400 bad request unable to register.
So let's take a look at the logs.
If we do Heroku logs dash dash tails
look at the error KNEX warning connection error.
So it's not finding the host that we want.
So let's go to our documentation to connecting to node dot js and we see here that with the client postgres
actually just gives us a database URL here.
And we also need to have SSL true here and we can read up on it a little bit more but we can just copy
this
remove all the database information and within the host we can say process dot env dot DATABASE_URL
Let's save.
We'll have to git add this again.
Git commit adding database
connection and we'll all Git push Heroku to Master
And while this is loading I really want to go through the fact that this is one of those things that
you just have to read and it's so platform specific that just because you learn this one way on Heroku
doesn't mean it works on the others but it's all a matter of just reading documentation and being comfortable
with that.
Let's do Heroku logs here to keep an eye on make sure everything is working.
All right we have a port so let's go back to our app.
I'm going to close the console for now.
Click register and it looks like it's still not working.
If we open up the network click register we have the bad request.
If we go back to the logs we have a KNEX warning again connection error.
This is a good time to use another command which is Heroku config
and Heroku config actually gives us the database your real and this database URL.
Well you see that they're using Amazon AWS But you see here in the KNEX warning that we're actually
getting that link so looks like we need to actually use the connection string exactly like they have
told us.
So we forgot to do that let's do a connection string here.
Whoops.
Let's copy this connection string.
And now it's getting repetitive.
But this is how a debugging session usually works.
I'm just going to do a quick commit here.
Git push Heroku master.
All right.
And let's give that another go.
Let's actually try registering now.
So we'll do Jenny
Jenny at gmail dot com we'll do one two three register and Jenny is logged in.
Awesome.
It's working.
If we go to the logs here we see that what we're doing post request to register and we can check out
the logs and we can even go to our postgres Heroku PG PSQL do a select star from users and we
have Jenny and Todd both registered.
Awesome.
Just to check that the login table is working as well.
I have a log in Table.
Nice.
And then finally to get a face
we'll grab another face.we'll view image.
That's a big one.
We'll see if it works nicely.
I press detect and look that it is working.
But Jennies entries is not updating.
Let's go back to Jenny's profile and make sure that her information is correct.
If I go to users looks like entry's is not being updated.
If we look in the console logs we get failed resource on the image endpoint
and if we go to the network and submit this again we see that the image endpoint is failing and this
is something that again we're going to tackle in the next video.
I'll see you in that one. Bye-Bye