mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-10-14 17:54:42 +00:00
222 lines
5.7 KiB
Plaintext
222 lines
5.7 KiB
Plaintext
@startuml database-schema
|
|
!theme plain
|
|
skinparam backgroundColor #FFFFFF
|
|
skinparam defaultFontName Arial
|
|
skinparam linetype ortho
|
|
skinparam packageStyle rectangle
|
|
|
|
title Database Schema
|
|
caption Every table also has a RowVersion ROWVERSION column (optimistic concurrency), omitted below for brevity.\nTables marked (*) have no repository/feature slice yet.
|
|
|
|
package "User & Auth" {
|
|
entity "UserAccount" as User {
|
|
* UserAccountID: UNIQUEIDENTIFIER <<PK>>
|
|
--
|
|
* Username: VARCHAR(64) <<UNIQUE>>
|
|
* FirstName: NVARCHAR(128)
|
|
* LastName: NVARCHAR(128)
|
|
* Email: VARCHAR(128) <<UNIQUE>>
|
|
* CreatedAt: DATETIME
|
|
UpdatedAt: DATETIME
|
|
* DateOfBirth: DATE
|
|
}
|
|
|
|
entity "UserCredential" as Cred {
|
|
* UserCredentialID: UNIQUEIDENTIFIER <<PK>>
|
|
--
|
|
* UserAccountID: UNIQUEIDENTIFIER <<FK>>
|
|
* CreatedAt: DATETIME
|
|
* Expiry: DATETIME
|
|
* Hash: NVARCHAR(256)
|
|
* IsRevoked: BIT
|
|
RevokedAt: DATETIME
|
|
}
|
|
|
|
entity "UserVerification" as Verify {
|
|
* UserVerificationID: UNIQUEIDENTIFIER <<PK>>
|
|
--
|
|
* UserAccountID: UNIQUEIDENTIFIER <<FK, UNIQUE>>
|
|
* VerificationDateTime: DATETIME
|
|
}
|
|
|
|
entity "UserProfile" as Profile {
|
|
* UserProfileID: UNIQUEIDENTIFIER <<PK>>
|
|
--
|
|
* UserAccountID: UNIQUEIDENTIFIER <<FK, UNIQUE>>
|
|
* Biography: NVARCHAR(MAX)
|
|
}
|
|
|
|
entity "UserAvatar" as Avatar {
|
|
* UserAvatarID: UNIQUEIDENTIFIER <<PK>>
|
|
--
|
|
* UserProfileID: UNIQUEIDENTIFIER <<FK>>
|
|
* PhotoID: UNIQUEIDENTIFIER <<FK>>
|
|
* ValidFrom: DATETIME2(3)
|
|
ValidTo: DATETIME2(3)
|
|
..
|
|
At most one row per UserProfileID
|
|
has ValidTo IS NULL (active avatar)
|
|
}
|
|
|
|
entity "UserFollow (*)" as Follow {
|
|
* UserFollowID: UNIQUEIDENTIFIER <<PK>>
|
|
--
|
|
* UserAccountID: UNIQUEIDENTIFIER <<FK>>
|
|
* FollowingID: UNIQUEIDENTIFIER <<FK>>
|
|
* CreatedAt: DATETIME
|
|
}
|
|
|
|
entity "Photo (*)" as Photo {
|
|
* PhotoID: UNIQUEIDENTIFIER <<PK>>
|
|
--
|
|
Hyperlink: NVARCHAR(256)
|
|
* UploadedByID: UNIQUEIDENTIFIER <<FK>>
|
|
* UploadedAt: DATETIME
|
|
}
|
|
}
|
|
|
|
package "Location" {
|
|
entity "Country" as Country {
|
|
* CountryID: UNIQUEIDENTIFIER <<PK>>
|
|
--
|
|
* CountryName: NVARCHAR(100)
|
|
* ISO3166_1: CHAR(2) <<UNIQUE>>
|
|
}
|
|
|
|
entity "StateProvince" as StateProvince {
|
|
* StateProvinceID: UNIQUEIDENTIFIER <<PK>>
|
|
--
|
|
* StateProvinceName: NVARCHAR(100)
|
|
* ISO3166_2: CHAR(6) <<UNIQUE>>
|
|
* CountryID: UNIQUEIDENTIFIER <<FK>>
|
|
}
|
|
|
|
entity "City" as City {
|
|
* CityID: UNIQUEIDENTIFIER <<PK>>
|
|
--
|
|
* CityName: NVARCHAR(100)
|
|
* StateProvinceID: UNIQUEIDENTIFIER <<FK>>
|
|
}
|
|
}
|
|
|
|
package "Brewery" {
|
|
entity "BreweryPost" as Brewery {
|
|
* BreweryPostID: UNIQUEIDENTIFIER <<PK>>
|
|
--
|
|
* BreweryName: NVARCHAR(256)
|
|
* PostedByID: UNIQUEIDENTIFIER <<FK>>
|
|
* Description: NVARCHAR(512)
|
|
* CreatedAt: DATETIME
|
|
UpdatedAt: DATETIME
|
|
}
|
|
|
|
entity "BreweryPostLocation" as BreweryLoc {
|
|
* BreweryPostLocationID: UNIQUEIDENTIFIER <<PK>>
|
|
--
|
|
* BreweryPostID: UNIQUEIDENTIFIER <<FK, UNIQUE>>
|
|
* AddressLine1: NVARCHAR(256)
|
|
AddressLine2: NVARCHAR(256)
|
|
* PostalCode: NVARCHAR(20)
|
|
* CityID: UNIQUEIDENTIFIER <<FK>>
|
|
Coordinates: GEOGRAPHY
|
|
}
|
|
|
|
entity "BreweryPostPhoto (*)" as BreweryPhoto {
|
|
* BreweryPostPhotoID: UNIQUEIDENTIFIER <<PK>>
|
|
--
|
|
* BreweryPostID: UNIQUEIDENTIFIER <<FK>>
|
|
* PhotoID: UNIQUEIDENTIFIER <<FK>>
|
|
* LinkedAt: DATETIME
|
|
}
|
|
}
|
|
|
|
package "Beer (*)" {
|
|
entity "BeerStyle (*)" as BeerStyle {
|
|
* BeerStyleID: UNIQUEIDENTIFIER <<PK>>
|
|
--
|
|
* StyleName: NVARCHAR(100) <<UNIQUE>>
|
|
Description: NVARCHAR(MAX)
|
|
}
|
|
|
|
entity "BeerPost (*)" as Beer {
|
|
* BeerPostID: UNIQUEIDENTIFIER <<PK>>
|
|
--
|
|
* Name: NVARCHAR(100)
|
|
* Description: NVARCHAR(MAX)
|
|
* ABV: DECIMAL(4,2)
|
|
* IBU: INT
|
|
* PostedByID: UNIQUEIDENTIFIER <<FK>>
|
|
* BeerStyleID: UNIQUEIDENTIFIER <<FK>>
|
|
* BrewedByID: UNIQUEIDENTIFIER <<FK>>
|
|
* CreatedAt: DATETIME
|
|
UpdatedAt: DATETIME
|
|
}
|
|
|
|
entity "BeerPostPhoto (*)" as BeerPhoto {
|
|
* BeerPostPhotoID: UNIQUEIDENTIFIER <<PK>>
|
|
--
|
|
* BeerPostID: UNIQUEIDENTIFIER <<FK>>
|
|
* PhotoID: UNIQUEIDENTIFIER <<FK>>
|
|
* LinkedAt: DATETIME
|
|
}
|
|
|
|
entity "BeerPostComment (*)" as BeerComment {
|
|
* BeerPostCommentID: UNIQUEIDENTIFIER <<PK>>
|
|
--
|
|
* Comment: NVARCHAR(250)
|
|
* BeerPostID: UNIQUEIDENTIFIER <<FK>>
|
|
* CommentedByID: UNIQUEIDENTIFIER <<FK>>
|
|
* Rating: INT
|
|
* CreatedAt: DATETIME
|
|
UpdatedAt: DATETIME
|
|
}
|
|
}
|
|
|
|
' Relationships: User & Auth
|
|
User ||--o{ Cred : "has"
|
|
User ||--o| Verify : "has"
|
|
User ||--o| Profile : "has"
|
|
Profile ||--o{ Avatar : "has (history)"
|
|
Avatar }o--|| Photo : "refers to"
|
|
User ||--o{ Follow : "follows (UserAccountID)"
|
|
User ||--o{ Follow : "followed by (FollowingID)"
|
|
User ||--o{ Photo : "uploaded"
|
|
|
|
' Relationships: Location
|
|
Country ||--o{ StateProvince : "has"
|
|
StateProvince ||--o{ City : "has"
|
|
|
|
' Relationships: Brewery
|
|
User ||--o{ Brewery : "posted"
|
|
Brewery ||--o| BreweryLoc : "has"
|
|
City ||--o{ BreweryLoc : "located in"
|
|
Brewery ||--o{ BreweryPhoto : "has"
|
|
Photo ||--o{ BreweryPhoto : "linked to"
|
|
|
|
' Relationships: Beer
|
|
User ||--o{ Beer : "posted"
|
|
BeerStyle ||--o{ Beer : "categorizes"
|
|
Brewery ||--o{ Beer : "brewed"
|
|
Beer ||--o{ BeerPhoto : "has"
|
|
Photo ||--o{ BeerPhoto : "linked to"
|
|
Beer ||--o{ BeerComment : "has"
|
|
User ||--o{ BeerComment : "commented"
|
|
|
|
note bottom of User
|
|
Auth reads/writes (registration, login, credential
|
|
rotation, verification) go through ASP.NET Core
|
|
Identity's UserManager<ApplicationUser>, backed by
|
|
Features.Users' DapperUserStore - inline SQL, no
|
|
stored procedures. Profile/avatar data goes through
|
|
Features.Users' UserProfileRepository.
|
|
end note
|
|
|
|
note bottom of Brewery
|
|
Backed by Features.Breweries' BreweryRepository
|
|
(Dapper); create/update/delete run inline SQL
|
|
inside a transaction, with optimistic concurrency
|
|
via RowVersion
|
|
end note
|
|
|
|
@enduml
|