Deploying a PostgreSQL database on Heroku (Part 1)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone welcome back um i'm going to explain to you guys in this tutorial how to set up a postgres database on the heroku platform alright so we're going to go ahead and begin i'm gonna go over here to the url um i'll leave this in the description below you guys can register here confirm your email once all that's done let's go ahead and log in so once you log into your heroku account what we're going to take a look at is the following we start off with our dashboard so we're going to create a new project let's create a new app now the app names have to be unique guys so i'm just going to type in here pokemon 2017 27 662. all right now i'm just going to use a very basic example with the pokemon i'm just going to have a pokemon and a pokemon trainer just for the purposes of this video now here you can kind of see some of the functionalities that heroku offers you you can add a pipeline uh you can connect to github you can use the container registry all sorts of really cool things here so what we're going to focus on first is installing the heroku cli now to install this command line interface uh you will need to install brew i'll leave the link in the description below so we're going to copy this command and we'll paste it into our terminal all right now since i've already installed it on my machine it's just going to tell me that here it's going to show me the latest version all right once we've installed this it's basically going to unlock this command here this heroic command but which we'll use in a minute all right so now that we've done that let's go back and we're going to create the postgres database so head over to resources and we'll type in postgres and here we'll see the different plans now depending on your needs there's uh different plans available the standard all the way to a 16 000 a month plan for big enterprise applications we'll focus on the hobby dev which is free now once we submit the form and open the database it's going to show us what we can do and what are the basic limitations of the database all right let's wait for this to configure yeah so here is provisioning our database and we'll take a look at the utilization restrictions we're allowed up to 20 connections which is pretty decent for a small project um we're also allowed 10 000 rows of storage which is more than enough for what we need for the courses at the university and that's pretty much it so let's go ahead and begin by looking at the settings and checking the database credentials now here we have information relating to the host the database the username the port that the database is on the password and some other information here all right now just to uh be able to create our database we need this information so i'm going to go over here to our terminal and i'm going to type in this information below we have uh what do you have this instruction from a previous example i'm just going to copy this and we're going to edit this into a text editor alright so the first thing we're going to do is replace the host here with the host for our particular database the port remains the same the username will change let's copy this and this just basically tells us that we'll be we're going to be providing a password once the database has been logged into so we're going to select the database name and that's it all right so i'm going to copy this instruction this command and i'll type it in here copy and paste now here it's gonna ask us to type in our password so we're gonna copy this and paste it oh oops there must have been something wrong here maybe i didn't copy the database name right let's go ahead put that today okay let's try this again i'm gonna copy the password there we go so here uh we have we've already logged in to the database all right so if you type in backslash dt it'll show us the list of relations and since we don't have any at the moment it's going to show up as blank all right guys so now that we've taken a look at how to enter the database we're going to create a schema so i'm going to open up a new terminal all right and let's open up the document so let's go to our desktop and it's going to be named pokemon.skill now you can use any text editor i just prefer to use sublime text all right guys so here we're going to just have i'm going to create two tables all right so our first one's just going to be to create a trainer all right let me make this a little smaller all right so we'll have here create table i'll name this a trainer and we're going to give it some attributes so a trainer is going to have a trainer id which will be numeric which is the standard for postgres all right he's also going to have a name which we'll designate by varchar and inside we'll put the number of bytes and we'll we could also say he has some badges all right that's going to be numeric as well and we're going to give it a primary key so we'll name this trainer pk and the primary key for the trainer will just be his id all right now once we have this we're going to create uh another table for our pokemon so create pokemon all right let's do the same thing we did earlier and we'll give it the pokemon some attributes as well the pokemon has an id according to his entry in the pokedex um he also has a name let's give that varchar and he also has a trainer which is asso which is associated to the particular pokemon we'll take a look at this in a minute all right and we'll make our constraint the primary key all right so we're going to have here primary key and it's going to be the id of the pokemon all right now we will have to alter this table just to provide some unique constraints all right so let's alter this table and we'll add a constraint so that the pokemon has a unique name okay so this is going to be unique name all right well we'll also need to add another constraint to provide the foreign key of the trainer all right so we'll have alter table we'll article the pokemon table i'm going to add a constraint okay pokemon trainer and this is going to be a foreign key to the trainer attribute in my pokemon class and it's going to reference my trainer oh this is ref references the id of a trainer all right so here we created a table with a trainer we've also um created a pokemon table which has id name and trainer and we all we added one constraint for the pokemon and we added a foreign key to the trainer all right let's go ahead and save this all right and when we come back um we're going to type in this instruction now what this does is uh it basically connects to our application which we named as this and it's gonna execute this sql um script all right there we go so now if we come back here and we type in slash dt we see the two tables have been created now if we want to take a look the and make sure that our constraints are in place we'll type in backslash t plus the name of the table and we see here that uh the primary key is the id of this pokemon and it has a unique constraint for the name of the pokemon and it has a foreign key constraint for you know referencing the trainer id now if we do the same thing for the trainer we'll see that he has he's referenced by the pokemon table in which the id of the trainer is the foreign key of the table so everything looks good so far so now what we can do is come back over here to firefox and we're gonna go to data clips now data eclipse is kind of like a it's a way to see your data it won't let us do any inserts but we can do select pretty much most queries to the database that exists so let's create a data clip um there we go i'll just call this query let's just say here select from a trainer there's nothing there but this is just so that we can uh save our data clip we're going to give it a name we'll just call this test and we'll save and run this query and it returned our results since we haven't put anything in yet now here we can see our table with our different values and that's pretty much it all right so let's in the next video uh so that this isn't too long in part two we're gonna do some inserts we're gonna do some queries and then i'll show you guys how to install data grip to make the access to the heroku database a little bit more efficient all right so i'll see you guys in the next video
Info
Channel: CodeHive
Views: 6,149
Rating: 4.8928571 out of 5
Keywords: heroku, postgres, deploy, heroku postgres
Id: 80oty2v4HsE
Channel Id: undefined
Length: 10min 47sec (647 seconds)
Published: Fri Mar 12 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.