Simplifying Development: Moving from a Multi-Database to a Single-Database Setup

The Original Setup: Two Databases

Initially, I used two PostgreSQL databases: one for calories data and another for users data. Here’s how I configured them with Sequelize:


I avoided foreign keys across databases and planned to handle relationships in the application code. However, this setup quickly became cumbersome for my small project in the sense that without foreign keys, I had to manually handle relationships, slowing down development.

The Switch: A Single Database

I consolidated into a single database for simplicity. Here’s the updated configuration:



I migrated both users and calories tables into the calorie-app database, added foreign keys, and updated my Sequelize models to use associations.

Benefits of the Transition

  • Faster Development: Foreign keys and Sequelize associations simplified my code.
  • Simpler Queries: I could use JOINs for efficient data retrieval.

Trade-Offs

A single database might limit scalability in the future, but for my small user base, this isn’t a concern yet. It also introduces a single point of failure, which I mitigate with backups.



Comments

Popular posts from this blog

@ModelAttribute vs @RequestBody in Validation

Side Project(a self-imposed 3-day "Hackathon" challenge)

Google: The King is Back