WEBVTT 00:01.710 --> 00:06.090 So before we can start working with the data we now have available to us, we obviously need to set 00:06.090 --> 00:11.850 up some models and I'm looking at models that go right now and I can see we have one for widgets and 00:11.850 --> 00:12.390 we need more. 00:12.810 --> 00:14.190 So let's go look at our database. 00:14.220 --> 00:16.560 Back over to your favorite, my Esquibel client. 00:16.950 --> 00:18.540 And we have an orders table. 00:18.540 --> 00:22.650 And if we look at the structure of that, these are the fields that we need to add. 00:22.650 --> 00:26.170 So ID, widget ID and transaction ID are all ints. 00:26.340 --> 00:32.610 Let's add one for orders, so I'll create a new model which I'll call type order. 00:33.150 --> 00:36.900 It's a struct and it has an ID, which is an int. 00:38.460 --> 00:48.840 It has a let's go back here widget Odean transaction ID and status widget ID, which is an Int transaction 00:48.870 --> 00:53.820 ID, which is an ID status ID, which is an ID. 00:54.390 --> 00:55.860 Let's go back and see what else is there. 00:58.750 --> 01:10.000 Quantity and amount are both in quantity int amount int and that it has created an update that I'll 01:10.000 --> 01:11.020 just copy these two. 01:13.990 --> 01:19.810 OK, and let's format this and the adjacent fields so I can copy this one. 01:22.790 --> 01:31.880 And then for Wichita, we want Wichita ID and for transaction ID, we want transaction transactionally, 01:34.970 --> 01:36.140 status ID, 01:39.650 --> 01:40.520 quantity 01:45.440 --> 01:46.100 and amount 01:50.310 --> 01:51.340 for Mathis. 01:51.890 --> 01:53.000 OK, so there's order. 01:53.040 --> 01:54.050 Let's give it a comment. 01:57.740 --> 02:00.380 Is the time for all orders. 02:02.900 --> 02:04.340 OK, so that gives us order. 02:04.350 --> 02:11.630 Let's get the next one that we don't need to do schema migration because that's handled by SOTA statuses 02:12.290 --> 02:15.320 and that just has ID name and created out and updated. 02:15.620 --> 02:16.610 So let's copy this. 02:18.110 --> 02:18.680 And change in 02:22.340 --> 02:35.390 status, so it had its name created and updated that name, which is a string we'll call that name and 02:35.390 --> 02:37.370 created an updated that are right there. 02:37.380 --> 02:41.900 So we'll just delete this format it give it its comment. 02:44.420 --> 02:47.180 Status is the type or statuses 02:49.730 --> 02:52.830 and what's next transaction statuses. 02:52.850 --> 02:54.520 And that's virtually identical. 02:54.530 --> 02:55.670 So let's copy that one. 02:58.340 --> 03:00.230 So status is for order, stew's. 03:02.490 --> 03:04.020 And transaction status 03:06.780 --> 03:13.380 is a type for transaction statuses, and I'll put orders up here to make this clear. 03:15.600 --> 03:17.670 And this is called transaction status. 03:17.940 --> 03:21.780 So paystub, that gives us transaction status. 03:21.790 --> 03:23.250 Next is transactions. 03:23.610 --> 03:26.950 And there's a few more in there ID amount currency in the last four. 03:26.970 --> 03:27.960 So let's copy this. 03:31.770 --> 03:34.110 And this is called transaction singular. 03:41.230 --> 03:48.280 Transactions, we'll just fix this comment, so we had I.D. then we had amount currency in the last 03:48.320 --> 03:54.620 four amount, which is in it. 03:56.350 --> 03:57.370 We'll call this amount 04:02.830 --> 04:09.790 then currency, which is a string and that's called currency 04:13.960 --> 04:24.610 last for which is a string and last underscore for what else we have. 04:26.570 --> 04:30.980 Bank return code, which is a string of duplicate that. 04:32.930 --> 04:39.150 Thank return code, thank return. 04:39.680 --> 04:50.570 Code, then transaction status I.D., which is an entry and I'll just call this transaction status I.D., 04:51.680 --> 04:59.870 which is in it to make this transaction status I.D. format this OK. 05:00.740 --> 05:02.520 And after that, we have created an updated. 05:02.660 --> 05:03.860 So that's it for that one then. 05:03.860 --> 05:07.150 We have users already, first name, last name, email. 05:08.450 --> 05:09.980 So let's just copy this. 05:13.510 --> 05:14.500 And call it user 05:19.570 --> 05:20.750 type for users. 05:23.470 --> 05:24.430 So first thing, 05:28.540 --> 05:29.380 which is a strength. 05:34.190 --> 05:44.270 First name, last name, and this will be the last name, and this will be emailed 05:48.530 --> 05:52.850 and emailed and what's next? 05:55.600 --> 05:57.260 Password creator updated us. 05:57.400 --> 06:01.210 So we just need this, we can delete this one. 06:02.680 --> 06:09.700 This will be password and this will be password format. 06:10.420 --> 06:12.790 Do we have any more widgets? 06:12.790 --> 06:13.760 We already have widgets. 06:14.290 --> 06:16.090 OK, so now we have some models. 06:16.570 --> 06:23.260 But when I look at my widget type, which was here when we started this whole exercise, there seems 06:23.260 --> 06:28.540 to be one thing missing and the one thing missing is actually the image, because if we look at a widget, 06:28.540 --> 06:29.350 we have a picture. 06:29.350 --> 06:32.840 So we probably should add a column to this. 06:32.860 --> 06:39.580 Now, I can add it right here in the type I could say image, which is just a string with a path to 06:39.580 --> 06:40.060 the image. 06:40.060 --> 06:43.150 And I call that Jason image and format it. 06:43.750 --> 06:45.490 We actually need to add it to our database. 06:45.520 --> 06:47.230 And this is where soda comes in. 06:47.230 --> 06:48.040 Very helpful. 06:48.490 --> 06:54.490 Now you'll notice, but I've already copied the migration's we used in the last lesson into a folder 06:54.490 --> 06:59.020 at the root level of my application called Migration's, and there they all are. 06:59.020 --> 07:01.630 Those are the ones that we just ran in the previous lecture. 07:02.350 --> 07:08.910 And I also have my database dot amount right here and it has my username and password as it should, 07:09.340 --> 07:11.840 and that's also at the root level of my application. 07:11.950 --> 07:16.330 Now I can actually open my terminal now and I'm in the correct folder. 07:16.330 --> 07:17.800 I'm at the root level of my application. 07:17.800 --> 07:23.050 As you can see here, there's all the files at the root level, including database, dot y, AML and 07:23.050 --> 07:30.130 I can type SOTA generate fears and image to widgets. 07:30.700 --> 07:32.230 So SOTA is the command. 07:32.230 --> 07:36.040 Obviously generate is going to create an up and down migration. 07:36.430 --> 07:41.110 Fiz is the format I want to put them in and it's the migration. 07:41.110 --> 07:44.350 I'm just going to call it whatever I want, but I'm going to call it something that's meaningful. 07:44.620 --> 07:47.110 I want to add an image column to the widgets table. 07:47.110 --> 07:53.980 So I called my migration add image to widgets and I return and it creates two new files right here up 07:53.980 --> 07:54.760 and down. 07:55.480 --> 08:02.080 Now, if I go back to my Web browser and again look at the sort of documentation, I'm going to go right 08:02.080 --> 08:07.480 down here to fizz and click on that and say, how do I add a column right here? 08:08.320 --> 08:10.720 And if I click that, the syntax is as simple as this. 08:10.810 --> 08:18.760 So I'll copy this and I'll go back to my ID and I'll open the up migration and make sure you get the 08:18.760 --> 08:19.180 right one. 08:19.180 --> 08:23.680 It ends in up dot fears and I'll paste that in there and change it. 08:24.370 --> 08:26.080 I want to add a column to widgets. 08:26.920 --> 08:29.670 I want to call the column image. 08:30.520 --> 08:34.150 It will be a string and I'll put a default in there 08:37.450 --> 08:38.230 of an empty string. 08:38.690 --> 08:41.370 OK, and now I want the down migration. 08:41.380 --> 08:43.930 So let's open that file and go back to our documentation. 08:45.370 --> 08:46.990 And how do I drop a column. 08:47.020 --> 08:47.610 It's right there. 08:47.620 --> 08:48.390 Drop a column. 08:48.400 --> 08:49.540 So I'll copy this. 08:50.650 --> 08:56.320 Go back to my EDEK, paste that into the down migration which is right here. 08:56.470 --> 09:01.570 Add image to widget, start down phase and I'm from the widgets table. 09:03.250 --> 09:06.310 I want to drop the column which I just added called Image. 09:07.690 --> 09:10.390 So those are both been done and I've saved them both. 09:10.390 --> 09:11.900 So I'll clear the screen in my terminal. 09:12.250 --> 09:16.480 So now if I'm in the correct directory and I am, then I should be able to run. 09:16.480 --> 09:17.890 So to my great. 09:19.800 --> 09:24.240 And it should have added the file or the column image to widgets. 09:24.360 --> 09:31.440 So let's go back to our database and make sure and if I look at the widgets table and look at the structure, 09:32.370 --> 09:32.930 there it is. 09:33.360 --> 09:35.990 So I have an image column added to this. 09:36.000 --> 09:41.460 Now, right now, we don't actually have any value for our current widget image. 09:41.850 --> 09:43.230 So we can actually add that. 09:43.320 --> 09:46.680 And what I can do is, simply put, the name of the image in there. 09:47.100 --> 09:50.690 And it's just widget PMG. 09:51.120 --> 09:51.530 OK. 09:52.620 --> 09:54.870 And that gets our data up to date. 09:55.770 --> 09:58.830 So now we have our necessary models. 09:58.830 --> 10:04.650 And the next step, of course, is to start writing some functions to update this one, get get one 10:04.650 --> 10:10.860 widget or get widget by ID and get the correct columns from the database and we'll have to do one four 10:10.860 --> 10:15.870 transactions and one for all widgets and something to modify them, something to delete them. 10:16.590 --> 10:20.330 This is all very straightforward and we'll get started on that in the next lesson.