1
00:00:00,500 --> 00:00:01,920
Hey, welcome to this new lecture.

2
00:00:02,010 --> 00:00:08,480
And by the end of this lecture, I'm going to have my webapp published online.

3
00:00:09,200 --> 00:00:10,770
So instead of this, I'll have a public URL.

4
00:00:10,770 --> 00:00:18,090
And everyone can visit my Web app and everyone can send data and gets an e-mail to their

5
00:00:18,090 --> 00:00:18,750
e-mail address.

6
00:00:19,810 --> 00:00:26,180
And as you can imagine, I'm going to use Heroku to deploy my files to their Cloud.

7
00:00:27,480 --> 00:00:29,640
So we used Heroku twice in the course.

8
00:00:29,670 --> 00:00:34,490
We use Heroku to deploy a static Flask Website.

9
00:00:35,140 --> 00:00:41,580
And then we used Heroku again to deploy a Bokeh chart, which was, again, a Flask Website.

10
00:00:43,050 --> 00:00:45,990
Now, this here is going to be a little bit different.

11
00:00:46,440 --> 00:00:54,210
The difference there is this time we have a database involved in this, and that means there are a few

12
00:00:54,210 --> 00:01:00,400
more steps that we need to go through in order to have this Web application online.

13
00:01:00,990 --> 00:01:06,630
So it's good that you first go through the lecturer named deploying the Web site to a live server,

14
00:01:06,900 --> 00:01:10,430
which is part of the section where we build the static Web site with Flask.

15
00:01:11,400 --> 00:01:17,100
In this lecture, I'm going to go through those steps again, but I'm not going to stop in detail at

16
00:01:17,100 --> 00:01:17,640
each of them.

17
00:01:18,390 --> 00:01:22,390
So this is still going to work if you haven't taken that to lecture already.

18
00:01:23,860 --> 00:01:27,570
And, you know, I'll go through each step one by one.

19
00:01:31,650 --> 00:01:34,320
So let me stop this script first.

20
00:01:34,380 --> 00:01:34,830
Control.

21
00:01:35,100 --> 00:01:36,630
C.

22
00:01:36,700 --> 00:01:40,260
These are my files. For this to work,

23
00:01:40,500 --> 00:01:45,390
you need an account in Heroku and I've shown you that earlier.

24
00:01:45,870 --> 00:01:48,510
So you need to create an account on Heroku.com.

25
00:01:49,410 --> 00:01:53,010
And then you need to download the Heroku Toolbelt.

26
00:01:53,850 --> 00:01:55,760
So please do so if you haven't done already.

27
00:01:58,720 --> 00:02:04,300
Once you have gone through those steps and then you go ahead and open a terminal in these directories.

28
00:02:04,400 --> 00:02:09,050
In the main directory of your application, in my case, that had to be this one here, demo.

29
00:02:09,490 --> 00:02:15,140
And as usually what you want to do, is you want to initialize a git repository in your local directory,

30
00:02:15,140 --> 00:02:16,160
in your current directory.

31
00:02:17,580 --> 00:02:20,600
Then you also want to have these three files,

32
00:02:20,690 --> 00:02:23,510
so the requirements.txt file, the porc profile.

33
00:02:23,960 --> 00:02:25,590
And the runtime.txt file.

34
00:02:26,160 --> 00:02:29,150
Then you upload all of these files to Heroku.

35
00:02:30,170 --> 00:02:33,800
However, in this case, we still need these three files.

36
00:02:34,220 --> 00:02:41,480
But we also need to make a small change in our app.py file, which is what this one here.

37
00:02:42,680 --> 00:02:48,440
As you can see here, this DATABASE_URI is pointing to our local database.

38
00:02:49,220 --> 00:02:53,060
So I've got my postgresql installed in my system.

39
00:02:54,470 --> 00:02:57,220
And that URI is pointing to my local postgresql.

40
00:02:58,460 --> 00:03:00,830
What you want to do now is you want to change

41
00:03:00,870 --> 00:03:03,330
you want to change this URL to points to the Heroku database.

42
00:03:03,830 --> 00:03:08,630
However, we still don't know the URI of our Heroku database.

43
00:03:09,400 --> 00:03:13,100
Now, the reason we do know that is that we still don't have a database in Heroku.

44
00:03:13,820 --> 00:03:15,440
So let's go ahead and create a database.

45
00:03:17,000 --> 00:03:23,600
Again, you need to go to your command line, you need to log in, Heroku login.

46
00:03:24,770 --> 00:03:30,130
So if you haven't installed Heroku Toolbelt yet, you wouldn't be able to login to Heroku.

47
00:03:30,500 --> 00:03:34,760
So Heroku Toolbelt makes it possible to login to the Heroku server.

48
00:03:41,390 --> 00:03:50,750
These are the credentials that I used to create a Heroku account and my password there and I'm logged

49
00:03:50,750 --> 00:03:51,330
in successful.

50
00:03:51,810 --> 00:03:59,570
Now databases come as add ons in Heroku, and you can either go through, to create a database

51
00:03:59,570 --> 00:04:00,470
through the Web page.

52
00:04:01,850 --> 00:04:09,650
So you'd go here, and go to databases, and then you create a database in here.

53
00:04:09,950 --> 00:04:11,640
But this is not recommended.

54
00:04:13,520 --> 00:04:15,860
The correct way to do that is through the command line.

55
00:04:16,610 --> 00:04:21,620
This will also allow you to connect to your database through the appropriate app.

56
00:04:21,980 --> 00:04:27,390
So in our case, we need to connect this database to an app that we haven't uncreated yet.

57
00:04:27,710 --> 00:04:32,960
So let's first create an app in Heroku and then we create a database and we connect the database to

58
00:04:32,960 --> 00:04:33,650
that app.

59
00:04:33,770 --> 00:04:36,800
To create an app is quite easy, Heroku create,

60
00:04:38,050 --> 00:04:44,230
and the app name, let's say data collector.

61
00:04:44,740 --> 00:04:48,970
Hopefully, this will be free, not occupied. Yeah, that it's already taken.

62
00:04:50,710 --> 00:04:51,640
Well, let's try another one.

63
00:04:54,790 --> 00:04:56,250
Dcollector maybe.

64
00:04:57,870 --> 00:04:58,630
Dcollector.

65
00:04:59,530 --> 00:05:00,760
All right, that was created.

66
00:05:01,130 --> 00:05:08,820
And now we go ahead and create a database and databases come as add ons in Heroku.

67
00:05:09,280 --> 00:05:13,620
So you do want to say: "heroku addons create".

68
00:05:13,660 --> 00:05:15,040
So you want to create a new addon.

69
00:05:16,720 --> 00:05:23,940
And then Heroku. The addon name that you want to create is heroku-postgresql: and a colon.

70
00:05:24,350 --> 00:05:30,270
And here comes the type of database which would be a hobby-dev.

71
00:05:30,670 --> 00:05:36,160
So you have quite a few databases, which technically are the same.

72
00:05:36,190 --> 00:05:37,750
But this one is free.

73
00:05:38,610 --> 00:05:41,140
And this hobby-dev, which means hobby developer.

74
00:05:41,440 --> 00:05:42,880
So you're making this for hobby.

75
00:05:43,720 --> 00:05:51,760
This particular one doesn't allow you to have more than 10000 records rows in your database, which

76
00:05:51,760 --> 00:05:52,800
is still a good number

77
00:05:52,840 --> 00:05:53,320
by the way.

78
00:05:54,530 --> 00:06:00,130
And if you want more than you'd have to pay for another database, you're going to look up for that

79
00:06:00,160 --> 00:06:02,050
on Heroku to get the prices.

80
00:06:02,290 --> 00:06:09,970
But this will work great for us, so let's create that. You need to pass a flag, the app flag.

81
00:06:11,320 --> 00:06:16,210
And then here you pass the name of the app that you want to connect to your database to.

82
00:06:17,000 --> 00:06:17,210
So execute

83
00:06:17,650 --> 00:06:17,920
that.

84
00:06:20,490 --> 00:06:23,490
Database has been created and is available.

85
00:06:24,520 --> 00:06:29,850
This database is empty, of course, we have just created it. Note that if you have a free

86
00:06:29,860 --> 00:06:33,930
Heroku account like I have, you can't have more than five apps.

87
00:06:34,680 --> 00:06:35,940
That includes databases.

88
00:06:36,000 --> 00:06:42,720
So if you already had five apps in Heroku, you'd be able to create a database because that would be

89
00:06:42,720 --> 00:06:47,800
counted as another app, which it's not technically an app, but it's counted out.

90
00:06:47,980 --> 00:06:54,960
Now that we have a database, we need to figure out a way to get the URI of that database so that

91
00:06:54,960 --> 00:07:01,200
we can replace the URI, in our app.py script, and to get the URI of the database

92
00:07:01,320 --> 00:07:08,730
you'd say Heroku config --app decollector execute.

93
00:07:12,680 --> 00:07:13,230
Yeah, that's it.

94
00:07:13,530 --> 00:07:16,800
No, I'm going to go ahead and copy this.

95
00:07:20,060 --> 00:07:20,480
Like that.

96
00:07:20,840 --> 00:07:24,120
Be careful here if you miss a character things

97
00:07:24,370 --> 00:07:25,490
won't to work.

98
00:07:26,090 --> 00:07:26,810
So if I

99
00:07:26,810 --> 00:07:27,440
right-click here,

100
00:07:27,650 --> 00:07:28,220
I copy that,

101
00:07:29,210 --> 00:07:32,690
and paste it there.

102
00:07:34,970 --> 00:07:36,920
Be careful here.

103
00:07:37,070 --> 00:07:38,650
We only need this.

104
00:07:39,040 --> 00:07:43,190
This part. That should be assigned to this.

105
00:07:50,570 --> 00:07:53,160
And this goes here.

106
00:07:55,740 --> 00:08:04,940
Let me view Toggle Soft Wrap and save, and I'd comment this out.

107
00:08:05,040 --> 00:08:12,960
I don't need this anymore, so please triple check this, because if you get this wrong, it will be

108
00:08:13,350 --> 00:08:14,930
difficult to troubleshoot it.

109
00:08:15,900 --> 00:08:20,280
So, again, what we have is app.config and then sqlalchemy DATABASE_URI.

110
00:08:21,170 --> 00:08:23,040
And that is equal to a string.

111
00:08:23,890 --> 00:08:27,200
And in that string you should enter the database URI

112
00:08:27,260 --> 00:08:28,800
that we got from here.

113
00:08:29,480 --> 00:08:36,600
So this part in here, and yeah what that means is, you know, this would be the username.

114
00:08:37,230 --> 00:08:38,580
This would be the password.

115
00:08:39,630 --> 00:08:40,490
Up to here.

116
00:08:40,780 --> 00:08:51,960
And then you have @, and then the address of the server up to here and then a column and the port

117
00:08:51,960 --> 00:08:52,210
of the server.

118
00:08:52,960 --> 00:08:56,140
And then you have the name or the database.

119
00:08:57,060 --> 00:09:02,600
Then I need to add something more here and that would be sslmode=require.

120
00:09:03,480 --> 00:09:09,660
So what I'm doing here, I'm, I'm forcing the PostgreSQL adopter to actually use, to actually require

121
00:09:09,690 --> 00:09:17,910
SSL because otherwise, I won't be able to connect to the database through my command line.

122
00:09:18,300 --> 00:09:24,960
So from my Windows computer though, the reason I want to connect to Heroku through my Windows computer

123
00:09:25,320 --> 00:09:31,740
is that I'm going to create a table in the database and I'll show you how to do that in just a minute.

124
00:09:32,640 --> 00:09:34,800
So please include this part here.

125
00:09:35,880 --> 00:09:44,580
Questionmark ?sslmode=required. Make sure, to save the script and then go to the command line again.

126
00:09:45,900 --> 00:09:51,630
Now the app file is ready to be deployed to Heroku, but we need these files.

127
00:09:51,720 --> 00:09:56,070
So we need the requirements.txt and the other files that I mentioned earlier.

128
00:09:56,430 --> 00:09:58,240
So let's go ahead and create these files.

129
00:09:59,920 --> 00:10:00,190
Mm hmm.

130
00:10:01,530 --> 00:10:03,990
I'm going to activate the virtual environment first.

131
00:10:09,600 --> 00:10:11,040
So that I can create

132
00:10:15,250 --> 00:10:19,350
a requirements.txt file with all the packages that I have installed.

133
00:10:20,130 --> 00:10:28,680
However, as you know, you first need to install gunicorn so that gonicorn is included in the requirements.txt

134
00:10:28,680 --> 00:10:29,280
file.

135
00:10:31,010 --> 00:10:35,220
And yeah, once you've done that, then you go ahead and pip freeze.

136
00:10:35,380 --> 00:10:47,270
And requirements.txt, double-check the name, requirements.txt, yeah, execute and we have requirements.txt

137
00:10:47,280 --> 00:10:49,770
generated.

138
00:10:49,970 --> 00:10:52,730
Gunicorn is there and everything else that we need.

139
00:10:54,540 --> 00:11:01,830
Now I'll create a Procfile.

140
00:11:03,780 --> 00:11:08,820
This should be without any extension. On a Mac and Linux

141
00:11:08,820 --> 00:11:16,380
you can easily make a file without extensions, but on Windows, if you go here you have to make sure

142
00:11:16,650 --> 00:11:20,820
that height extensions for known file types should be unchecked.

143
00:11:21,990 --> 00:11:27,240
So make sure of that, and then you can create a ProcFile without an extension.

144
00:11:27,910 --> 00:11:32,610
Then you can go ahead and edit it in Atom, or notepad, or whatever you like.

145
00:11:33,780 --> 00:11:41,980
That should be web: gunicorn and app for the file name.

146
00:11:42,030 --> 00:11:47,190
So we have app.py, and app.py has a variable named app.

147
00:11:47,790 --> 00:11:50,970
So the variable where our Flask instance is stored.

148
00:11:51,300 --> 00:11:53,010
So app:app like that.

149
00:11:54,260 --> 00:11:54,370
Yeah.

150
00:11:54,420 --> 00:12:03,100
We're done with that. ProcFile requirements.txt and another file called 

151
00:12:03,610 --> 00:12:04,380
runtime.txt.

152
00:12:15,820 --> 00:12:17,560
So I'm using Python 3.

153
00:12:17,760 --> 00:12:19,840
And therefore, I need to write here

154
00:12:20,380 --> 00:12:28,680
python-3.5.1 because that's the available runtime for Heroku at the moment.

155
00:12:29,050 --> 00:12:31,060
But you can check that out for the Internet.

156
00:12:31,540 --> 00:12:32,560
On the Heroku Webpage.

157
00:12:32,980 --> 00:12:37,630
So they have 3.5.1, and 2.7.11 at the moment.

158
00:12:39,280 --> 00:12:46,080
And now we didn't do these in our previous lectures where I showed you how to deploy websites on Heroku.

159
00:12:46,810 --> 00:12:54,480
But in this lecture, I'm going to create another file and that should be named .gitignore.

160
00:12:56,350 --> 00:12:58,930
Actually, this is not possible on Windows.

161
00:12:59,050 --> 00:13:04,810
So you can not have a file without a name. On a Mac and a Linux

162
00:13:04,810 --> 00:13:05,950
you wouldn't have this problem.

163
00:13:06,760 --> 00:13:09,310
So the workaround here is to...

164
00:13:10,110 --> 00:13:17,440
I'll delete that, you know, you can create a file from the command line and you can use Notepad and then

165
00:13:17,440 --> 00:13:20,080
say .gitignore.

166
00:13:20,140 --> 00:13:24,550
So the file name. Cannot find the .gitignore file.

167
00:13:24,560 --> 00:13:29,170
Do you want to create a new file? Yes, and that will create a dot ignore file.

168
00:13:30,310 --> 00:13:33,400
So this one here, that's the workaround.

169
00:13:33,730 --> 00:13:41,830
Now, what this .gitignore file is, is a file where you can pass the names of folders of the

170
00:13:41,830 --> 00:13:48,970
directories and the files that you don't want to upload to Heroku, because, you know, when you initialize

171
00:13:49,050 --> 00:13:55,180
a git repository and then you add and then you add the files to the repository, all the files

172
00:13:55,240 --> 00:14:01,780
that are in this directory and all the directories with files inside them will be uploaded to

173
00:14:01,800 --> 00:14:01,960
Heroku.

174
00:14:02,110 --> 00:14:07,170
But sometimes you may not need some folders, some directories or files such as virtual.

175
00:14:07,480 --> 00:14:15,550
So we don't need a whole virtual environment to to upload it on Heroku because that's that'd be around

176
00:14:15,550 --> 00:14:16,810
45 megabytes.

177
00:14:17,590 --> 00:14:18,310
We don't need that.

178
00:14:19,120 --> 00:14:21,840
Previously when we deployed Flask Websites to Heroku,

179
00:14:22,300 --> 00:14:28,490
in our previous lectures, the Virtual folder was outside of the demo folder.

180
00:14:28,900 --> 00:14:36,370
So the virtual directory was one level up and it wasn't included in the deployment. In this case

181
00:14:36,400 --> 00:14:38,470
this is in this directory here.

182
00:14:38,800 --> 00:14:40,660
So it will be included in the deployment.

183
00:14:40,690 --> 00:14:41,530
It will be uploaded to Heroku.

184
00:14:42,190 --> 00:14:46,400
Therefore, we have this git ignore file that git knows.

185
00:14:46,600 --> 00:14:50,920
So it is able to read the file name and that he knows what to do with the file.

186
00:14:51,760 --> 00:14:58,170
So in that file you can go ahead now and it's .gitignore.

187
00:14:58,840 --> 00:15:01,480
And what you can do is you can pass

188
00:15:05,470 --> 00:15:10,180
the folder, the directory, and the file names that you don't want to include in deployment.

189
00:15:10,510 --> 00:15:15,420
So __pychache__ and I have this heroktest.

190
00:15:15,940 --> 00:15:21,430
I think I was doing some tests earlier, so I created this and I wouldn't want that to be uploaded.

191
00:15:21,940 --> 00:15:28,730
Also virtual the directory, and then we have this file

192
00:15:28,780 --> 00:15:29,040
in here.

193
00:15:32,670 --> 00:15:34,440
Let me copy it.

194
00:15:36,900 --> 00:15:37,440
Here we are.

195
00:15:38,100 --> 00:15:39,370
So that was a whl.

196
00:15:40,560 --> 00:15:43,010
I don't want that to be uploaded to Heroku either.

197
00:15:44,040 --> 00:15:45,330
What else do we have here?

198
00:15:47,450 --> 00:15:47,570
Yeah.

199
00:15:47,760 --> 00:15:48,180
That's it.

200
00:15:49,570 --> 00:15:50,670
So let me double check.

201
00:15:50,820 --> 00:15:50,960
Yeah.

202
00:15:51,440 --> 00:15:55,690
Py_chache, herok_test and psycopg2.

203
00:15:55,960 --> 00:15:56,760
That's all.

204
00:15:59,420 --> 00:16:00,760
Save that file,

205
00:16:00,790 --> 00:16:00,920
and yeah.

206
00:16:01,050 --> 00:16:03,510
Oh we're basically done with generating files.

207
00:16:04,440 --> 00:16:04,550
Yeah.

208
00:16:04,770 --> 00:16:06,570
So we had ProcFile, runtime.txt.

209
00:16:07,300 --> 00:16:10,400
Requirements.txt, and .gitignore.

210
00:16:11,580 --> 00:16:17,440
Let's go back to our console now and we are ready to deploy our files.

211
00:16:18,210 --> 00:16:21,640
So first of all, you need to create to initialize the gitrepository.

212
00:16:22,430 --> 00:16:24,380
We got the dot git folder in there.

213
00:16:25,320 --> 00:16:31,470
Then get and add everything, and then git commit the changes.

214
00:16:34,890 --> 00:16:36,750
First commit as note.

215
00:16:38,990 --> 00:16:39,510
Oh, sorry.

216
00:16:39,870 --> 00:16:43,200
I meant to say commit with double m.

217
00:16:43,530 --> 00:16:44,840
I put three ms there.

218
00:16:46,770 --> 00:16:47,230
Alright.

219
00:16:48,630 --> 00:16:50,510
And 12 changed.

220
00:16:50,550 --> 00:16:53,370
So we've got the 12 files added to the repository.

221
00:16:54,060 --> 00:16:55,380
Actually there should be less.

222
00:16:55,530 --> 00:16:57,360
Maybe I've made some error here.

223
00:16:57,360 --> 00:17:00,050
__pychache__. 

224
00:17:00,500 --> 00:17:04,510
I have added an H in here which shouldn't be the there.

225
00:17:05,700 --> 00:17:10,620
That means I'm uploading these three files as well to my app.

226
00:17:11,480 --> 00:17:12,430
That shouldn't be a problem.

227
00:17:12,450 --> 00:17:13,860
So let's just ignore that.

228
00:17:14,430 --> 00:17:20,520
It's important to not include the virtual directory because that's quite big and you don't want to have

229
00:17:21,000 --> 00:17:24,730
that many files in your Web application directory on Heroku.

230
00:17:25,260 --> 00:17:25,500
Good.

231
00:17:27,020 --> 00:17:30,360
We're now ready to push the changes to Heroku.

232
00:17:31,050 --> 00:17:35,470
First, let's make sure Heroku info.

233
00:17:36,630 --> 00:17:38,850
Let's see if we're connected to our app.

234
00:17:39,180 --> 00:17:40,820
So it says no app specified.

235
00:17:42,000 --> 00:17:47,280
So let's go ahead and connect our session to our app.

236
00:17:48,000 --> 00:17:48,660
That'd be git: remote, the app flag.

237
00:17:48,750 --> 00:17:58,860
After that, we have to enter the name of our app, dcollector.

238
00:17:58,950 --> 00:18:00,810
And that should do it.

239
00:18:02,090 --> 00:18:02,340
So yeah.

240
00:18:02,380 --> 00:18:06,150
And now we have set a git remote, which has the name Heroku.

241
00:18:06,750 --> 00:18:08,810
Now we go ahead and say git push heroku.

242
00:18:09,080 --> 00:18:13,000
Which happens to be the name of our git.

243
00:18:13,830 --> 00:18:16,280
So heroku master.

244
00:18:18,750 --> 00:18:23,370
And you may have to wait a while here while these are applied.

245
00:18:23,640 --> 00:18:26,550
So we've got a python that was detected.

246
00:18:28,570 --> 00:18:35,650
So then installing Python 3.5.1, and then installing the dependencies.

247
00:18:35,680 --> 00:18:37,080
So the packages.

248
00:18:41,090 --> 00:18:43,060
And know that completed successfully.

249
00:18:43,510 --> 00:18:45,010
However, we are not done yet.

250
00:18:45,100 --> 00:18:54,640
I mean, you can check up Heroku Open EPM, sorry.

251
00:18:56,350 --> 00:18:58,870
So I'm just checking if the website is up.

252
00:18:58,900 --> 00:19:01,110
So it's actually uploaded.

253
00:19:01,780 --> 00:19:04,330
But if you enter some data in there

254
00:19:08,250 --> 00:19:11,710
and you say submit, you get an error.

255
00:19:13,270 --> 00:19:19,240
So either the server is overloaded, which is not the case, or there is an error in the application.

256
00:19:20,110 --> 00:19:27,100
And our error is that you know, we have a database on Heroku because we created that earlier in

257
00:19:27,100 --> 00:19:29,080
the terminal session.

258
00:19:29,650 --> 00:19:32,800
So with this command: heroku addons create heroku PostgreSQL.

259
00:19:33,040 --> 00:19:34,330
But that's an empty database.

260
00:19:34,330 --> 00:19:37,360
So we haven't created the tables just yet.

261
00:19:37,640 --> 00:19:39,600
And to create a table there.

262
00:19:40,600 --> 00:19:45,410
You know, we have this model here, and our tables should be named data.

263
00:19:45,850 --> 00:19:48,480
But we haven't executed this model on Heroku.

264
00:19:50,380 --> 00:19:54,730
We have this table in our computer, in our local system.

265
00:19:54,940 --> 00:20:02,440
If you could remember, we did from app import db and db.create_all that created a table.

266
00:20:02,680 --> 00:20:04,370
So we're gonna do the same on Heroku.

267
00:20:05,860 --> 00:20:06,810
So how do we do that?

268
00:20:07,700 --> 00:20:15,990
Oh well, we do that from the command line again and we have to open a Python session on Heroku.

269
00:20:17,020 --> 00:20:22,980
So basically what we're gonna do is we're going to execute by phone that is installed on Heroku from

270
00:20:22,980 --> 00:20:24,910
our command line. To do that

271
00:20:25,000 --> 00:20:28,110
you say heroku, run, and Python.

272
00:20:36,830 --> 00:20:42,750
And that will run a Python 3.5.1 session for you, even if it's

273
00:20:42,750 --> 00:20:43,530
python 2.7

274
00:20:44,040 --> 00:20:48,030
that shouldn't be a problem because we're just running some basic commands here.

275
00:20:48,450 --> 00:20:50,640
So the version shouldn't be a problem at this point.

276
00:20:51,570 --> 00:20:53,280
That's how you run a python session.

277
00:20:53,340 --> 00:20:54,630
And, you know.

278
00:20:55,050 --> 00:20:57,570
Let me exit for a moment.

279
00:20:58,260 --> 00:21:01,860
You can also are on a bash on Heroku.

280
00:21:01,860 --> 00:21:04,560
We just like the terminal.

281
00:21:04,670 --> 00:21:06,540
Heroku runs on Linux.

282
00:21:06,930 --> 00:21:12,420
So now that bash is open here, you can execute Linux commands ls.

283
00:21:12,650 --> 00:21:20,030
It will list all the files and folders that you have in the main directory, which is app.py,

284
00:21:20,050 --> 00:21:20,600
our app file.

285
00:21:21,210 --> 00:21:27,930
Then you have runtime.txt, and static folder, and so on. You know, we don't have this virual

286
00:21:27,930 --> 00:21:28,380
folder.

287
00:21:28,980 --> 00:21:32,480
We have the pycache there because I made this typo.

288
00:21:33,630 --> 00:21:36,270
And yeah, if you want to see

289
00:21:38,910 --> 00:21:40,150
what these files contain.

290
00:21:40,170 --> 00:21:41,310
You can do cat

291
00:21:42,540 --> 00:21:44,010
and the name or the file.

292
00:21:44,090 --> 00:21:47,370
So so cat app.py, and you'll see the code there.

293
00:21:49,590 --> 00:21:56,520
However, you cannot edit your files directly on Heroku, the way to edit your files is the

294
00:21:56,520 --> 00:21:59,010
way that I showed you earlier in the course.

295
00:21:59,330 --> 00:22:02,670
You know that that was the lecturer named "Maintaining your website".

296
00:22:03,480 --> 00:22:07,870
That's where you'll learn how to change something on your files.

297
00:22:08,790 --> 00:22:09,800
So you change that locally.

298
00:22:09,870 --> 00:22:13,260
Then you upload the changes via get to Heroku.

299
00:22:13,860 --> 00:22:18,120
That's how it should work, actually, because you have a separate development environment there.

300
00:22:18,450 --> 00:22:20,760
And then you upload the changes to the production.

301
00:22:20,790 --> 00:22:21,800
So to Heroku.

302
00:22:22,950 --> 00:22:25,800
So please check out that lecture, if you like/

303
00:22:25,830 --> 00:22:27,210
Later on if you want to make changes.

304
00:22:27,750 --> 00:22:34,370
And I'll text exit the Bash now with Exit, and run python again.

305
00:22:36,910 --> 00:22:42,160
So, now, I'm running python on the main directory where my app.py file is located.

306
00:22:43,370 --> 00:22:52,060
And what that means is, you know, I can say from app, which is the app.py file import db.

307
00:22:54,380 --> 00:22:55,700
We've got a warning there.

308
00:22:55,780 --> 00:22:58,930
But I wouldn't go through that now.

309
00:22:59,020 --> 00:23:00,160
So things are working, actually.

310
00:23:01,070 --> 00:23:05,000
We were able to import the db sqlalchemy object there.

311
00:23:05,600 --> 00:23:12,950
And then you say db.create_all just as we did in our local system earlier when we built the

312
00:23:12,950 --> 00:23:15,340
application, and yeah.

313
00:23:15,620 --> 00:23:16,320
That is successful.

314
00:23:16,900 --> 00:23:18,100
And you can exit then.

315
00:23:21,290 --> 00:23:28,460
So now you have you should have a table named data or whatever you have called it, whatever you have

316
00:23:28,460 --> 00:23:31,460
named it in here.

317
00:23:31,700 --> 00:23:35,410
So here you should have a table in your Heroku database.

318
00:23:35,820 --> 00:23:41,930
And there is actually a way to prove that, you know, you can run escarole commands from your command

319
00:23:41,930 --> 00:23:47,000
line again, commands that point to the Heroku database.

320
00:23:48,350 --> 00:23:51,200
However, you should make sure that PSQL

321
00:23:51,200 --> 00:23:52,830
is added to your,

322
00:23:53,090 --> 00:23:56,780
to your path, to your search path in your computer.

323
00:23:57,590 --> 00:24:04,490
So on Windows, that's means psql.exe should be included in your environment variables.

324
00:24:05,540 --> 00:24:07,640
So at the moment mine is not included.

325
00:24:07,820 --> 00:24:09,230
So I'm gonna go ahead and include that.

326
00:24:09,920 --> 00:24:12,590
So you should go to your Program Files.

327
00:24:12,590 --> 00:24:13,390
PosgreSQL.

328
00:24:13,470 --> 00:24:13,780
And...

329
00:24:14,090 --> 00:24:20,690
The version folder and bin. So here,

330
00:24:20,720 --> 00:24:26,280
here we have this psql, should be among these files.

331
00:24:28,610 --> 00:24:29,060
It's here.

332
00:24:30,410 --> 00:24:35,660
So what we need is when you type in psql from the command line you want to execute this file.

333
00:24:35,900 --> 00:24:38,570
And that accesses SQL queries.

334
00:24:40,340 --> 00:24:48,570
So what you do is just copy this path and go to the environment, environment variables.

335
00:24:48,570 --> 00:24:55,880
So system environment variables, go to Environment Variables button and then locate here,

336
00:24:55,910 --> 00:24:58,720
down here, the path variable.

337
00:24:59,360 --> 00:25:06,050
Go to edit and you have some existing values there.

338
00:25:06,170 --> 00:25:07,370
So some other paths.

339
00:25:07,770 --> 00:25:11,930
And what you want to do is you want to make sure that you have a semicolumn in there.

340
00:25:12,780 --> 00:25:15,620
And then you paste your other path.

341
00:25:15,860 --> 00:25:16,970
So it should be like this.

342
00:25:18,470 --> 00:25:21,000
This is our path like that.

343
00:25:21,020 --> 00:25:21,990
Okay.

344
00:25:22,430 --> 00:25:22,880
Okay.

345
00:25:22,900 --> 00:25:23,370
There.

346
00:25:23,560 --> 00:25:23,910
Okay.

347
00:25:23,930 --> 00:25:24,260
Here.

348
00:25:25,270 --> 00:25:30,080
And now my current terminal probably hasn't received the path yet.

349
00:25:30,320 --> 00:25:31,610
So I'm going to open a new one.

350
00:25:32,280 --> 00:25:34,070
Everywhere.

351
00:25:34,100 --> 00:25:34,870
Everywhere he wants.

352
00:25:35,360 --> 00:25:36,300
So mine is at C.

353
00:25:36,370 --> 00:25:41,180
And I'm gonna go ahead and Heroku login again.

354
00:25:46,880 --> 00:25:48,710
Pass my credentials.

355
00:25:51,690 --> 00:26:03,110
Then you want to run a command heroku pg: psql and the app name, which is dcollecor. Execute.

356
00:26:07,290 --> 00:26:08,290
Connecting to database.

357
00:26:08,940 --> 00:26:11,850
If you see this, then that means you're connected.

358
00:26:13,490 --> 00:26:19,740
And now every sql query that you do is applied to the database or your dcollector app.

359
00:26:20,040 --> 00:26:25,470
So the app that you specified in here, let's say select from data.

360
00:26:27,910 --> 00:26:29,580
Yeah, we got zeros.

361
00:26:30,420 --> 00:26:31,380
We didn't get an error.

362
00:26:31,410 --> 00:26:35,760
So there exists a table called data in our database.

363
00:26:36,810 --> 00:26:42,300
And what I'm going to do now, I'm going to browse through my Web app as a visitor and I'm going to

364
00:26:42,300 --> 00:26:48,870
submit some data and then I'm going to apply the query again in here just to see if those data went

365
00:26:48,870 --> 00:26:49,200
through.

366
00:26:50,130 --> 00:26:55,140
Something to be aware of is, you know, you should add a semicolon after every sql query that you

367
00:26:55,140 --> 00:26:56,100
pass in here.

368
00:26:57,180 --> 00:27:05,490
So, no, I need to go back here and let's say Heroku open.
Just a fancy thing to open

369
00:27:05,490 --> 00:27:06,050
your web app.

370
00:27:06,800 --> 00:27:07,960
Mm hmm.

371
00:27:08,090 --> 00:27:08,550
Okay.

372
00:27:12,900 --> 00:27:13,680
Submit.

373
00:27:15,610 --> 00:27:19,670
Great, now we've got the success web page successfully.

374
00:27:20,340 --> 00:27:20,680
Mm hmm.

375
00:27:21,640 --> 00:27:22,350
Let's see now.

376
00:27:22,360 --> 00:27:28,330
Here, execute the sql query again.

377
00:27:29,210 --> 00:27:32,290
We've got one row which is great.

378
00:27:33,010 --> 00:27:36,510
But if you don't trust sql, then go on, check your e-mail.

379
00:27:36,670 --> 00:27:37,660
So,

380
00:27:37,690 --> 00:27:38,590
this is looking good.

381
00:27:39,410 --> 00:27:40,750
We have one people.

382
00:27:40,760 --> 00:27:43,720
Well, that doesn't sound very grammatically correct.

383
00:27:45,060 --> 00:27:47,170
So, you can...

384
00:27:47,230 --> 00:27:53,260
You can play around with that if you'd like to send the string person when you have less than one submission

385
00:27:53,290 --> 00:27:54,130
in your database.

386
00:27:54,490 --> 00:27:59,530
If you want to go that fancy. Yeah, this is working great.

387
00:28:02,090 --> 00:28:08,020
And if you want to play around with your application, you know you may want to use your email address

388
00:28:08,060 --> 00:28:09,400
to test your application.

389
00:28:10,030 --> 00:28:16,040
For that you'd have to delete your email address record from the database because, you know,

390
00:28:16,710 --> 00:28:22,150
now if you submit this again, you get this message.

391
00:28:23,500 --> 00:28:36,250
If you want to delete the record, you'd say delete from data where email_ with an on school equals

392
00:28:36,250 --> 00:28:37,990
to, single codes,

393
00:28:38,140 --> 00:28:40,840
and your email.

394
00:28:44,980 --> 00:28:45,820
Oh, I forgot

395
00:28:46,040 --> 00:28:46,690
the semicolumn.

396
00:28:47,770 --> 00:28:47,980
Great.

397
00:28:48,010 --> 00:28:52,460
Now we got the message to delete one if you apply select from data

398
00:28:52,480 --> 00:28:55,810
again you get zeros there and then you can start over again.

399
00:29:01,620 --> 00:29:02,580
So it's working.

400
00:29:04,190 --> 00:29:04,690
And yeah.

401
00:29:04,980 --> 00:29:06,210
I hope you enjoyed this.

402
00:29:06,310 --> 00:29:09,030
And I really hope things are working on your end.

403
00:29:09,450 --> 00:29:12,760
It's quite a lot of commands that you need to type in and execute there.

404
00:29:13,770 --> 00:29:15,180
And it's not easy to remember them.

405
00:29:15,840 --> 00:29:22,800
However, you have a list of all the commands of all the steps actually of that you need to deploy a

406
00:29:22,800 --> 00:29:28,580
Flask web application together with a PostgreSQL database, how to deploy that on Heroku.

407
00:29:29,350 --> 00:29:30,620
And yet that's about it.

408
00:29:31,020 --> 00:29:34,170
Thanks a lot for being a student of my course.

409
00:29:35,150 --> 00:29:38,330
I'll talk to you in the next lectures, see you.

