Database Design - ChrispyPeaches/FocusFriends GitHub Wiki

Schema

Overall Architecture

Database Schema Architecture drawio

Base

EER Diagram

BaseSchema drawio

Components

Users

  • After a person signs up to the app, they will have a "user" created on the cloud database
  • User is basically the heart of DB where most FKs point to

image

Pets

  • Local DB component of every pet within the app

image

Badges

  • Local DB component of every badge within the app

image

UserPets

  • Cloud DB component that records which pets the user owns

image

UserBadges

  • Cloud DB component that records which badges the user owns

image

UserSessionHistory

  • Cloud DB component that records whenever the user starts another "Focus Session"

image

Friendship

  • There is 1 entry per user-friend relationship.

  • So say we have two users. One is the inviter, the other is the invitee.

  • The inviter will always be in the UserId column and the invitee will always be in the friendid column.

  • Then the status denotes whether or not the invitee has accepted the request

image

FocusAPI

Same as base

FocusApp

Difference from Base Schema

  1. DateTimeOffsets are not supported by SQLite, so columns representing this datatype are stored as UTC date times in string format as this is Microsoft's recommendation when working with Entity Framework.
  2. Guids are not supported by SQLite, so columns representing this datatype are stored as strings
  3. String maxlength limits are not supported by SQLite, so it is enforced by Entity Framework

Technical Design

Shared Schema

For shared database schema between the FocusApp and FocusAPI, base models are defined inside of FocusCore that define the shared attributes of the models' properties and tables.

These base models define tables, their columns, their relationships to other tables, and all other database design information shared by both projects. This is done using Entity Framework Core mapping attributes, (documentation about how to use these can be found here).

To change a child model for a specific project, you can:

  • Add properties.
  • Modify existing properties
    • To modify a property of a child class, add the new modifier to the property and it will hide the base property.
      • Example: changing the datatype of the DateCreated property
        public new DateTime DateCreated { get; set; }
        
  • When referencing another model in a child model, the new modifier hides the base property's reference to the base model.
    • Example: Referencing the FocusAPI's User property inside of the FocusAPI's UserSession model

      Base UserSession Model:

      public FocusCore.Models.BaseUser User { get; set; }
      

      Child UserSession Model:

      public new FocusAPI.Models.User User { get; set; }
      

Database Model Architecture

Database Technical Design Diagram drawio

⚠️ **GitHub.com Fallback** ⚠️