DEV Community

Cover image for It's modeling time
Sumit Roy
Sumit Roy

Posted on

It's modeling time

After all setup, we are in the stage of data modeling where I have to define the schema of the data I am going to use in my web app.

Features

  • Code Pasting using Code mirror
  • Making snippets private
  • Adding search page with a random snippet option

Upcoming features include starring someone's code snippet and adding a count of the number of views of that snippet.

These many features will require me to add several tables:-

  • One table to store users data
  • One for tags
  • And the last one for codes

Modeling

One basic rule you must follow is-

Never put same string data twice. Use relationship instead.

This means if you are using this table named 'cities_info'

id cities State
1 Chennai Tamil Nadu
2 Kanchipuram Tamil Nadu
3 Kolkata West Bengal

here 'Tamil Nadu' is coming twice which is not good for our database. Thus there should be another table storing all the states

id states
1 Tamil Nadu
2 West Bengal
3 Gujrat

and then a foreign key will be added in the table 'cities_info' instead of a State column. So the resulting table 'cities_info' will be

id cities state_id
1 Chennai 1
2 Kanchipuram 1
3 Kolkata 2

In this integers are repeating but that's not the problem. The problem is with repeating strings.

In my case, the tables and their relationship are as follows:-

I designed it using dbdesigner tool. It can be done by any other means also such as pony orm.

These tables satisfied all the functionalities of my web app like storing code snippets in the code table, the language in language table and tags in the tag table.

One interesting table is tag_code which is a perfect example of the basic rule I discussed earlier.

Next post, is going to be about hasura data API and postman collection for querying them.

Here is the index of all the post regarding this series of snipcode developemnt

Part I: App Idea
Part II: App prototype
Part III: Local Development
Part IV: G for Git
Part V: Data Modeling
Part VI: Data & Auth APIs
Part VII: Basic Functionalities
Part VIII: App Screen 1
Part IX: App Screen 2
Part X: App Screen 3
Part XI: User Reviews
Part X: Final Submission

Top comments (0)