DEV Community

dgloriaweb
dgloriaweb

Posted on

Planning and creating a database before you start working on your backend can save you time

In many cases we start developing an api endpoint or an application before we knew what our database will contain and how we are going to use the data.
We have to remember that the migration file has to be created, and later on the validation rules have to match the existing migration structure. Doing this while creating the controllers can result in a lot of back-and-forth between the database management and the actual controller/service coding of the endpoint.

My best solution for this is: create the tables in any table management tool, eg. excel or google sheets.
Add your mock data, that will show you if you have duplicates, which you can extract to a separate table and add the foreign key to your main table. (This will quickly show if your main table is the table you thought is the main, or it happens to be some other one. :) )

Once you have filled your tables with all the data your endpoint will need, you can add a new worksheet, where you define the column names, type, length, default values, nullable, regex or any other criteria you want to validate the incoming request against. This you can use later in your development as a quick reference.
This you can simply and quickly turn into a Laravel or any other migration code by using the =concatenate function, or create the sql INSERT code as well.
This, as mentioned above, will also give you the validation rules you have to add to your endpoint.

If you like this article and would like to learn more, write me in the comments below.

Top comments (0)