Database Design - ChrispyPeaches/FocusFriends GitHub Wiki
- 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
- Local DB component of every pet within the app
- Local DB component of every badge within the app
- Cloud DB component that records which pets the user owns
- Cloud DB component that records which badges the user owns
- Cloud DB component that records whenever the user starts another "Focus Session"
-
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
- 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.
- Guids are not supported by SQLite, so columns representing this datatype are stored as strings
- String maxlength limits are not supported by SQLite, so it is enforced by Entity Framework
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; }
- Example: changing the datatype of the DateCreated property
- To modify a property of a child class, add the
- 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; }
-