#9 Introduction to PostgreSQL: Database Migration
Transcript
English (Auto-generated)
Hello everyone today we will learn how to migrate our tables from our face code editor into your terminal. So it mimics more like the real life, how we would write our SQL tables inquiries. So let's go ahead and take a look at our E. R. D. Diagram. So E. R. D diagrams or entity relationship diagrams. But that is a whole new course that we're not gonna go through. We're just basically gonna take a look at this and see what information we have to input in Rvs code create these tables and migrate these data into our database. So as you can see here at the top at the notes our table names. So we have a table called cohorts and a table called students. We also have something called primary key and foreign key but we're not gonna go into details with those. We have four calm names in the cohorts called I. D. Names start and end. And a bunch more column table names for our students. However to save time I have already created the students table but we will create the cohorts table together. So I guess let's put rvs code side by side with the cohorts and we will take great table cohorts remember the open end bracket and have this type of semicolon at the end or else the file won't finish executing because I didn't see a semicolon which notes that that's the end of the sentence. So we have a I. D. And it's an integer. And they specifically said we don't want it to be known. So I'll get this typed serial primary key. Not milk. Because when you type serial primary key, it's smart enough to know that it's an in ginger and it will auto increment for you. But we do have the note. Not noel by ourselves to make sure that this value cannot be empty or no. Next we have a name. So the name. Remember the name is usually a string. So we used our car give it to 55 in case we have a really really long name. We can also take a knoll here. We want because it wouldn't make sense if we have an empty name and cohort. We have a start date. We'll just call it a date and you can use other date formats. But for me I'm just gonna use the normal date formats. So command s to save this fall and we will move into our terminal. So let's full screen this and pop this back out. We're gonna go to our terminals in our terminal. You can see that we're already in the postgres underscore demo folder as denoted here. And then now we're gonna log into our postgres user. So we're gonna still be using cuts one user to log in. We're gonna use the same database database privilege as you can see I spelled something wrong. Oh no, you're connected. So never mind. I successfully connected. That looks like an error message for a second. And we will type backslash G. T. To see how many tables we have. So currently in our database test database privilege, we only have one table. And it's called pets that I created several videos ago. But now we want to add two more table which is the students table and cohorts table. So this is the syntax to import these table files into our database. We're gonna have a backslash I. Space and then we will use the folder name. So migrations and now slash because we're no migration folder. And now we'll look for a file called students underscore cohorts SQL and click enter. And it will say that relation cohorts does not exist. So maybe I did not save this properly, that's why I didn't register my table. So let's try this again. Um Now it will say that it created the uh 2nd table. It says already exists because for the second time my cohorts table is being created. So let's make sure that both our students and cohorts table are now here. So as you can see our students in cohorts table are successfully created. And to make sure that it works we can try taking select star from students. But as you can see we have all the column names here and we don't have any roles yet because we did not insert any data into tables. So let's try this for cohort. So to make sure we have the cohorts table, right? And as you remember we only imported for table columns. So I. D. Name started an end date. So as you can see, we were successfully able to migrate our table into our database. Mhm.