Use database migration utilities in Adonis to its complete potential. Carry out incremental updates - may it be a new table, or changes to existing table using distinct migration files that are version controlled.
You have a beautiful Todo application that has a
todos table with the following columns:
Now, let’s say our users ask for a new field called
Your first instinct may be to add the column to the database, change controller code if required, and call it a day. But, what if you to start making changes at different times to -
- create a related entity called
todo sub-itemson 3-Jan
remarkscolumn on 15-Jan
- add pre-default value to
The point is that there may be tens or hundreds of changes to be deployed to your target environment. It is quite easy to get lost in the details and not track all the changes that needs to be done in a higher environment.
That’s where Adonis migration files save significant effort and time, and make the whole migration process efficient.
In the above example of
todos table: the first migration file will look like this -
When the changes start pouring in, you don’t make changes in the database or in the same file. Instead you create a new file -
I have not provided anything in
down method but you could potentially drop newly created columns in the same file.
Apply changes to the database in dev/higher environments -
Repeat the process for other fields as changes come through.
There are several advantages in following this process -
- Complete clarity on schema changes to the entire development team
- Catch all changes to the schema. All files are version controlled
- Apply or rollback changes with ease. Everything is controlled through code