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.

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

đź‘‹ Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay