From d6e176bcd90abb08c87f80d24ba827acde54cdd9 Mon Sep 17 00:00:00 2001 From: Aaron Po Date: Wed, 2 Sep 2026 22:23:30 -0400 Subject: [PATCH] Split dbo schema into per-domain SQL schemas (#274) --- docs/web/database.md | 64 +++++++++++------- docs/web/diagrams/database-schema.md | 29 ++++---- .../{identity.mmd => auth.mmd} | 18 +---- docs/web/diagrams/database-schema/beer.mmd | 10 ++- docs/web/diagrams/database-schema/brewery.mmd | 21 +++++- .../{location.mmd => geolocation.mmd} | 13 +--- docs/web/diagrams/database-schema/media.mmd | 31 +-------- docs/web/diagrams/database-schema/social.mmd | 34 ++++++++++ .../scripts/01-Auth/00-Schema.sql | 2 + .../{01-schema => 01-Auth}/01-UserAccount.sql | 2 +- .../02-UserVerification.sql} | 6 +- .../03-UserCredential.sql} | 8 +-- .../scripts/02-Geolocation/00-Schema.sql | 2 + .../01-Country.sql} | 2 +- .../02-StateProvince.sql} | 6 +- .../03-City.sql} | 6 +- .../scripts/03-Media/00-Schema.sql | 2 + .../02-Photo.sql => 03-Media/01-Photo.sql} | 6 +- .../scripts/04-Brewery/00-Schema.sql | 2 + .../01-BreweryPost.sql} | 6 +- .../02-BreweryPostLocation.sql} | 12 ++-- .../03-BreweryPostPhoto.sql} | 10 +-- .../scripts/05-Beer/00-Schema.sql | 2 + .../01-BeerStyle.sql} | 2 +- .../02-BeerPost.sql} | 14 ++-- .../03-BeerPostPhoto.sql} | 10 +-- .../04-BeerPostComment.sql} | 10 +-- .../scripts/06-Social/00-Schema.sql | 2 + .../01-UserFollow.sql} | 10 +-- .../02-UserProfile.sql} | 4 +- .../03-UserAvatar.sql} | 12 ++-- .../Repository/BreweryRepository.cs | 66 +++++++++---------- .../Repository/LocationRepository.cs | 20 +++--- .../Repository/PhotoUploadRepository.cs | 4 +- .../Identity/DapperUserStore.cs | 40 +++++------ .../Repository/UserListRepository.cs | 4 +- .../Repository/UserProfileRepository.cs | 10 +-- 37 files changed, 275 insertions(+), 227 deletions(-) rename docs/web/diagrams/database-schema/{identity.mmd => auth.mmd} (70%) rename docs/web/diagrams/database-schema/{location.mmd => geolocation.mmd} (62%) create mode 100644 docs/web/diagrams/database-schema/social.mmd create mode 100644 web/backend/Database/Database.Migrations/scripts/01-Auth/00-Schema.sql rename web/backend/Database/Database.Migrations/scripts/{01-schema => 01-Auth}/01-UserAccount.sql (95%) rename web/backend/Database/Database.Migrations/scripts/{01-schema/03-UserVerification.sql => 01-Auth/02-UserVerification.sql} (76%) rename web/backend/Database/Database.Migrations/scripts/{01-schema/04-UserCredential.sql => 01-Auth/03-UserCredential.sql} (78%) create mode 100644 web/backend/Database/Database.Migrations/scripts/02-Geolocation/00-Schema.sql rename web/backend/Database/Database.Migrations/scripts/{01-schema/06-Country.sql => 02-Geolocation/01-Country.sql} (90%) rename web/backend/Database/Database.Migrations/scripts/{01-schema/07-StateProvince.sql => 02-Geolocation/02-StateProvince.sql} (80%) rename web/backend/Database/Database.Migrations/scripts/{01-schema/08-City.sql => 02-Geolocation/03-City.sql} (72%) create mode 100644 web/backend/Database/Database.Migrations/scripts/03-Media/00-Schema.sql rename web/backend/Database/Database.Migrations/scripts/{01-schema/02-Photo.sql => 03-Media/01-Photo.sql} (70%) create mode 100644 web/backend/Database/Database.Migrations/scripts/04-Brewery/00-Schema.sql rename web/backend/Database/Database.Migrations/scripts/{01-schema/09-BreweryPost.sql => 04-Brewery/01-BreweryPost.sql} (77%) rename web/backend/Database/Database.Migrations/scripts/{01-schema/10-BreweryPostLocation.sql => 04-Brewery/02-BreweryPostLocation.sql} (78%) rename web/backend/Database/Database.Migrations/scripts/{01-schema/11-BreweryPostPhoto.sql => 04-Brewery/03-BreweryPostPhoto.sql} (69%) create mode 100644 web/backend/Database/Database.Migrations/scripts/05-Beer/00-Schema.sql rename web/backend/Database/Database.Migrations/scripts/{01-schema/12-BeerStyle.sql => 05-Beer/01-BeerStyle.sql} (91%) rename web/backend/Database/Database.Migrations/scripts/{01-schema/13-BeerPost.sql => 05-Beer/02-BeerPost.sql} (79%) rename web/backend/Database/Database.Migrations/scripts/{01-schema/14-BeerPostPhoto.sql => 05-Beer/03-BeerPostPhoto.sql} (70%) rename web/backend/Database/Database.Migrations/scripts/{01-schema/15-BeerPostComment.sql => 05-Beer/04-BeerPostComment.sql} (79%) create mode 100644 web/backend/Database/Database.Migrations/scripts/06-Social/00-Schema.sql rename web/backend/Database/Database.Migrations/scripts/{01-schema/05-UserFollow.sql => 06-Social/01-UserFollow.sql} (76%) rename web/backend/Database/Database.Migrations/scripts/{01-schema/16-UserProfile.sql => 06-Social/02-UserProfile.sql} (84%) rename web/backend/Database/Database.Migrations/scripts/{01-schema/17-UserAvatar.sql => 06-Social/03-UserAvatar.sql} (80%) diff --git a/docs/web/database.md b/docs/web/database.md index 34f5c0e8..8b962767 100644 --- a/docs/web/database.md +++ b/docs/web/database.md @@ -15,33 +15,51 @@ convention. For the vertical-slice code that talks to this schema, see ## Schema -The full schema lives under -`web/backend/Database/Database.Migrations/scripts/01-schema/` with one numbered -script per table. +The schema is split into six SQL Server schemas, one per feature area, each +living in its own numbered folder under +`web/backend/Database/Database.Migrations/scripts/`. The folder numbers +(`01`-`06`) fix the load order so foreign-key dependencies resolve — DbUp runs +embedded scripts in alphabetical-by-resource-name order, so e.g. `04-Brewery` +(which references `Auth`, `Geolocation`, and `Media`) runs after all three. +Each folder's `00-Schema.sql` creates its SQL schema before its tables run: ``` -01-schema - ├── 01-UserAccount.sql - ├── 02-Photo.sql - ├── 03-UserVerification.sql - ├── 04-UserCredential.sql - ├── 05-UserFollow.sql - ├── 06-Country.sql - ├── 07-StateProvince.sql - ├── 08-City.sql - ├── 09-BreweryPost.sql - ├── 10-BreweryPostLocation.sql - ├── 11-BreweryPostPhoto.sql - ├── 12-BeerStyle.sql - ├── 13-BeerPost.sql - ├── 14-BeerPostPhoto.sql - ├── 15-BeerPostComment.sql - ├── 16-UserProfile.sql - └── 17-UserAvatar.sql +scripts + ├── 01-Auth (UserAccount, UserVerification, UserCredential) + │ ├── 00-Schema.sql + │ ├── 01-UserAccount.sql + │ ├── 02-UserVerification.sql + │ └── 03-UserCredential.sql + ├── 02-Geolocation (Country, StateProvince, City) + │ ├── 00-Schema.sql + │ ├── 01-Country.sql + │ ├── 02-StateProvince.sql + │ └── 03-City.sql + ├── 03-Media (Photo) + │ ├── 00-Schema.sql + │ └── 01-Photo.sql + ├── 04-Brewery (BreweryPost, BreweryPostLocation, BreweryPostPhoto) + │ ├── 00-Schema.sql + │ ├── 01-BreweryPost.sql + │ ├── 02-BreweryPostLocation.sql + │ └── 03-BreweryPostPhoto.sql + ├── 05-Beer (BeerStyle, BeerPost, BeerPostPhoto, BeerPostComment) + │ ├── 00-Schema.sql + │ ├── 01-BeerStyle.sql + │ ├── 02-BeerPost.sql + │ ├── 03-BeerPostPhoto.sql + │ └── 04-BeerPostComment.sql + └── 06-Social (UserFollow, UserProfile, UserAvatar) + ├── 00-Schema.sql + ├── 01-UserFollow.sql + ├── 02-UserProfile.sql + └── 03-UserAvatar.sql ``` -Each script is run in order by `Database.Migrations` (DbUp) on startup. Each -table is queried directly by the owning feature slice's repository (see +Each script is run in order by `Database.Migrations` (DbUp) on startup. Tables +are referenced schema-qualified in code (e.g. `Auth.UserAccount`), not under +the default `dbo` schema. Each table is queried directly by the owning +feature slice's repository (see [Direct SQL via Dapper/ADO.NET](architecture.md#direct-sql-via-dapperadonet)). A generated DBML copy of the schema (for import into a diagramming tool such as diff --git a/docs/web/diagrams/database-schema.md b/docs/web/diagrams/database-schema.md index fb4e219a..e9e8738a 100644 --- a/docs/web/diagrams/database-schema.md +++ b/docs/web/diagrams/database-schema.md @@ -1,39 +1,46 @@ # Database Schema -Five diagrams, one per schema category — mirrors the `identity` / `media` / -`location` / `brewery` / `beer` schema split. Every table also has a +Six diagrams, one per SQL Server schema — mirrors the `Auth` / `Geolocation` / +`Media` / `Brewery` / `Beer` / `Social` schema split under +`web/backend/Database/Database.Migrations/scripts/`. Every table also has a `RowVersion ROWVERSION` column (optimistic concurrency), omitted below for brevity. Tables marked `(*)` have no repository/feature slice yet. -Boxes with no attribute list (e.g. `Photo` in the identity diagram) are owned by -a different schema and shown only to keep the relationship visible; see the +Boxes with no attribute list (e.g. `Photo` in the auth diagram) are owned by a +different schema and shown only to keep the relationship visible; see the diagram named after that schema for its full definition. -## Identity (`identity`) +## Auth (`Auth`) ```mermaid ---8<-- "web/diagrams/database-schema/identity.mmd" +--8<-- "web/diagrams/database-schema/auth.mmd" ``` -## Media (`media`) +## Social (`Social`) + +```mermaid +--8<-- "web/diagrams/database-schema/social.mmd" +``` + +## Media (`Media`) ```mermaid --8<-- "web/diagrams/database-schema/media.mmd" ``` -## Location (`location`) +## Geolocation (`Geolocation`) ```mermaid ---8<-- "web/diagrams/database-schema/location.mmd" +--8<-- "web/diagrams/database-schema/geolocation.mmd" ``` -## Brewery (`brewery`) +## Brewery (`Brewery`) ```mermaid --8<-- "web/diagrams/database-schema/brewery.mmd" ``` -## Beer (`beer`) +## Beer (`Beer`) ```mermaid --8<-- "web/diagrams/database-schema/beer.mmd" diff --git a/docs/web/diagrams/database-schema/identity.mmd b/docs/web/diagrams/database-schema/auth.mmd similarity index 70% rename from docs/web/diagrams/database-schema/identity.mmd rename to docs/web/diagrams/database-schema/auth.mmd index f3d913e9..f15c99b0 100644 --- a/docs/web/diagrams/database-schema/identity.mmd +++ b/docs/web/diagrams/database-schema/auth.mmd @@ -6,12 +6,11 @@ config: erDiagram User ||--o{ Cred : "has credentials" User ||--o| Verify : "has verification" + + %% Cross-schema: defined in full in social.mmd / media.mmd / brewery.mmd / beer.mmd User ||--o| Profile : "has profile" User ||--o{ Follow : "follows" User ||--o{ Follow : "followed by" - - %% Cross-schema: defined in full in media.mmd / brewery.mmd / beer.mmd - Profile ||--o{ Avatar : "has avatar history" User ||--o{ Photo : "uploads" User ||--o{ Brewery : "posts" User ||--o{ Beer : "posts" @@ -43,16 +42,3 @@ erDiagram uniqueidentifier UserAccountID "FK, UK" datetime VerificationDateTime } - - Profile { - uniqueidentifier UserProfileID PK - uniqueidentifier UserAccountID "FK, UK" - nvarchar Biography - } - - Follow { - uniqueidentifier UserFollowID PK - uniqueidentifier UserAccountID FK - uniqueidentifier FollowingID FK - datetime CreatedAt - } diff --git a/docs/web/diagrams/database-schema/beer.mmd b/docs/web/diagrams/database-schema/beer.mmd index 3d02995f..1ee22792 100644 --- a/docs/web/diagrams/database-schema/beer.mmd +++ b/docs/web/diagrams/database-schema/beer.mmd @@ -8,10 +8,11 @@ erDiagram Beer ||--o{ BeerPhoto : "has photos" Beer ||--o{ BeerComment : "has comments" - %% Cross-schema: defined in full in identity.mmd / brewery.mmd / media.mmd + %% Cross-schema: defined in full in auth.mmd / brewery.mmd / media.mmd User ||--o{ Beer : "posts" Brewery ||--o{ Beer : "brews" User ||--o{ BeerComment : "comments" + BeerPhoto }o--|| Photo : "uses photo" BeerStyle { uniqueidentifier BeerStyleID PK @@ -41,3 +42,10 @@ erDiagram datetime CreatedAt datetime UpdatedAt "nullable" } + + BeerPhoto { + uniqueidentifier BeerPostPhotoID PK + uniqueidentifier BeerPostID FK + uniqueidentifier PhotoID FK + datetime LinkedAt + } diff --git a/docs/web/diagrams/database-schema/brewery.mmd b/docs/web/diagrams/database-schema/brewery.mmd index f5346cbe..276d74a1 100644 --- a/docs/web/diagrams/database-schema/brewery.mmd +++ b/docs/web/diagrams/database-schema/brewery.mmd @@ -9,8 +9,10 @@ erDiagram Brewery ||--o{ BreweryPhoto : "has photos" Brewery ||--o{ Beer : "brews" - %% Cross-schema: defined in full in identity.mmd / location.mmd / media.mmd / beer.mmd + %% Cross-schema: defined in full in auth.mmd / geolocation.mmd / media.mmd / beer.mmd User ||--o{ Brewery : "posts" + BreweryLocation }o--|| City : "located in" + BreweryPhoto }o--|| Photo : "uses photo" Brewery { uniqueidentifier BreweryPostID PK @@ -20,3 +22,20 @@ erDiagram datetime CreatedAt datetime UpdatedAt "nullable" } + + BreweryLocation { + uniqueidentifier BreweryPostLocationID PK + uniqueidentifier BreweryPostID "FK, UK" + nvarchar AddressLine1 + nvarchar AddressLine2 "nullable" + nvarchar PostalCode + uniqueidentifier CityID FK + geography Coordinates "nullable" + } + + BreweryPhoto { + uniqueidentifier BreweryPostPhotoID PK + uniqueidentifier BreweryPostID FK + uniqueidentifier PhotoID FK + datetime LinkedAt + } diff --git a/docs/web/diagrams/database-schema/location.mmd b/docs/web/diagrams/database-schema/geolocation.mmd similarity index 62% rename from docs/web/diagrams/database-schema/location.mmd rename to docs/web/diagrams/database-schema/geolocation.mmd index 5b9bd022..241a6e40 100644 --- a/docs/web/diagrams/database-schema/location.mmd +++ b/docs/web/diagrams/database-schema/geolocation.mmd @@ -1,10 +1,9 @@ erDiagram Country ||--o{ StateProvince : "has" StateProvince ||--o{ City : "has" - City ||--o{ BreweryLocation : "located in" %% Cross-schema: defined in full in brewery.mmd - Brewery ||--o| BreweryLocation : "has location" + City ||--o{ BreweryLocation : "located in" Country { uniqueidentifier CountryID PK @@ -24,13 +23,3 @@ erDiagram nvarchar CityName uniqueidentifier StateProvinceID FK } - - BreweryLocation { - uniqueidentifier BreweryPostLocationID PK - uniqueidentifier BreweryPostID "FK, UK" - nvarchar AddressLine1 - nvarchar AddressLine2 "nullable" - nvarchar PostalCode - uniqueidentifier CityID FK - geography Coordinates "nullable" - } diff --git a/docs/web/diagrams/database-schema/media.mmd b/docs/web/diagrams/database-schema/media.mmd index 8e82238a..c76a7cfa 100644 --- a/docs/web/diagrams/database-schema/media.mmd +++ b/docs/web/diagrams/database-schema/media.mmd @@ -4,41 +4,16 @@ config: --- erDiagram + User ||--o{ Photo : "uploads" + + %% Cross-schema: defined in full in auth.mmd / social.mmd / brewery.mmd / beer.mmd Avatar }o--|| Photo : "uses photo" Photo ||--o{ BreweryPhoto : "used in" Photo ||--o{ BeerPhoto : "used in" - %% Cross-schema: defined in full in identity.mmd / brewery.mmd / beer.mmd - Profile ||--o{ Avatar : "has avatar history" - User ||--o{ Photo : "uploads" - Brewery ||--o{ BreweryPhoto : "has photos" - Beer ||--o{ BeerPhoto : "has photos" - Photo { uniqueidentifier PhotoID PK nvarchar Hyperlink "nullable" uniqueidentifier UploadedByID FK datetime UploadedAt } - - Avatar { - uniqueidentifier UserAvatarID PK - uniqueidentifier UserProfileID FK - uniqueidentifier PhotoID FK - datetime2 ValidFrom - datetime2 ValidTo "nullable; at most one row per UserProfileID has ValidTo IS NULL (active avatar)" - } - - BreweryPhoto { - uniqueidentifier BreweryPostPhotoID PK - uniqueidentifier BreweryPostID FK - uniqueidentifier PhotoID FK - datetime LinkedAt - } - - BeerPhoto { - uniqueidentifier BeerPostPhotoID PK - uniqueidentifier BeerPostID FK - uniqueidentifier PhotoID FK - datetime LinkedAt - } diff --git a/docs/web/diagrams/database-schema/social.mmd b/docs/web/diagrams/database-schema/social.mmd new file mode 100644 index 00000000..7979e7e0 --- /dev/null +++ b/docs/web/diagrams/database-schema/social.mmd @@ -0,0 +1,34 @@ +--- +config: + layout: elk +--- + +erDiagram + User ||--o| Profile : "has profile" + User ||--o{ Follow : "follows" + User ||--o{ Follow : "followed by" + Profile ||--o{ Avatar : "has avatar history" + + %% Cross-schema: defined in full in auth.mmd / media.mmd + Avatar }o--|| Photo : "uses photo" + + Profile { + uniqueidentifier UserProfileID PK + uniqueidentifier UserAccountID "FK, UK" + nvarchar Biography + } + + Follow { + uniqueidentifier UserFollowID PK + uniqueidentifier UserAccountID FK + uniqueidentifier FollowingID FK + datetime CreatedAt + } + + Avatar { + uniqueidentifier UserAvatarID PK + uniqueidentifier UserProfileID FK + uniqueidentifier PhotoID FK + datetime2 ValidFrom + datetime2 ValidTo "nullable; at most one row per UserProfileID has ValidTo IS NULL (active avatar)" + } diff --git a/web/backend/Database/Database.Migrations/scripts/01-Auth/00-Schema.sql b/web/backend/Database/Database.Migrations/scripts/01-Auth/00-Schema.sql new file mode 100644 index 00000000..0f6e0d99 --- /dev/null +++ b/web/backend/Database/Database.Migrations/scripts/01-Auth/00-Schema.sql @@ -0,0 +1,2 @@ +IF NOT EXISTS (SELECT 1 FROM sys.schemas WHERE name = 'Auth') + EXEC('CREATE SCHEMA Auth'); diff --git a/web/backend/Database/Database.Migrations/scripts/01-schema/01-UserAccount.sql b/web/backend/Database/Database.Migrations/scripts/01-Auth/01-UserAccount.sql similarity index 95% rename from web/backend/Database/Database.Migrations/scripts/01-schema/01-UserAccount.sql rename to web/backend/Database/Database.Migrations/scripts/01-Auth/01-UserAccount.sql index 024df8c2..c712cc74 100644 --- a/web/backend/Database/Database.Migrations/scripts/01-schema/01-UserAccount.sql +++ b/web/backend/Database/Database.Migrations/scripts/01-Auth/01-UserAccount.sql @@ -1,4 +1,4 @@ -CREATE TABLE dbo.UserAccount +CREATE TABLE Auth.UserAccount ( UserAccountID UNIQUEIDENTIFIER CONSTRAINT DF_UserAccountID DEFAULT NEWID(), diff --git a/web/backend/Database/Database.Migrations/scripts/01-schema/03-UserVerification.sql b/web/backend/Database/Database.Migrations/scripts/01-Auth/02-UserVerification.sql similarity index 76% rename from web/backend/Database/Database.Migrations/scripts/01-schema/03-UserVerification.sql rename to web/backend/Database/Database.Migrations/scripts/01-Auth/02-UserVerification.sql index 9febb3d9..2837cbcb 100644 --- a/web/backend/Database/Database.Migrations/scripts/01-schema/03-UserVerification.sql +++ b/web/backend/Database/Database.Migrations/scripts/01-Auth/02-UserVerification.sql @@ -1,4 +1,4 @@ -CREATE TABLE UserVerification -- delete verification data when user account is deleted +CREATE TABLE Auth.UserVerification -- delete verification data when user account is deleted ( UserVerificationID UNIQUEIDENTIFIER CONSTRAINT DF_UserVerificationID DEFAULT NEWID(), @@ -15,7 +15,7 @@ CREATE TABLE UserVerification -- delete verification data when user account is d CONSTRAINT FK_UserVerification_UserAccount FOREIGN KEY (UserAccountID) - REFERENCES UserAccount (UserAccountID) + REFERENCES Auth.UserAccount (UserAccountID) ON DELETE CASCADE, CONSTRAINT AK_UserVerification_UserAccountID @@ -24,4 +24,4 @@ CREATE TABLE UserVerification -- delete verification data when user account is d CREATE NONCLUSTERED INDEX IX_UserVerification_UserAccount - ON UserVerification(UserAccountID); + ON Auth.UserVerification(UserAccountID); diff --git a/web/backend/Database/Database.Migrations/scripts/01-schema/04-UserCredential.sql b/web/backend/Database/Database.Migrations/scripts/01-Auth/03-UserCredential.sql similarity index 78% rename from web/backend/Database/Database.Migrations/scripts/01-schema/04-UserCredential.sql rename to web/backend/Database/Database.Migrations/scripts/01-Auth/03-UserCredential.sql index 17cef1e1..9ac591b6 100644 --- a/web/backend/Database/Database.Migrations/scripts/01-schema/04-UserCredential.sql +++ b/web/backend/Database/Database.Migrations/scripts/01-Auth/03-UserCredential.sql @@ -1,4 +1,4 @@ -CREATE TABLE UserCredential -- delete credentials when user account is deleted +CREATE TABLE Auth.UserCredential -- delete credentials when user account is deleted ( UserCredentialID UNIQUEIDENTIFIER CONSTRAINT DF_UserCredentialID DEFAULT NEWID(), @@ -26,15 +26,15 @@ CREATE TABLE UserCredential -- delete credentials when user account is deleted CONSTRAINT FK_UserCredential_UserAccount FOREIGN KEY (UserAccountID) - REFERENCES UserAccount (UserAccountID) + REFERENCES Auth.UserAccount (UserAccountID) ON DELETE CASCADE ); CREATE NONCLUSTERED INDEX IX_UserCredential_UserAccount - ON UserCredential(UserAccountID); + ON Auth.UserCredential(UserAccountID); CREATE NONCLUSTERED INDEX IX_UserCredential_Account_Active - ON UserCredential(UserAccountID, IsRevoked, Expiry) + ON Auth.UserCredential(UserAccountID, IsRevoked, Expiry) INCLUDE (Hash); diff --git a/web/backend/Database/Database.Migrations/scripts/02-Geolocation/00-Schema.sql b/web/backend/Database/Database.Migrations/scripts/02-Geolocation/00-Schema.sql new file mode 100644 index 00000000..a8515f54 --- /dev/null +++ b/web/backend/Database/Database.Migrations/scripts/02-Geolocation/00-Schema.sql @@ -0,0 +1,2 @@ +IF NOT EXISTS (SELECT 1 FROM sys.schemas WHERE name = 'Geolocation') + EXEC('CREATE SCHEMA Geolocation'); diff --git a/web/backend/Database/Database.Migrations/scripts/01-schema/06-Country.sql b/web/backend/Database/Database.Migrations/scripts/02-Geolocation/01-Country.sql similarity index 90% rename from web/backend/Database/Database.Migrations/scripts/01-schema/06-Country.sql rename to web/backend/Database/Database.Migrations/scripts/02-Geolocation/01-Country.sql index 07a727b0..8266c622 100644 --- a/web/backend/Database/Database.Migrations/scripts/01-schema/06-Country.sql +++ b/web/backend/Database/Database.Migrations/scripts/02-Geolocation/01-Country.sql @@ -1,4 +1,4 @@ -CREATE TABLE Country +CREATE TABLE Geolocation.Country ( CountryID UNIQUEIDENTIFIER CONSTRAINT DF_CountryID DEFAULT NEWID(), diff --git a/web/backend/Database/Database.Migrations/scripts/01-schema/07-StateProvince.sql b/web/backend/Database/Database.Migrations/scripts/02-Geolocation/02-StateProvince.sql similarity index 80% rename from web/backend/Database/Database.Migrations/scripts/01-schema/07-StateProvince.sql rename to web/backend/Database/Database.Migrations/scripts/02-Geolocation/02-StateProvince.sql index d91526c3..2f34f720 100644 --- a/web/backend/Database/Database.Migrations/scripts/01-schema/07-StateProvince.sql +++ b/web/backend/Database/Database.Migrations/scripts/02-Geolocation/02-StateProvince.sql @@ -1,4 +1,4 @@ -CREATE TABLE StateProvince +CREATE TABLE Geolocation.StateProvince ( StateProvinceID UNIQUEIDENTIFIER CONSTRAINT DF_StateProvinceID DEFAULT NEWID(), @@ -20,9 +20,9 @@ CREATE TABLE StateProvince CONSTRAINT FK_StateProvince_Country FOREIGN KEY (CountryID) - REFERENCES Country (CountryID) + REFERENCES Geolocation.Country (CountryID) ); CREATE NONCLUSTERED INDEX IX_StateProvince_Country - ON StateProvince(CountryID); + ON Geolocation.StateProvince(CountryID); diff --git a/web/backend/Database/Database.Migrations/scripts/01-schema/08-City.sql b/web/backend/Database/Database.Migrations/scripts/02-Geolocation/03-City.sql similarity index 72% rename from web/backend/Database/Database.Migrations/scripts/01-schema/08-City.sql rename to web/backend/Database/Database.Migrations/scripts/02-Geolocation/03-City.sql index ee2cce0f..64f5fe24 100644 --- a/web/backend/Database/Database.Migrations/scripts/01-schema/08-City.sql +++ b/web/backend/Database/Database.Migrations/scripts/02-Geolocation/03-City.sql @@ -1,4 +1,4 @@ -CREATE TABLE City +CREATE TABLE Geolocation.City ( CityID UNIQUEIDENTIFIER CONSTRAINT DF_CityID DEFAULT NEWID(), @@ -14,9 +14,9 @@ CREATE TABLE City CONSTRAINT FK_City_StateProvince FOREIGN KEY (StateProvinceID) - REFERENCES StateProvince (StateProvinceID) + REFERENCES Geolocation.StateProvince (StateProvinceID) ); CREATE NONCLUSTERED INDEX IX_City_StateProvince - ON City(StateProvinceID); + ON Geolocation.City(StateProvinceID); diff --git a/web/backend/Database/Database.Migrations/scripts/03-Media/00-Schema.sql b/web/backend/Database/Database.Migrations/scripts/03-Media/00-Schema.sql new file mode 100644 index 00000000..9e24f814 --- /dev/null +++ b/web/backend/Database/Database.Migrations/scripts/03-Media/00-Schema.sql @@ -0,0 +1,2 @@ +IF NOT EXISTS (SELECT 1 FROM sys.schemas WHERE name = 'Media') + EXEC('CREATE SCHEMA Media'); diff --git a/web/backend/Database/Database.Migrations/scripts/01-schema/02-Photo.sql b/web/backend/Database/Database.Migrations/scripts/03-Media/01-Photo.sql similarity index 70% rename from web/backend/Database/Database.Migrations/scripts/01-schema/02-Photo.sql rename to web/backend/Database/Database.Migrations/scripts/03-Media/01-Photo.sql index d7f6d2cc..3232bf5d 100644 --- a/web/backend/Database/Database.Migrations/scripts/01-schema/02-Photo.sql +++ b/web/backend/Database/Database.Migrations/scripts/03-Media/01-Photo.sql @@ -1,4 +1,4 @@ -CREATE TABLE Photo -- All photos must be linked to a user account, you cannot delete a user account if they have uploaded photos +CREATE TABLE Media.Photo -- All photos must be linked to a user account, you cannot delete a user account if they have uploaded photos ( PhotoID UNIQUEIDENTIFIER CONSTRAINT DF_PhotoID DEFAULT NEWID(), @@ -18,10 +18,10 @@ CREATE TABLE Photo -- All photos must be linked to a user account, you cannot de CONSTRAINT FK_Photo_UploadedBy FOREIGN KEY (UploadedByID) - REFERENCES UserAccount (UserAccountID) + REFERENCES Auth.UserAccount (UserAccountID) ON DELETE NO ACTION ); CREATE NONCLUSTERED INDEX IX_Photo_UploadedByID - ON Photo(UploadedByID); + ON Media.Photo(UploadedByID); diff --git a/web/backend/Database/Database.Migrations/scripts/04-Brewery/00-Schema.sql b/web/backend/Database/Database.Migrations/scripts/04-Brewery/00-Schema.sql new file mode 100644 index 00000000..256fe866 --- /dev/null +++ b/web/backend/Database/Database.Migrations/scripts/04-Brewery/00-Schema.sql @@ -0,0 +1,2 @@ +IF NOT EXISTS (SELECT 1 FROM sys.schemas WHERE name = 'Brewery') + EXEC('CREATE SCHEMA Brewery'); diff --git a/web/backend/Database/Database.Migrations/scripts/01-schema/09-BreweryPost.sql b/web/backend/Database/Database.Migrations/scripts/04-Brewery/01-BreweryPost.sql similarity index 77% rename from web/backend/Database/Database.Migrations/scripts/01-schema/09-BreweryPost.sql rename to web/backend/Database/Database.Migrations/scripts/04-Brewery/01-BreweryPost.sql index 4a8fc640..b42d600a 100644 --- a/web/backend/Database/Database.Migrations/scripts/01-schema/09-BreweryPost.sql +++ b/web/backend/Database/Database.Migrations/scripts/04-Brewery/01-BreweryPost.sql @@ -1,4 +1,4 @@ -CREATE TABLE BreweryPost -- A user cannot be deleted if they have a post +CREATE TABLE Brewery.BreweryPost -- A user cannot be deleted if they have a post ( BreweryPostID UNIQUEIDENTIFIER CONSTRAINT DF_BreweryPostID DEFAULT NEWID(), @@ -21,10 +21,10 @@ CREATE TABLE BreweryPost -- A user cannot be deleted if they have a post CONSTRAINT FK_BreweryPost_UserAccount FOREIGN KEY (PostedByID) - REFERENCES UserAccount (UserAccountID) + REFERENCES Auth.UserAccount (UserAccountID) ON DELETE NO ACTION ); CREATE NONCLUSTERED INDEX IX_BreweryPost_PostedByID - ON BreweryPost(PostedByID); + ON Brewery.BreweryPost(PostedByID); diff --git a/web/backend/Database/Database.Migrations/scripts/01-schema/10-BreweryPostLocation.sql b/web/backend/Database/Database.Migrations/scripts/04-Brewery/02-BreweryPostLocation.sql similarity index 78% rename from web/backend/Database/Database.Migrations/scripts/01-schema/10-BreweryPostLocation.sql rename to web/backend/Database/Database.Migrations/scripts/04-Brewery/02-BreweryPostLocation.sql index f3eefa9a..15a13a6f 100644 --- a/web/backend/Database/Database.Migrations/scripts/01-schema/10-BreweryPostLocation.sql +++ b/web/backend/Database/Database.Migrations/scripts/04-Brewery/02-BreweryPostLocation.sql @@ -1,4 +1,4 @@ -CREATE TABLE BreweryPostLocation +CREATE TABLE Brewery.BreweryPostLocation ( BreweryPostLocationID UNIQUEIDENTIFIER CONSTRAINT DF_BreweryPostLocationID DEFAULT NEWID(), @@ -25,24 +25,24 @@ CREATE TABLE BreweryPostLocation CONSTRAINT FK_BreweryPostLocation_BreweryPost FOREIGN KEY (BreweryPostID) - REFERENCES BreweryPost (BreweryPostID) + REFERENCES Brewery.BreweryPost (BreweryPostID) ON DELETE CASCADE, CONSTRAINT FK_BreweryPostLocation_City FOREIGN KEY (CityID) - REFERENCES City (CityID) + REFERENCES Geolocation.City (CityID) ); CREATE NONCLUSTERED INDEX IX_BreweryPostLocation_BreweryPost - ON BreweryPostLocation(BreweryPostID); + ON Brewery.BreweryPostLocation(BreweryPostID); CREATE NONCLUSTERED INDEX IX_BreweryPostLocation_City - ON BreweryPostLocation(CityID); + ON Brewery.BreweryPostLocation(CityID); CREATE SPATIAL INDEX SIDX_BreweryPostLocation_Coordinates - ON BreweryPostLocation(Coordinates) + ON Brewery.BreweryPostLocation(Coordinates) USING GEOGRAPHY_GRID WITH ( GRIDS = (LEVEL_1 = MEDIUM, LEVEL_2 = MEDIUM, LEVEL_3 = MEDIUM, LEVEL_4 = MEDIUM), diff --git a/web/backend/Database/Database.Migrations/scripts/01-schema/11-BreweryPostPhoto.sql b/web/backend/Database/Database.Migrations/scripts/04-Brewery/03-BreweryPostPhoto.sql similarity index 69% rename from web/backend/Database/Database.Migrations/scripts/01-schema/11-BreweryPostPhoto.sql rename to web/backend/Database/Database.Migrations/scripts/04-Brewery/03-BreweryPostPhoto.sql index e6407b3f..32c57413 100644 --- a/web/backend/Database/Database.Migrations/scripts/01-schema/11-BreweryPostPhoto.sql +++ b/web/backend/Database/Database.Migrations/scripts/04-Brewery/03-BreweryPostPhoto.sql @@ -1,4 +1,4 @@ -CREATE TABLE BreweryPostPhoto -- All photos linked to a post are deleted if the post is deleted +CREATE TABLE Brewery.BreweryPostPhoto -- All photos linked to a post are deleted if the post is deleted ( BreweryPostPhotoID UNIQUEIDENTIFIER CONSTRAINT DF_BreweryPostPhotoID DEFAULT NEWID(), @@ -17,19 +17,19 @@ CREATE TABLE BreweryPostPhoto -- All photos linked to a post are deleted if the CONSTRAINT FK_BreweryPostPhoto_BreweryPost FOREIGN KEY (BreweryPostID) - REFERENCES BreweryPost (BreweryPostID) + REFERENCES Brewery.BreweryPost (BreweryPostID) ON DELETE CASCADE, CONSTRAINT FK_BreweryPostPhoto_Photo FOREIGN KEY (PhotoID) - REFERENCES Photo (PhotoID) + REFERENCES Media.Photo (PhotoID) ON DELETE CASCADE ); CREATE NONCLUSTERED INDEX IX_BreweryPostPhoto_Photo_BreweryPost - ON BreweryPostPhoto(PhotoID, BreweryPostID); + ON Brewery.BreweryPostPhoto(PhotoID, BreweryPostID); CREATE NONCLUSTERED INDEX IX_BreweryPostPhoto_BreweryPost_Photo - ON BreweryPostPhoto(BreweryPostID, PhotoID); + ON Brewery.BreweryPostPhoto(BreweryPostID, PhotoID); diff --git a/web/backend/Database/Database.Migrations/scripts/05-Beer/00-Schema.sql b/web/backend/Database/Database.Migrations/scripts/05-Beer/00-Schema.sql new file mode 100644 index 00000000..2bf98e8f --- /dev/null +++ b/web/backend/Database/Database.Migrations/scripts/05-Beer/00-Schema.sql @@ -0,0 +1,2 @@ +IF NOT EXISTS (SELECT 1 FROM sys.schemas WHERE name = 'Beer') + EXEC('CREATE SCHEMA Beer'); diff --git a/web/backend/Database/Database.Migrations/scripts/01-schema/12-BeerStyle.sql b/web/backend/Database/Database.Migrations/scripts/05-Beer/01-BeerStyle.sql similarity index 91% rename from web/backend/Database/Database.Migrations/scripts/01-schema/12-BeerStyle.sql rename to web/backend/Database/Database.Migrations/scripts/05-Beer/01-BeerStyle.sql index 484b6654..779682c9 100644 --- a/web/backend/Database/Database.Migrations/scripts/01-schema/12-BeerStyle.sql +++ b/web/backend/Database/Database.Migrations/scripts/05-Beer/01-BeerStyle.sql @@ -1,4 +1,4 @@ -CREATE TABLE BeerStyle +CREATE TABLE Beer.BeerStyle ( BeerStyleID UNIQUEIDENTIFIER CONSTRAINT DF_BeerStyleID DEFAULT NEWID(), diff --git a/web/backend/Database/Database.Migrations/scripts/01-schema/13-BeerPost.sql b/web/backend/Database/Database.Migrations/scripts/05-Beer/02-BeerPost.sql similarity index 79% rename from web/backend/Database/Database.Migrations/scripts/01-schema/13-BeerPost.sql rename to web/backend/Database/Database.Migrations/scripts/05-Beer/02-BeerPost.sql index 4a70a826..73626099 100644 --- a/web/backend/Database/Database.Migrations/scripts/01-schema/13-BeerPost.sql +++ b/web/backend/Database/Database.Migrations/scripts/05-Beer/02-BeerPost.sql @@ -1,4 +1,4 @@ -CREATE TABLE BeerPost +CREATE TABLE Beer.BeerPost ( BeerPostID UNIQUEIDENTIFIER CONSTRAINT DF_BeerPostID DEFAULT NEWID(), @@ -31,16 +31,16 @@ CREATE TABLE BeerPost CONSTRAINT FK_BeerPost_PostedBy FOREIGN KEY (PostedByID) - REFERENCES UserAccount (UserAccountID) + REFERENCES Auth.UserAccount (UserAccountID) ON DELETE NO ACTION, CONSTRAINT FK_BeerPost_BeerStyle FOREIGN KEY (BeerStyleID) - REFERENCES BeerStyle (BeerStyleID), + REFERENCES Beer.BeerStyle (BeerStyleID), CONSTRAINT FK_BeerPost_Brewery FOREIGN KEY (BrewedByID) - REFERENCES BreweryPost (BreweryPostID), + REFERENCES Brewery.BreweryPost (BreweryPostID), CONSTRAINT CHK_BeerPost_ABV CHECK (ABV >= 0 AND ABV <= 67), @@ -51,12 +51,12 @@ CREATE TABLE BeerPost CREATE NONCLUSTERED INDEX IX_BeerPost_PostedBy - ON BeerPost(PostedByID); + ON Beer.BeerPost(PostedByID); CREATE NONCLUSTERED INDEX IX_BeerPost_BeerStyle - ON BeerPost(BeerStyleID); + ON Beer.BeerPost(BeerStyleID); CREATE NONCLUSTERED INDEX IX_BeerPost_BrewedBy - ON BeerPost(BrewedByID); + ON Beer.BeerPost(BrewedByID); diff --git a/web/backend/Database/Database.Migrations/scripts/01-schema/14-BeerPostPhoto.sql b/web/backend/Database/Database.Migrations/scripts/05-Beer/03-BeerPostPhoto.sql similarity index 70% rename from web/backend/Database/Database.Migrations/scripts/01-schema/14-BeerPostPhoto.sql rename to web/backend/Database/Database.Migrations/scripts/05-Beer/03-BeerPostPhoto.sql index 415de2f2..2f1b5c26 100644 --- a/web/backend/Database/Database.Migrations/scripts/01-schema/14-BeerPostPhoto.sql +++ b/web/backend/Database/Database.Migrations/scripts/05-Beer/03-BeerPostPhoto.sql @@ -1,4 +1,4 @@ -CREATE TABLE BeerPostPhoto -- All photos linked to a beer post are deleted if the post is deleted +CREATE TABLE Beer.BeerPostPhoto -- All photos linked to a beer post are deleted if the post is deleted ( BeerPostPhotoID UNIQUEIDENTIFIER CONSTRAINT DF_BeerPostPhotoID DEFAULT NEWID(), @@ -17,19 +17,19 @@ CREATE TABLE BeerPostPhoto -- All photos linked to a beer post are deleted if th CONSTRAINT FK_BeerPostPhoto_BeerPost FOREIGN KEY (BeerPostID) - REFERENCES BeerPost (BeerPostID) + REFERENCES Beer.BeerPost (BeerPostID) ON DELETE CASCADE, CONSTRAINT FK_BeerPostPhoto_Photo FOREIGN KEY (PhotoID) - REFERENCES Photo (PhotoID) + REFERENCES Media.Photo (PhotoID) ON DELETE CASCADE ); CREATE NONCLUSTERED INDEX IX_BeerPostPhoto_Photo_BeerPost - ON BeerPostPhoto(PhotoID, BeerPostID); + ON Beer.BeerPostPhoto(PhotoID, BeerPostID); CREATE NONCLUSTERED INDEX IX_BeerPostPhoto_BeerPost_Photo - ON BeerPostPhoto(BeerPostID, PhotoID); + ON Beer.BeerPostPhoto(BeerPostID, PhotoID); diff --git a/web/backend/Database/Database.Migrations/scripts/01-schema/15-BeerPostComment.sql b/web/backend/Database/Database.Migrations/scripts/05-Beer/04-BeerPostComment.sql similarity index 79% rename from web/backend/Database/Database.Migrations/scripts/01-schema/15-BeerPostComment.sql rename to web/backend/Database/Database.Migrations/scripts/05-Beer/04-BeerPostComment.sql index 3e0b386e..8b59056f 100644 --- a/web/backend/Database/Database.Migrations/scripts/01-schema/15-BeerPostComment.sql +++ b/web/backend/Database/Database.Migrations/scripts/05-Beer/04-BeerPostComment.sql @@ -1,4 +1,4 @@ -CREATE TABLE BeerPostComment +CREATE TABLE Beer.BeerPostComment ( BeerPostCommentID UNIQUEIDENTIFIER CONSTRAINT DF_BeerPostComment DEFAULT NEWID(), @@ -23,11 +23,11 @@ CREATE TABLE BeerPostComment CONSTRAINT FK_BeerPostComment_BeerPost FOREIGN KEY (BeerPostID) - REFERENCES BeerPost (BeerPostID), + REFERENCES Beer.BeerPost (BeerPostID), CONSTRAINT FK_BeerPostComment_UserAccount FOREIGN KEY (CommentedByID) - REFERENCES UserAccount (UserAccountID) + REFERENCES Auth.UserAccount (UserAccountID) ON DELETE NO ACTION, CONSTRAINT CHK_BeerPostComment_Rating @@ -36,8 +36,8 @@ CREATE TABLE BeerPostComment CREATE NONCLUSTERED INDEX IX_BeerPostComment_BeerPost - ON BeerPostComment(BeerPostID); + ON Beer.BeerPostComment(BeerPostID); CREATE NONCLUSTERED INDEX IX_BeerPostComment_CommentedBy - ON BeerPostComment(CommentedByID); + ON Beer.BeerPostComment(CommentedByID); diff --git a/web/backend/Database/Database.Migrations/scripts/06-Social/00-Schema.sql b/web/backend/Database/Database.Migrations/scripts/06-Social/00-Schema.sql new file mode 100644 index 00000000..ad886419 --- /dev/null +++ b/web/backend/Database/Database.Migrations/scripts/06-Social/00-Schema.sql @@ -0,0 +1,2 @@ +IF NOT EXISTS (SELECT 1 FROM sys.schemas WHERE name = 'Social') + EXEC('CREATE SCHEMA Social'); diff --git a/web/backend/Database/Database.Migrations/scripts/01-schema/05-UserFollow.sql b/web/backend/Database/Database.Migrations/scripts/06-Social/01-UserFollow.sql similarity index 76% rename from web/backend/Database/Database.Migrations/scripts/01-schema/05-UserFollow.sql rename to web/backend/Database/Database.Migrations/scripts/06-Social/01-UserFollow.sql index 5e9d06a8..fa4c2176 100644 --- a/web/backend/Database/Database.Migrations/scripts/01-schema/05-UserFollow.sql +++ b/web/backend/Database/Database.Migrations/scripts/06-Social/01-UserFollow.sql @@ -1,4 +1,4 @@ -CREATE TABLE UserFollow +CREATE TABLE Social.UserFollow ( UserFollowID UNIQUEIDENTIFIER CONSTRAINT DF_UserFollowID DEFAULT NEWID(), @@ -17,12 +17,12 @@ CREATE TABLE UserFollow CONSTRAINT FK_UserFollow_UserAccount FOREIGN KEY (UserAccountID) - REFERENCES UserAccount (UserAccountID) + REFERENCES Auth.UserAccount (UserAccountID) ON DELETE NO ACTION, CONSTRAINT FK_UserFollow_UserAccountFollowing FOREIGN KEY (FollowingID) - REFERENCES UserAccount (UserAccountID) + REFERENCES Auth.UserAccount (UserAccountID) ON DELETE NO ACTION, CONSTRAINT CK_CannotFollowOwnAccount @@ -32,8 +32,8 @@ CREATE TABLE UserFollow CREATE NONCLUSTERED INDEX IX_UserFollow_UserAccount_FollowingID - ON UserFollow(UserAccountID, FollowingID); + ON Social.UserFollow(UserAccountID, FollowingID); CREATE NONCLUSTERED INDEX IX_UserFollow_FollowingID_UserAccount - ON UserFollow(FollowingID, UserAccountID); + ON Social.UserFollow(FollowingID, UserAccountID); diff --git a/web/backend/Database/Database.Migrations/scripts/01-schema/16-UserProfile.sql b/web/backend/Database/Database.Migrations/scripts/06-Social/02-UserProfile.sql similarity index 84% rename from web/backend/Database/Database.Migrations/scripts/01-schema/16-UserProfile.sql rename to web/backend/Database/Database.Migrations/scripts/06-Social/02-UserProfile.sql index 956ac67e..a74f51f0 100644 --- a/web/backend/Database/Database.Migrations/scripts/01-schema/16-UserProfile.sql +++ b/web/backend/Database/Database.Migrations/scripts/06-Social/02-UserProfile.sql @@ -1,4 +1,4 @@ -CREATE TABLE dbo.UserProfile +CREATE TABLE Social.UserProfile ( UserProfileID UNIQUEIDENTIFIER CONSTRAINT DF_UserProfileID DEFAULT NEWID(), @@ -17,6 +17,6 @@ CREATE TABLE dbo.UserProfile CONSTRAINT FK_UserProfile_UserAccount FOREIGN KEY (UserAccountID) - REFERENCES UserAccount (UserAccountID) + REFERENCES Auth.UserAccount (UserAccountID) ON DELETE CASCADE ); diff --git a/web/backend/Database/Database.Migrations/scripts/01-schema/17-UserAvatar.sql b/web/backend/Database/Database.Migrations/scripts/06-Social/03-UserAvatar.sql similarity index 80% rename from web/backend/Database/Database.Migrations/scripts/01-schema/17-UserAvatar.sql rename to web/backend/Database/Database.Migrations/scripts/06-Social/03-UserAvatar.sql index 8c7c09be..b0bce15c 100644 --- a/web/backend/Database/Database.Migrations/scripts/01-schema/17-UserAvatar.sql +++ b/web/backend/Database/Database.Migrations/scripts/06-Social/03-UserAvatar.sql @@ -1,4 +1,4 @@ -CREATE TABLE dbo.UserAvatar +CREATE TABLE Social.UserAvatar ( UserAvatarID UNIQUEIDENTIFIER CONSTRAINT DF_UserAvatarID DEFAULT NEWID(), @@ -18,12 +18,12 @@ CREATE TABLE dbo.UserAvatar CONSTRAINT FK_UserAvatar_UserProfile FOREIGN KEY (UserProfileID) - REFERENCES dbo.UserProfile (UserProfileID) + REFERENCES Social.UserProfile (UserProfileID) ON DELETE CASCADE, CONSTRAINT FK_UserAvatar_Photo FOREIGN KEY (PhotoID) - REFERENCES dbo.Photo (PhotoID) + REFERENCES Media.Photo (PhotoID) ON DELETE NO ACTION ON UPDATE NO ACTION, @@ -33,11 +33,11 @@ CREATE TABLE dbo.UserAvatar -- At most one active avatar per profile CREATE UNIQUE NONCLUSTERED INDEX UX_UserAvatar_ActiveOne - ON dbo.UserAvatar (UserProfileID) + ON Social.UserAvatar (UserProfileID) WHERE ValidTo IS NULL; CREATE NONCLUSTERED INDEX IX_UserAvatar_Photo - ON dbo.UserAvatar (PhotoID); + ON Social.UserAvatar (PhotoID); CREATE NONCLUSTERED INDEX ix_UserAvatar_Profile - ON dbo.UserAvatar (UserProfileID) + ON Social.UserAvatar (UserProfileID) diff --git a/web/backend/Features/Features.Breweries/Repository/BreweryRepository.cs b/web/backend/Features/Features.Breweries/Repository/BreweryRepository.cs index 4cb9a823..8c8cac7a 100644 --- a/web/backend/Features/Features.Breweries/Repository/BreweryRepository.cs +++ b/web/backend/Features/Features.Breweries/Repository/BreweryRepository.cs @@ -62,11 +62,11 @@ public class BreweryRepository(ISqlConnectionFactory connectionFactory) co.CountryID, co.CountryName, co.ISO3166_1 AS Iso31661 - FROM dbo.BreweryPost bp - LEFT JOIN dbo.BreweryPostLocation bpl ON bp.BreweryPostID = bpl.BreweryPostID - LEFT JOIN dbo.City c ON bpl.CityID = c.CityID - LEFT JOIN dbo.StateProvince sp ON c.StateProvinceID = sp.StateProvinceID - LEFT JOIN dbo.Country co ON sp.CountryID = co.CountryID + FROM Brewery.BreweryPost bp + LEFT JOIN Brewery.BreweryPostLocation bpl ON bp.BreweryPostID = bpl.BreweryPostID + LEFT JOIN Geolocation.City c ON bpl.CityID = c.CityID + LEFT JOIN Geolocation.StateProvince sp ON c.StateProvinceID = sp.StateProvinceID + LEFT JOIN Geolocation.Country co ON sp.CountryID = co.CountryID WHERE bp.BreweryPostID = @BreweryPostId """, new { BreweryPostId = id }, @@ -85,7 +85,7 @@ public class BreweryRepository(ISqlConnectionFactory connectionFactory) await using DbConnection connection = await CreateConnection(); return await connection.ExecuteScalarAsync( new CommandDefinition( - "SELECT PostedByID FROM dbo.BreweryPost WHERE BreweryPostID = @BreweryPostId", + "SELECT PostedByID FROM Brewery.BreweryPost WHERE BreweryPostID = @BreweryPostId", new { BreweryPostId = id }, cancellationToken: cancellationToken ) @@ -126,11 +126,11 @@ public class BreweryRepository(ISqlConnectionFactory connectionFactory) co.CountryID, co.CountryName, co.ISO3166_1 AS Iso31661 - FROM dbo.BreweryPost bp - LEFT JOIN dbo.BreweryPostLocation bpl ON bp.BreweryPostID = bpl.BreweryPostID - LEFT JOIN dbo.City c ON bpl.CityID = c.CityID - LEFT JOIN dbo.StateProvince sp ON c.StateProvinceID = sp.StateProvinceID - LEFT JOIN dbo.Country co ON sp.CountryID = co.CountryID + FROM Brewery.BreweryPost bp + LEFT JOIN Brewery.BreweryPostLocation bpl ON bp.BreweryPostID = bpl.BreweryPostID + LEFT JOIN Geolocation.City c ON bpl.CityID = c.CityID + LEFT JOIN Geolocation.StateProvince sp ON c.StateProvinceID = sp.StateProvinceID + LEFT JOIN Geolocation.Country co ON sp.CountryID = co.CountryID ORDER BY bp.CreatedAt DESC OFFSET @Offset ROWS FETCH NEXT @Limit ROWS ONLY """, @@ -173,11 +173,11 @@ public class BreweryRepository(ISqlConnectionFactory connectionFactory) co.CountryName, co.ISO3166_1 AS Iso31661, bpl.Coordinates.STDistance(@Origin) AS DistanceMetres - FROM dbo.BreweryPost bp - INNER JOIN dbo.BreweryPostLocation bpl ON bp.BreweryPostID = bpl.BreweryPostID - LEFT JOIN dbo.City c ON bpl.CityID = c.CityID - LEFT JOIN dbo.StateProvince sp ON c.StateProvinceID = sp.StateProvinceID - LEFT JOIN dbo.Country co ON sp.CountryID = co.CountryID + FROM Brewery.BreweryPost bp + INNER JOIN Brewery.BreweryPostLocation bpl ON bp.BreweryPostID = bpl.BreweryPostID + LEFT JOIN Geolocation.City c ON bpl.CityID = c.CityID + LEFT JOIN Geolocation.StateProvince sp ON c.StateProvinceID = sp.StateProvinceID + LEFT JOIN Geolocation.Country co ON sp.CountryID = co.CountryID WHERE bpl.Coordinates IS NOT NULL AND bpl.Coordinates.STDistance(@Origin) <= @RangeInMetres ORDER BY bpl.Coordinates.STDistance(@Origin) ASC @@ -223,11 +223,11 @@ public class BreweryRepository(ISqlConnectionFactory connectionFactory) co.CountryID, co.CountryName, co.ISO3166_1 AS Iso31661 - FROM dbo.BreweryPost bp - INNER JOIN dbo.BreweryPostLocation bpl ON bp.BreweryPostID = bpl.BreweryPostID - LEFT JOIN dbo.City c ON bpl.CityID = c.CityID - LEFT JOIN dbo.StateProvince sp ON c.StateProvinceID = sp.StateProvinceID - LEFT JOIN dbo.Country co ON sp.CountryID = co.CountryID + FROM Brewery.BreweryPost bp + INNER JOIN Brewery.BreweryPostLocation bpl ON bp.BreweryPostID = bpl.BreweryPostID + LEFT JOIN Geolocation.City c ON bpl.CityID = c.CityID + LEFT JOIN Geolocation.StateProvince sp ON c.StateProvinceID = sp.StateProvinceID + LEFT JOIN Geolocation.Country co ON sp.CountryID = co.CountryID WHERE bpl.Coordinates IS NOT NULL ORDER BY bp.BreweryPostID ASC """, @@ -249,7 +249,7 @@ public class BreweryRepository(ISqlConnectionFactory connectionFactory) new CommandDefinition( """ SELECT 1 FROM - dbo.BreweryPost + Brewery.BreweryPost WHERE BreweryPostID = @BreweryPostId """, @@ -268,7 +268,7 @@ public class BreweryRepository(ISqlConnectionFactory connectionFactory) bool cityExists = await connection.ExecuteScalarAsync( new CommandDefinition( - "SELECT 1 FROM dbo.City WHERE CityID = @CityId", + "SELECT 1 FROM Geolocation.City WHERE CityID = @CityId", new { brewery.Location.CityId }, transaction, cancellationToken: cancellationToken @@ -283,7 +283,7 @@ public class BreweryRepository(ISqlConnectionFactory connectionFactory) int updatedRows = await connection.ExecuteAsync( new CommandDefinition( """ - UPDATE dbo.BreweryPost + UPDATE Brewery.BreweryPost SET BreweryName = @BreweryName, Description = @Description, UpdatedAt = GETDATE() @@ -315,7 +315,7 @@ public class BreweryRepository(ISqlConnectionFactory connectionFactory) new CommandDefinition( """ DELETE FROM - dbo.BreweryPostLocation + Brewery.BreweryPostLocation WHERE BreweryPostID = @BreweryPostId """, new { brewery.BreweryPostId }, @@ -331,7 +331,7 @@ public class BreweryRepository(ISqlConnectionFactory connectionFactory) new CommandDefinition( """ SELECT 1 - FROM dbo.BreweryPostLocation + FROM Brewery.BreweryPostLocation WHERE BreweryPostID = @BreweryPostId """, new { brewery.BreweryPostId }, @@ -345,7 +345,7 @@ public class BreweryRepository(ISqlConnectionFactory connectionFactory) await connection.ExecuteAsync( new CommandDefinition( """ - UPDATE dbo.BreweryPostLocation + UPDATE Brewery.BreweryPostLocation SET CityID = @CityId, AddressLine1 = @AddressLine1, AddressLine2 = @AddressLine2, @@ -375,7 +375,7 @@ public class BreweryRepository(ISqlConnectionFactory connectionFactory) await connection.ExecuteAsync( new CommandDefinition( """ - INSERT INTO dbo.BreweryPostLocation + INSERT INTO Brewery.BreweryPostLocation (BreweryPostLocationID, BreweryPostID, CityID, @@ -434,7 +434,7 @@ public class BreweryRepository(ISqlConnectionFactory connectionFactory) int rows = await connection.ExecuteAsync( """ DELETE FROM - dbo.BreweryPost + Brewery.BreweryPost WHERE BreweryPostID = @BreweryPostId """, @@ -462,7 +462,7 @@ public class BreweryRepository(ISqlConnectionFactory connectionFactory) """ SELECT 1 FROM - dbo.UserAccount + Auth.UserAccount WHERE UserAccountID = @PostedById """, @@ -481,7 +481,7 @@ public class BreweryRepository(ISqlConnectionFactory connectionFactory) """ SELECT 1 FROM - dbo.City + Geolocation.City WHERE CityID = @CityId """, @@ -497,7 +497,7 @@ public class BreweryRepository(ISqlConnectionFactory connectionFactory) await connection.ExecuteAsync( new CommandDefinition( """ - INSERT INTO dbo.BreweryPost + INSERT INTO Brewery.BreweryPost (BreweryPostID, BreweryName, Description, PostedByID) VALUES (@BreweryPostId, @BreweryName, @Description, @PostedById) @@ -516,7 +516,7 @@ public class BreweryRepository(ISqlConnectionFactory connectionFactory) await connection.ExecuteAsync( new CommandDefinition( """ - INSERT INTO dbo.BreweryPostLocation + INSERT INTO Brewery.BreweryPostLocation (BreweryPostLocationID, BreweryPostID, CityID, diff --git a/web/backend/Features/Features.Locations/Repository/LocationRepository.cs b/web/backend/Features/Features.Locations/Repository/LocationRepository.cs index 8121b21f..d2c8c7d9 100644 --- a/web/backend/Features/Features.Locations/Repository/LocationRepository.cs +++ b/web/backend/Features/Features.Locations/Repository/LocationRepository.cs @@ -46,7 +46,7 @@ public class LocationRepository(ISqlConnectionFactory connectionFactory) await connection.ExecuteScalarAsync( """ SELECT 1 - FROM dbo.City + FROM Geolocation.City WHERE CityName = @CityName AND StateProvinceID = @StateProvinceId """, new { location.CityName, StateProvinceId = stateProvinceId } @@ -56,7 +56,7 @@ public class LocationRepository(ISqlConnectionFactory connectionFactory) if (!cityExists) await connection.ExecuteAsync( """ - INSERT INTO dbo.City (StateProvinceID, CityName) + INSERT INTO Geolocation.City (StateProvinceID, CityName) VALUES (@StateProvinceId, @CityName) """, new { StateProvinceId = stateProvinceId, location.CityName } @@ -79,7 +79,7 @@ public class LocationRepository(ISqlConnectionFactory connectionFactory) await connection.ExecuteScalarAsync( """ SELECT 1 - FROM dbo.Country + FROM Geolocation.Country WHERE ISO3166_1 = @ISO3166_1 """, new { ISO3166_1 = isoCode } @@ -91,7 +91,7 @@ public class LocationRepository(ISqlConnectionFactory connectionFactory) // race is tolerated (the resulting duplicate row, if any, is out of scope for this method). await connection.ExecuteAsync( """ - INSERT INTO dbo.Country (CountryName, ISO3166_1) + INSERT INTO Geolocation.Country (CountryName, ISO3166_1) VALUES (@CountryName, @ISO3166_1) """, new { CountryName = countryName, ISO3166_1 = isoCode } @@ -125,7 +125,7 @@ public class LocationRepository(ISqlConnectionFactory connectionFactory) await connection.ExecuteScalarAsync( """ SELECT 1 - FROM dbo.StateProvince + FROM Geolocation.StateProvince WHERE ISO3166_2 = @ISO3166_2 """, new { ISO3166_2 = isoCode } @@ -135,7 +135,7 @@ public class LocationRepository(ISqlConnectionFactory connectionFactory) if (!exists) await connection.ExecuteAsync( """ - INSERT INTO dbo.StateProvince (StateProvinceName, ISO3166_2, CountryID) + INSERT INTO Geolocation.StateProvince (StateProvinceName, ISO3166_2, CountryID) VALUES (@StateProvinceName, @ISO3166_2, @CountryId) """, new @@ -153,7 +153,7 @@ public class LocationRepository(ISqlConnectionFactory connectionFactory) return await connection.ExecuteScalarAsync( """ SELECT CountryID - FROM dbo.Country + FROM Geolocation.Country WHERE ISO3166_1 = @ISO3166_1 """, new { ISO3166_1 = isoCode } @@ -166,7 +166,7 @@ public class LocationRepository(ISqlConnectionFactory connectionFactory) return await connection.ExecuteScalarAsync( """ SELECT StateProvinceID - FROM dbo.StateProvince + FROM Geolocation.StateProvince WHERE ISO3166_2 = @ISO3166_2 """, new { ISO3166_2 = isoCode } @@ -179,8 +179,8 @@ public class LocationRepository(ISqlConnectionFactory connectionFactory) return await connection.ExecuteScalarAsync( """ SELECT c.CityID - FROM dbo.City c - INNER JOIN dbo.StateProvince sp ON sp.StateProvinceID = c.StateProvinceID + FROM Geolocation.City c + INNER JOIN Geolocation.StateProvince sp ON sp.StateProvinceID = c.StateProvinceID WHERE c.CityName = @CityName AND sp.ISO3166_2 = @StateProvinceCode """, new { CityName = cityName, StateProvinceCode = stateProvinceIsoCode } diff --git a/web/backend/Features/Features.PhotoUpload/Repository/PhotoUploadRepository.cs b/web/backend/Features/Features.PhotoUpload/Repository/PhotoUploadRepository.cs index 0c449fe0..51f6837f 100644 --- a/web/backend/Features/Features.PhotoUpload/Repository/PhotoUploadRepository.cs +++ b/web/backend/Features/Features.PhotoUpload/Repository/PhotoUploadRepository.cs @@ -28,7 +28,7 @@ public class PhotoUploadRepository(ISqlConnectionFactory connectionFactory) """ SELECT 1 FROM - dbo.UserAccount + Auth.UserAccount WHERE UserAccountID = @UploadedById """, @@ -44,7 +44,7 @@ public class PhotoUploadRepository(ISqlConnectionFactory connectionFactory) await connection.ExecuteAsync( new CommandDefinition( """ - INSERT INTO dbo.Photo (PhotoID, Hyperlink, UploadedByID) + INSERT INTO Media.Photo (PhotoID, Hyperlink, UploadedByID) VALUES (@PhotoId, @Hyperlink, @UploadedById) """, new { photo.PhotoId, photo.Hyperlink, photo.UploadedById }, diff --git a/web/backend/Features/Features.Users/Identity/DapperUserStore.cs b/web/backend/Features/Features.Users/Identity/DapperUserStore.cs index 1e8965cb..df2d63ef 100644 --- a/web/backend/Features/Features.Users/Identity/DapperUserStore.cs +++ b/web/backend/Features/Features.Users/Identity/DapperUserStore.cs @@ -8,8 +8,8 @@ namespace Features.Auth.Identity; /// /// Dapper-based implementation of the ASP.NET Core Identity store interfaces consumed by -/// , persisting against the existing dbo.UserAccount, -/// dbo.UserCredential, and dbo.UserVerification tables. No EF Core is used, and no schema +/// , persisting against the existing Auth.UserAccount, +/// Auth.UserCredential, and Auth.UserVerification tables. No EF Core is used, and no schema /// changes were required: normalized name/email are computed on the fly rather than persisted (the /// existing unique indexes are already case-insensitive under SQL Server's default collation). /// @@ -21,7 +21,7 @@ public sealed class DapperUserStore(ISqlConnectionFactory connectionFactory) { private const string SelectUserSql = """ SELECT UserAccountID AS Id, Username AS UserName, FirstName, LastName, Email, DateOfBirth - FROM dbo.UserAccount + FROM Auth.UserAccount """; /// No unmanaged resources to release; each method opens and disposes its own connection. @@ -87,7 +87,7 @@ public sealed class DapperUserStore(ISqlConnectionFactory connectionFactory) Guid userAccountId = await connection.ExecuteScalarAsync( new CommandDefinition( """ - INSERT INTO dbo.UserAccount (Username, FirstName, LastName, DateOfBirth, Email) + INSERT INTO Auth.UserAccount (Username, FirstName, LastName, DateOfBirth, Email) OUTPUT INSERTED.UserAccountID VALUES (@UserName, @FirstName, @LastName, @DateOfBirth, @Email); """, @@ -107,7 +107,7 @@ public sealed class DapperUserStore(ISqlConnectionFactory connectionFactory) await connection.ExecuteAsync( new CommandDefinition( """ - INSERT INTO dbo.UserCredential (UserAccountId, Hash) + INSERT INTO Auth.UserCredential (UserAccountId, Hash) VALUES (@UserAccountId, @Hash); """, new { UserAccountId = userAccountId, Hash = user.PasswordHash }, @@ -141,7 +141,7 @@ public sealed class DapperUserStore(ISqlConnectionFactory connectionFactory) /// /// - /// Persists profile field changes and keeps dbo.UserVerification in sync with + /// Persists profile field changes and keeps Auth.UserVerification in sync with /// : a row is inserted (idempotently, matching the /// previous AuthRepository.ConfirmUserAccountAsync behavior) when /// , and removed when -- notably after @@ -157,7 +157,7 @@ public sealed class DapperUserStore(ISqlConnectionFactory connectionFactory) await connection.ExecuteAsync( new CommandDefinition( """ - UPDATE dbo.UserAccount + UPDATE Auth.UserAccount SET Username = @UserName, FirstName = @FirstName, LastName = @LastName, Email = @Email, DateOfBirth = @DateOfBirth, UpdatedAt = GETDATE() WHERE UserAccountID = @Id @@ -185,9 +185,9 @@ public sealed class DapperUserStore(ISqlConnectionFactory connectionFactory) /// /// - /// A plain DELETE against dbo.UserAccount: its foreign keys from - /// dbo.UserCredential, dbo.UserVerification, and dbo.UserProfile cascade - /// (dbo.UserAvatar cascades transitively through dbo.UserProfile), so no manual + /// A plain DELETE against Auth.UserAccount: its foreign keys from + /// Auth.UserCredential, Auth.UserVerification, and Social.UserProfile cascade + /// (Social.UserAvatar cascades transitively through Social.UserProfile), so no manual /// child cleanup is needed. Other tables (posts, comments, photos, follows) reference the /// account with ON DELETE NO ACTION by design; deleting an account that still has any of /// those fails with a foreign key violation, which is surfaced as a failed @@ -204,7 +204,7 @@ public sealed class DapperUserStore(ISqlConnectionFactory connectionFactory) { await connection.ExecuteAsync( new CommandDefinition( - "DELETE FROM dbo.UserAccount WHERE UserAccountID = @Id", + "DELETE FROM Auth.UserAccount WHERE UserAccountID = @Id", new { user.Id }, cancellationToken: cancellationToken ) @@ -273,7 +273,7 @@ public sealed class DapperUserStore(ISqlConnectionFactory connectionFactory) /// /// /// For an existing account ( already assigned), rotates the - /// credential transactionally -- revoking the previous dbo.UserCredential row(s) and inserting + /// credential transactionally -- revoking the previous Auth.UserCredential row(s) and inserting /// the new hash -- mirroring the previous AuthRepository.RotateCredentialAsync behavior. During /// registration calls this before the account has an ID (i.e. before /// runs); in that case only the in-memory hash is set, and @@ -301,7 +301,7 @@ public sealed class DapperUserStore(ISqlConnectionFactory connectionFactory) await connection.ExecuteAsync( new CommandDefinition( """ - UPDATE dbo.UserCredential + UPDATE Auth.UserCredential SET IsRevoked = 1, RevokedAt = GETDATE() WHERE UserAccountId = @UserAccountId AND IsRevoked = 0 """, @@ -314,7 +314,7 @@ public sealed class DapperUserStore(ISqlConnectionFactory connectionFactory) await connection.ExecuteAsync( new CommandDefinition( """ - INSERT INTO dbo.UserCredential (UserAccountId, Hash) + INSERT INTO Auth.UserCredential (UserAccountId, Hash) VALUES (@UserAccountId, @Hash); """, new { UserAccountId = user.Id, Hash = passwordHash }, @@ -423,7 +423,7 @@ public sealed class DapperUserStore(ISqlConnectionFactory connectionFactory) new CommandDefinition( """ SELECT Hash - FROM dbo.UserCredential + FROM Auth.UserCredential WHERE UserAccountId = @UserAccountId AND IsRevoked = 0 """, new { UserAccountId = user.Id }, @@ -435,7 +435,7 @@ public sealed class DapperUserStore(ISqlConnectionFactory connectionFactory) new CommandDefinition( """ SELECT TOP 1 1 - FROM dbo.UserVerification + FROM Auth.UserVerification WHERE UserAccountID = @UserAccountId """, new { UserAccountId = user.Id }, @@ -459,7 +459,7 @@ public sealed class DapperUserStore(ISqlConnectionFactory connectionFactory) new CommandDefinition( """ SELECT TOP 1 1 - FROM dbo.UserVerification + FROM Auth.UserVerification WHERE UserAccountID = @UserAccountId """, new { UserAccountId = userAccountId }, @@ -475,7 +475,7 @@ public sealed class DapperUserStore(ISqlConnectionFactory connectionFactory) await connection.ExecuteAsync( new CommandDefinition( """ - INSERT INTO dbo.UserVerification (UserAccountId, VerificationDateTime) + INSERT INTO Auth.UserVerification (UserAccountId, VerificationDateTime) VALUES (@UserAccountId, GETDATE()) """, new { UserAccountId = userAccountId }, @@ -489,7 +489,7 @@ public sealed class DapperUserStore(ISqlConnectionFactory connectionFactory) } } - /// Removes the dbo.UserVerification row for a user, if one exists. + /// Removes the Auth.UserVerification row for a user, if one exists. private static Task RemoveVerificationRowAsync( DbConnection connection, Guid userAccountId, @@ -497,7 +497,7 @@ public sealed class DapperUserStore(ISqlConnectionFactory connectionFactory) ) => connection.ExecuteAsync( new CommandDefinition( - "DELETE FROM dbo.UserVerification WHERE UserAccountID = @UserAccountId", + "DELETE FROM Auth.UserVerification WHERE UserAccountID = @UserAccountId", new { UserAccountId = userAccountId }, cancellationToken: cancellationToken ) diff --git a/web/backend/Features/Features.Users/Repository/UserListRepository.cs b/web/backend/Features/Features.Users/Repository/UserListRepository.cs index 8f90054a..d43fafc0 100644 --- a/web/backend/Features/Features.Users/Repository/UserListRepository.cs +++ b/web/backend/Features/Features.Users/Repository/UserListRepository.cs @@ -22,7 +22,7 @@ public class UserListRepository(ISqlConnectionFactory connectionFactory) UserAccountID, Username, FirstName, LastName, Email, CreatedAt, UpdatedAt, DateOfBirth, RowVersion - FROM dbo.UserAccount + FROM Auth.UserAccount WHERE UserAccountID = @UserAccountId """, new { UserAccountId = id } @@ -40,7 +40,7 @@ public class UserListRepository(ISqlConnectionFactory connectionFactory) return await connection.QueryAsync( """ SELECT UserAccountID, Username, FirstName, LastName, Email, CreatedAt, UpdatedAt, DateOfBirth, RowVersion - FROM dbo.UserAccount + FROM Auth.UserAccount ORDER BY CreatedAt DESC OFFSET @Offset ROWS FETCH NEXT @Limit ROWS ONLY """, diff --git a/web/backend/Features/Features.Users/Repository/UserProfileRepository.cs b/web/backend/Features/Features.Users/Repository/UserProfileRepository.cs index 3e9b235d..5eb5d78c 100644 --- a/web/backend/Features/Features.Users/Repository/UserProfileRepository.cs +++ b/web/backend/Features/Features.Users/Repository/UserProfileRepository.cs @@ -25,7 +25,7 @@ public class UserProfileRepository(ISqlConnectionFactory connectionFactory) return await connection.ExecuteScalarAsync( new CommandDefinition( """ - INSERT INTO dbo.UserProfile (UserAccountID, Biography) + INSERT INTO Social.UserProfile (UserAccountID, Biography) OUTPUT INSERTED.UserProfileID VALUES (@UserAccountId, @Biography) """, @@ -47,7 +47,7 @@ public class UserProfileRepository(ISqlConnectionFactory connectionFactory) new CommandDefinition( """ SELECT UserProfileID - FROM dbo.UserProfile + FROM Social.UserProfile WHERE UserAccountID = @UserAccountId """, new { UserAccountId = userAccountId }, @@ -73,7 +73,7 @@ public class UserProfileRepository(ISqlConnectionFactory connectionFactory) int updatedRows = await connection.ExecuteAsync( new CommandDefinition( """ - UPDATE dbo.UserProfile + UPDATE Social.UserProfile SET Biography = @Biography WHERE UserAccountID = @UserAccountId """, @@ -101,7 +101,7 @@ public class UserProfileRepository(ISqlConnectionFactory connectionFactory) await connection.ExecuteAsync( new CommandDefinition( """ - UPDATE dbo.UserAvatar + UPDATE Social.UserAvatar SET ValidTo = SYSUTCDATETIME() WHERE UserProfileID = @UserProfileId AND ValidTo IS NULL """, @@ -114,7 +114,7 @@ public class UserProfileRepository(ISqlConnectionFactory connectionFactory) await connection.ExecuteAsync( new CommandDefinition( """ - INSERT INTO dbo.UserAvatar (UserAvatarID, UserProfileID, PhotoID) + INSERT INTO Social.UserAvatar (UserAvatarID, UserProfileID, PhotoID) VALUES (@UserAvatarId, @UserProfileId, @PhotoId) """, new