Help needed: pulling my hair on database structure :-(

Hello all, I’m new to Bubble but I read both the Bubble manual and the Airdev Canvas manual as well as did all the lessons and looked at the tutorials but I’m still pulling my hair at how to structure the database for my use case, at a high level :frowning:

I think my biggest problem is to conceptualize how to structure the DB when there is a master list of tasks that every new user is assigned and has to do in a particular order and check off daily. It’s different from users creating their own tasks to complete, which maps to the classical To-do app use case.

All the use cases I have seen (To-do, marketplace, etc.) involve items belonging to users so it’s quite simple to just retrieve and display the things that “belong” to each user and each user only. What I’m trying to do is take the same list of tasks and have each user do them according to a specific schedule and record how they progress. Somehow, I can’t come up with a suitable DB structure for that.

My use case is a training plan to get users to implement a new habit per week by doing it daily. If they manage to do it daily for a week, then they get a new habit for the following to do in addition to the first habit which still has to be done.

There is the same training plan for everyone, for example the Covid inspired plan below:

  • Habit 1: Wash your hands
  • Habit 2: Wear a mask
  • Habit 3: sneeze in your elbow

And the schedule is:
Week 1: complete Habit 1 each day (check a box to indicate you did it). If at the end of week 1, you did it everyday, then Week 2 is unlocked. If not, you start again with Week 1.

Week 2: same but you have both Habit 1 and Habit 2 to complete each day.

Week 3: same but you have Habit 1, 2 and 3 to complete each day.

Users only have a personal dashboard with the Habit to complete each day and they can indicate if they did it for the day.

It seems simple enough to me but when I try to think how to structure the DB for such an application, I’m going in circles as it doesn’t really map to any of the other use cases I have seen in the tutorials :frowning:

I think where I struggle conceptually is that contrary to a more classical to-do app where I could create and retrieve To-dos easily based on the user who created them, here each user essentially has to complete the same set of daily tasks, in the same order, but at different dates based on when they sign up. I’m wondering how to best assign these tasks to users and record if/when they complete them.

The best I came up with are the following data types:

  • Habit:
    • Label field with name
    • Habit ID
  • Week:
    • Week ID
    • List of Habits in the week
  • Habits done:
    • Habit unique ID
    • Date done
    • User ID
    • Active week:
  • User:
    • Active week
    • Week 1 start date
    • Week 2 expected finished date
    • Week 2 start date
    • Week 2 expected finished date
    • etc.

I would then restrict the number of times a user can mark a habit done to once a day and then count the number of times a habit has been done in the week to mark each week complete.

This isn’t simple though and I’m wondering if I’m approaching the issue in the right way :frowning: It seems like since I know the exact tasks a user has to complete when they sign up, I should be able to have a simpler structure.

On the other hand, if I were to, say, assign a user a task with a due date for each daily habit, then I would end up with 7+14+21=42 individual tasks to be completed and that is just for 3 weeks…

If anyone has taken the time to read until this point and has any pointers on what I could read to get better and see what I am missing, I would be immensely grateful!

Many thanks!

Hi there! Welcome to Bubble!

Trying to structure databases can be challenging at times when building a new app. I’d suggest taking a look at Emil Drkusic’s examples on Vertabelo - he’s created pages of example data models to help you visualise and plan your own database! I remember getting the link somewhere on Bubble (credits to them)

Something that also definitely helped me while building my platform (still in progress) is understanding the user flow on each page so that you can fully map out all the fields required.

Hope this helps!

1 Like

Thanks a lot for your reply!

I already mapped all the user flows (which in this simplified model of the app isn’t much as they just mark habits done each day or do nothing if they haven’t done them).

And I also spent time on the Vertabelo website and blog reading up on model examples as I saw that referenced in another post in this forum when searching for more info.

Not sure why I don’t seem to be able to get my head around the general idea of what I need :frowning:

Not sure if this helps but maybe could try:

  • Habits (since you only have one task that repeats for the week):
    • Week (integer)
    • Habit (List of text - e.g. Week 1 = Wash your hands, Week 2 = Wash your hands; Wear a mask, Week 3 = Wash your hands, Wear a mask, Sneeze in your elbow)
  • Progress (a way to track each user)
    • Week (integer - which week is the user on )
    • Habit (integer - how many habits have the user competed for the current week - add a workflow step that only triggers when this is at 7 to +1 to the week when the user marks it as complete)
    • Current week (the date the current week starts - again can be added through a workflow when the user clicks on “Done” and under the condition that habit = 0, -> Habit + 1)
    • User (link with ID or email)
  • User

You could look at creating a different workflow for each day of the week

Apologies if this isn’t that clear - just jotting down quickly aha

Just quick shout out for posting your problem so clearly. I do want to see how your implementation is solved.
Hang in there ! :grin:
(Maybe take a day off if you are struggling with it too many hours in a row)

and how is that a problem ? is it because you have to create manually on bubble interphase the 42 tasks ? If that is the case then i think your model is wrong here, in effect you SHOULD NOT loop manually and that should be provided by a backend function
function (newUserid,createDate,weeks in advance) => all tasks creations for that new user schedulled by created date limited by weeks

ubble is very open-ended. That said, there are some limits to what the core language can do. Bubble’s language is comparable in power to spreadsheet formulas: you can do a lot, but anything requiring recursive or looping operations on data (such as, for instance, writing a custom machine-learning algorithm) would be difficult. The good news is that Bubble is fully extensible via Javascript plugins. You can create your own plugins to add connections to non-supported services, add elements written in Javascript or write server code (see Building Bubble Plugins). The Bubble model is to write the core website functionality using our visual language, and plug in Javascript to handle algorithms that are harder to build in Bubble.


You might need to look for external help as in plugin help Thanks a lot for taking the time to think about this and to post a potential structure!

The Progress data type is certainly very interesting and I will have a think as to how this might solve the issue. It’s late here and I need to look at this with a clear mind in the morning :slight_smile: Thank you for saying this and yes, I have been obsessing about this for the past 3 days (long weekend here) as I am eager to start work on this prototype but need to think the DB structure through before! A break might be indicated :slight_smile:

The main issue why I flagged creating the tasks all at once as a problem is that if the user doesn’t complete the Habits assigned daily, then I want to be able to re-assign the week to him/her. If all the tasks are already created, then this might involve shifting all the dates “due”.

1 Like

Friendly bump to get new eyes on this, if possible :smiley: