1 00:00:01,460 --> 00:00:02,480 Welcome back. 2 00:00:02,480 --> 00:00:09,380 We left off with Todd unable to register to our app because our backend server is not connected to any 3 00:00:09,380 --> 00:00:10,420 database. 4 00:00:10,910 --> 00:00:15,200 Luckily for us Heroku also has postgreSQL.. 5 00:00:15,230 --> 00:00:27,120 If I go to my dashboard here and let's go to personal and in this corner we have data. We click on data 6 00:00:29,420 --> 00:00:36,470 and it says hey looks like you don't have any data stores yet and we have Heroku postgres Redis 7 00:00:36,500 --> 00:00:40,010 and Kafka but postgres is what we need right. 8 00:00:40,980 --> 00:00:51,820 So let's create one and we can just log in with the same credentials the same thing that we had for 9 00:00:51,820 --> 00:01:02,480 our server and we can simply just install Heroku postgres and look at that. 10 00:01:02,520 --> 00:01:13,580 It already knows which application we want to install it to. So let's click on that click continue. 11 00:01:13,690 --> 00:01:17,420 And now we just pick the hobby dev which is free. 12 00:01:17,590 --> 00:01:19,430 We click on provision. 13 00:01:19,450 --> 00:01:19,840 There you go. 14 00:01:19,840 --> 00:01:24,840 It says the addon Heroku postgres has been successfully installed. 15 00:01:24,870 --> 00:01:29,560 Check out the documentation to get started. 16 00:01:29,610 --> 00:01:31,090 That's awesome to hear. 17 00:01:31,230 --> 00:01:42,650 Let's open it up and once again they have amazing documentation of how we can set up everything. 18 00:01:42,700 --> 00:01:47,440 So looking at here the first thing we want to run is Heroku addons to make sure that we actually have 19 00:01:47,440 --> 00:01:47,820 it. 20 00:01:48,220 --> 00:01:49,780 Let's go back to our server. 21 00:01:49,810 --> 00:01:57,420 I'm going to clear this and run Heroku addons and make this a little bit bigger. 22 00:01:58,530 --> 00:02:01,060 All right we have Heroku postgres. 23 00:02:01,200 --> 00:02:01,950 That's great. 24 00:02:05,030 --> 00:02:15,800 If we actually scroll down we see that we can run the CLI with Heroku PG info. 25 00:02:15,850 --> 00:02:16,520 So let's do that. 26 00:02:16,540 --> 00:02:30,910 I want to say Heroku PG info and I'll show that yep this is our postgres and we can connect to 27 00:02:30,910 --> 00:02:38,970 it by running PG psql just like we did on our laptop. 28 00:02:39,190 --> 00:02:39,980 Let's do that. 29 00:02:40,300 --> 00:02:45,170 I'm going to say Heroku PG PSQL 30 00:02:48,900 --> 00:02:51,840 and look af that - we're in our database. 31 00:02:52,710 --> 00:02:56,120 So let's recreate the database that we had originally. 32 00:02:56,310 --> 00:03:06,680 We can simply go back to our PSQL because PSQL is smart enough to remember our commands. 33 00:03:06,930 --> 00:03:14,330 And if we go to Query. There you go we have our create table commands ready. 34 00:03:14,510 --> 00:03:18,330 So let's create a login table. 35 00:03:22,840 --> 00:03:35,800 Perfect and let's create a the user tables well or a users table I'll copy this go back to Heroku and 36 00:03:35,800 --> 00:03:41,470 create table let's do backslash d to make sure that the tables are there. 37 00:03:41,470 --> 00:03:41,890 All right. 38 00:03:41,950 --> 00:03:47,980 We have our tables and you see that the owner is well something completely different than my laptop. 39 00:03:47,980 --> 00:03:49,960 But there's one more key thing that we need to fix. 40 00:03:49,960 --> 00:03:51,210 Now we have our tables 41 00:03:54,060 --> 00:04:01,130 but my connection on my server is still referring to my local host. 42 00:04:01,380 --> 00:04:02,860 How can I change this. 43 00:04:04,350 --> 00:04:12,490 If we exit out of this by doing backslash Q And we do again Heroku PG info 44 00:04:17,760 --> 00:04:23,520 we have the add on which might be the URL but a better way for us to do this is to actually 45 00:04:23,520 --> 00:04:27,160 run Heroku add ons. 46 00:04:27,160 --> 00:04:28,800 Yeah it's the exact same one. 47 00:04:28,860 --> 00:04:34,260 This is the URLl that they provide for us. 48 00:04:34,260 --> 00:04:35,090 So let's try this. 49 00:04:35,100 --> 00:04:42,960 If I do this postgres within this URL this database URL in here. 50 00:04:42,960 --> 00:04:46,080 Will it work? Let's find out. 51 00:04:46,410 --> 00:04:49,310 I'm going to once again Git add. 52 00:04:49,350 --> 00:04:51,370 So we have to commit the changes. 53 00:04:53,690 --> 00:04:58,490 And I will say updating database 54 00:05:01,400 --> 00:05:08,080 git push Hiroko master. 55 00:05:08,110 --> 00:05:08,480 All right. 56 00:05:08,560 --> 00:05:09,770 It's deployed. 57 00:05:10,090 --> 00:05:12,970 Let's go back to our app and see if it works now. 58 00:05:12,970 --> 00:05:15,990 We have Todd at gmail dot com. 59 00:05:16,030 --> 00:05:19,950 I click register. 60 00:05:20,240 --> 00:05:27,300 We still get an error here if we go to a console here and actually network and click register again we have 61 00:05:27,300 --> 00:05:30,570 400 bad request unable to register. 62 00:05:30,570 --> 00:05:32,110 So let's take a look at the logs. 63 00:05:33,490 --> 00:05:39,970 If we do Heroku logs dash dash tails 64 00:05:42,630 --> 00:05:45,490 look at the error KNEX warning connection error. 65 00:05:45,600 --> 00:05:50,140 So it's not finding the host that we want. 66 00:05:50,250 --> 00:06:01,240 So let's go to our documentation to connecting to node dot js and we see here that with the client postgres 67 00:06:01,250 --> 00:06:03,970 actually just gives us a database URL here. 68 00:06:03,980 --> 00:06:11,600 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 69 00:06:11,600 --> 00:06:11,990 this 70 00:06:15,100 --> 00:06:33,000 remove all the database information and within the host we can say process dot env dot DATABASE_URL 71 00:06:33,140 --> 00:06:35,440 Let's save. 72 00:06:35,640 --> 00:06:38,630 We'll have to git add this again. 73 00:06:39,360 --> 00:06:44,710 Git commit adding database 74 00:06:47,290 --> 00:06:53,250 connection and we'll all Git push Heroku to Master 75 00:06:53,490 --> 00:06:57,930 And while this is loading I really want to go through the fact that this is one of those things that 76 00:06:57,930 --> 00:07:04,530 you just have to read and it's so platform specific that just because you learn this one way on Heroku 77 00:07:04,530 --> 00:07:09,690 doesn't mean it works on the others but it's all a matter of just reading documentation and being comfortable 78 00:07:09,690 --> 00:07:10,160 with that. 79 00:07:11,030 --> 00:07:16,670 Let's do Heroku logs here to keep an eye on make sure everything is working. 80 00:07:16,670 --> 00:07:20,590 All right we have a port so let's go back to our app. 81 00:07:20,610 --> 00:07:22,910 I'm going to close the console for now. 82 00:07:22,950 --> 00:07:28,180 Click register and it looks like it's still not working. 83 00:07:28,190 --> 00:07:32,980 If we open up the network click register we have the bad request. 84 00:07:33,090 --> 00:07:38,630 If we go back to the logs we have a KNEX warning again connection error. 85 00:07:38,630 --> 00:07:42,980 This is a good time to use another command which is Heroku config 86 00:07:45,930 --> 00:07:53,270 and Heroku config actually gives us the database your real and this database URL. 87 00:07:53,270 --> 00:08:00,670 Well you see that they're using Amazon AWS But you see here in the KNEX warning that we're actually 88 00:08:00,670 --> 00:08:08,530 getting that link so looks like we need to actually use the connection string exactly like they have 89 00:08:08,530 --> 00:08:09,480 told us. 90 00:08:09,820 --> 00:08:12,370 So we forgot to do that let's do a connection string here. 91 00:08:12,370 --> 00:08:13,100 Whoops. 92 00:08:13,150 --> 00:08:16,330 Let's copy this connection string. 93 00:08:17,160 --> 00:08:20,660 And now it's getting repetitive. 94 00:08:20,680 --> 00:08:25,890 But this is how a debugging session usually works. 95 00:08:25,890 --> 00:08:28,830 I'm just going to do a quick commit here. 96 00:08:29,000 --> 00:08:30,700 Git push Heroku master. 97 00:08:30,720 --> 00:08:31,100 All right. 98 00:08:31,110 --> 00:08:32,320 And let's give that another go. 99 00:08:32,320 --> 00:08:35,169 Let's actually try registering now. 100 00:08:35,260 --> 00:08:36,070 So we'll do Jenny 101 00:08:40,820 --> 00:08:49,580 Jenny at gmail dot com we'll do one two three register and Jenny is logged in. 102 00:08:49,760 --> 00:08:50,290 Awesome. 103 00:08:50,310 --> 00:08:51,000 It's working. 104 00:08:51,030 --> 00:08:57,660 If we go to the logs here we see that what we're doing post request to register and we can check out 105 00:08:57,660 --> 00:09:17,170 the logs and we can even go to our postgres Heroku PG PSQL do a select star from users and we 106 00:09:17,170 --> 00:09:20,570 have Jenny and Todd both registered. 107 00:09:20,830 --> 00:09:21,530 Awesome. 108 00:09:21,730 --> 00:09:24,980 Just to check that the login table is working as well. 109 00:09:26,110 --> 00:09:27,910 I have a log in Table. 110 00:09:27,910 --> 00:09:28,700 Nice. 111 00:09:28,720 --> 00:09:33,270 And then finally to get a face 112 00:09:35,850 --> 00:09:41,240 we'll grab another face.we'll view image. 113 00:09:41,410 --> 00:09:42,710 That's a big one. 114 00:09:42,710 --> 00:09:45,010 We'll see if it works nicely. 115 00:09:45,020 --> 00:09:50,830 I press detect and look that it is working. 116 00:09:50,870 --> 00:09:57,090 But Jennies entries is not updating. 117 00:09:57,140 --> 00:10:02,640 Let's go back to Jenny's profile and make sure that her information is correct. 118 00:10:02,660 --> 00:10:07,200 If I go to users looks like entry's is not being updated. 119 00:10:10,120 --> 00:10:19,160 If we look in the console logs we get failed resource on the image endpoint 120 00:10:22,190 --> 00:10:31,570 and if we go to the network and submit this again we see that the image endpoint is failing and this 121 00:10:31,570 --> 00:10:37,680 is something that again we're going to tackle in the next video. 122 00:10:37,760 --> 00:10:38,440 I'll see you in that one. Bye-Bye