Migration Structure
This is the file that is created when you run the command:
Every time you perform a migration, you must also declare the SQL statement that can reverse what you did.
To do so, we use the following methods:
Up method: This method executes the SQL statements by running the command:
Down method: This method executes the SQL statements to reverse the actions of the up method.
This method is executed with the command:
To create an SQL statement, you need to include this code in the up and down method.
Example 1 - Create Table
If you are using or will use SoftDelete, remember to include in your migration the field deleted_at
with TIMESTAMP
type.
Example 2 - Alter Table
Remember to make the correct SQL statement to revert the changes you make with the up method.
Other examples
If you pass a field type A to type B, in the down method you must pass the field from type B to Type A (initial data type).
If you create a table Z, in the down method you must delete the table Z.
If you add a field A to a table Z, in the down method you must delete the field A in table Z.
If you add an index A to a table Z, in the down method you must remove the index A from table Z.
If you create a new table in the database or add a new field to a table, you need to create an .entity.ts file or add the field to the entity you modify.
Last updated