Data Modeling

Hariharan M
4 min readJul 24, 2017

--

The Building block of Ideas

This crucial step is imperative to ferry us across ignorant waters. We might want to structurize and froth a visual image of our app.

Let’s unwind the past a bit.

Now for the cover story,

The Catch is to make Postgres work for us.

PonyORM is an object-relational mapper

PonyORM makes it easy for you to create a database in Python, perceive relations as objects, fields as attributes and also supports ER to Relational Schema mapping.

I’ve used PonyORM with custom tools to build this Schema.

Here, I literally open up ‘Objective’ Ideas that define my app’s DB integrity.

Auth Rules

Hasura Auth does the Session Management for me.
All you need for an user is to supply these simple fields, for an identity crosscheck.
You get to look at every user for ID credentials, like mobile, username, email and the hasura_id.

I should credit Hasura for a Session Store, or the Middleware that tracks user sessions across devices. Cool eh.

My User Tweak with DB is to set up a dedicated Table to hold Deeper user info.

As mine is a Social Media cum Song App, say, you may want to know the user’s passion with music and credibility on a music stream of his choice.

Say, I’m a Pop Singer/ fan and my experience with Pop concerts have deep childhood bonds. I’ve never missed an one-time radio show on R-City that features the best Pop of the week.

So, the user may want to put this up, but he is nobody until he identifies himself with his bunch. That’s why, I’ve a field for his Profile name, Place of work, City and a short 2 line description, for people to connect with.

Working in Sync with Auth

So every user is obviously asked for an username/mobile Sign In and the corresponding hasura_id is mapped with id from the User table, so that I can render the right user with right feeds.

Note: I don’t want fake accounts, so I’ve a mobile verification with MSG91 setup.

Friends Matter

An Integral Part of Song Sharing is getting to know new people and expose your routine to a multi-color environment. I believe that friends can make a difference in our life with everything we do, positively :)

There’s a Friend Table that stores the user_id of the one who first sends a request and the friend_id is the one to whom the request is intended.

By default, a record insert into friend is taken for an invite, so request is set to true. Confirm is updated only when the other guy confirms the request.

But how do I find my friends, the people to whom I can send out invites and guys who have sent for me?

A view solves the trouble. For a given user_id, a friend is one who either sends a request or confirms an invite. I’ve checked for both the cases where this happens.
You can invite people who aren’t your friends and to whom you have neither sent any requests before nor received any.
Confirm is pretty easy for a logic. You select from friend, people you have not confirmed.

App Goals Visited

This is a Song App right? So where are the songs?

I plan to utilize the filestore DB running on the local cluster into saving songs. And the Relational Schema into mapping users with the song ids.

User is prompted with some details on the song.

The Ultimate Destiny of Social Media

If you can’t comment on your friend’s song or tag them or even like some, it’s no different from streaming songs from your local device in solitude.

There are no strangers here and nobody is striped from raising opinions. That calls for a new entities.

You like a song.
You comment on a song.

And the statistics with number of likes and comments is dangling. Let’s fix that with views.

A simple aggregation.
A comment aggregation.
I create an abstract entity — comments with songs
I add likes in the mix

So now every song tab has got this,

Cool ah!

Conclusion

If I were to join the tables for invites and confirms, that would place a heavy resource overhead on the UI thread, but a Data Model Design has solved my crisis.

They sure are omnipotent :)

Moral of the story is,

It’s a standout procedure to plan anything before doing

Stay tuned for more :)

--

--