So before we can start working with the data we now have available to us, we obviously need to set
up some models and I'm looking at models that go right now and I can see we have one for widgets and
we need more.
So let's go look at our database.
Back over to your favorite, my Esquibel client.
And we have an orders table.
And if we look at the structure of that, these are the fields that we need to add.
So ID, widget ID and transaction ID are all ints.
Let's add one for orders, so I'll create a new model which I'll call type order.
It's a struct and it has an ID, which is an int.
It has a let's go back here widget Odean transaction ID and status widget ID, which is an Int transaction
ID, which is an ID status ID, which is an ID.
Let's go back and see what else is there.
Quantity and amount are both in quantity int amount int and that it has created an update that I'll
just copy these two.
OK, and let's format this and the adjacent fields so I can copy this one.
And then for Wichita, we want Wichita ID and for transaction ID, we want transaction transactionally,
status ID,
quantity
and amount
for Mathis.
OK, so there's order.
Let's give it a comment.
Is the time for all orders.
OK, so that gives us order.
Let's get the next one that we don't need to do schema migration because that's handled by SOTA statuses
and that just has ID name and created out and updated.
So let's copy this.
And change in
status, so it had its name created and updated that name, which is a string we'll call that name and
created an updated that are right there.
So we'll just delete this format it give it its comment.
Status is the type or statuses
and what's next transaction statuses.
And that's virtually identical.
So let's copy that one.
So status is for order, stew's.
And transaction status
is a type for transaction statuses, and I'll put orders up here to make this clear.
And this is called transaction status.
So paystub, that gives us transaction status.
Next is transactions.
And there's a few more in there ID amount currency in the last four.
So let's copy this.
And this is called transaction singular.
Transactions, we'll just fix this comment, so we had I.D. then we had amount currency in the last
four amount, which is in it.
We'll call this amount
then currency, which is a string and that's called currency
last for which is a string and last underscore for what else we have.
Bank return code, which is a string of duplicate that.
Thank return code, thank return.
Code, then transaction status I.D., which is an entry and I'll just call this transaction status I.D.,
which is in it to make this transaction status I.D. format this OK.
And after that, we have created an updated.
So that's it for that one then.
We have users already, first name, last name, email.
So let's just copy this.
And call it user
type for users.
So first thing,
which is a strength.
First name, last name, and this will be the last name, and this will be emailed
and emailed and what's next?
Password creator updated us.
So we just need this, we can delete this one.
This will be password and this will be password format.
Do we have any more widgets?
We already have widgets.
OK, so now we have some models.
But when I look at my widget type, which was here when we started this whole exercise, there seems
to be one thing missing and the one thing missing is actually the image, because if we look at a widget,
we have a picture.
So we probably should add a column to this.
Now, I can add it right here in the type I could say image, which is just a string with a path to
the image.
And I call that Jason image and format it.
We actually need to add it to our database.
And this is where soda comes in.
Very helpful.
Now you'll notice, but I've already copied the migration's we used in the last lesson into a folder
at the root level of my application called Migration's, and there they all are.
Those are the ones that we just ran in the previous lecture.
And I also have my database dot amount right here and it has my username and password as it should,
and that's also at the root level of my application.
Now I can actually open my terminal now and I'm in the correct folder.
I'm at the root level of my application.
As you can see here, there's all the files at the root level, including database, dot y, AML and
I can type SOTA generate fears and image to widgets.
So SOTA is the command.
Obviously generate is going to create an up and down migration.
Fiz is the format I want to put them in and it's the migration.
I'm just going to call it whatever I want, but I'm going to call it something that's meaningful.
I want to add an image column to the widgets table.
So I called my migration add image to widgets and I return and it creates two new files right here up
and down.
Now, if I go back to my Web browser and again look at the sort of documentation, I'm going to go right
down here to fizz and click on that and say, how do I add a column right here?
And if I click that, the syntax is as simple as this.
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
right one.
It ends in up dot fears and I'll paste that in there and change it.
I want to add a column to widgets.
I want to call the column image.
It will be a string and I'll put a default in there
of an empty string.
OK, and now I want the down migration.
So let's open that file and go back to our documentation.
And how do I drop a column.
It's right there.
Drop a column.
So I'll copy this.
Go back to my EDEK, paste that into the down migration which is right here.
Add image to widget, start down phase and I'm from the widgets table.
I want to drop the column which I just added called Image.
So those are both been done and I've saved them both.
So I'll clear the screen in my terminal.
So now if I'm in the correct directory and I am, then I should be able to run.
So to my great.
And it should have added the file or the column image to widgets.
So let's go back to our database and make sure and if I look at the widgets table and look at the structure,
there it is.
So I have an image column added to this.
Now, right now, we don't actually have any value for our current widget image.
So we can actually add that.
And what I can do is, simply put, the name of the image in there.
And it's just widget PMG.
OK.
And that gets our data up to date.
So now we have our necessary models.
And the next step, of course, is to start writing some functions to update this one, get get one
widget or get widget by ID and get the correct columns from the database and we'll have to do one four
transactions and one for all widgets and something to modify them, something to delete them.
This is all very straightforward and we'll get started on that in the next lesson.