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.

Imagine monitoring actually built for developers

Billboard image

Join Vercel, CrowdStrike, and thousands of other teams that trust Checkly to streamline monitor creation and configuration with Monitoring as Code.

Start Monitoring

Top comments (0)

Billboard image

Try REST API Generation for MS SQL Server.

DreamFactory generates live REST APIs from database schemas with standardized endpoints for tables, views, and procedures in OpenAPI format. We support on-prem deployment with firewall security and include RBAC for secure, granular security controls.

See more!

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay