diff --git a/CHANGELOG.md b/CHANGELOG.md index 968e05d21..b9648e42a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Added + +- Added indexes for `alias`, `granteeUserId` and `userId` to the access database table +- Added indexes for `currency`, `name` and `userId` to the account database table +- Added an index for `accountId`, `date` and `updatedAt` to the account balance database table +- Added an index for `userId` to the auth device database table +- Added an index for `marketPrice` and `state` to the market data database table +- Added indexes for `date`, `isDraft` and `userId` to the order database table +- Added an index for `name` to the platform database table +- Added indexes for `assetClass`, `currency`, `dataSource`, `isin`, `name` and `symbol` to the symbol profile database table +- Added an index for `userId` to the subscription database table +- Added an index for `name` to the tag database table +- Added indexes for `accessToken`, `createdAt`, `provider`, `role` and `thirdPartyId` to the user database table + ### Changed - Harmonized the setting of a default locale in various components diff --git a/apps/api/src/app/account/account.service.ts b/apps/api/src/app/account/account.service.ts index 238e3d429..cb8467c18 100644 --- a/apps/api/src/app/account/account.service.ts +++ b/apps/api/src/app/account/account.service.ts @@ -21,10 +21,8 @@ export class AccountService { public async account({ id_userId }: Prisma.AccountWhereUniqueInput): Promise { - const { id, userId } = id_userId; - const [account] = await this.accounts({ - where: { id, userId } + where: id_userId }); return account; diff --git a/apps/api/src/app/user/user.service.ts b/apps/api/src/app/user/user.service.ts index 2c4d3760c..1f9fd0bf9 100644 --- a/apps/api/src/app/user/user.service.ts +++ b/apps/api/src/app/user/user.service.ts @@ -438,7 +438,7 @@ export class UserService { settings }, where: { - userId: userId + userId } }); diff --git a/package.json b/package.json index e06f09156..cb34bddd3 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "database:push": "prisma db push", "database:seed": "prisma db seed", "database:setup": "yarn database:push && yarn database:seed", - "database:validate": "prisma validate", + "database:validate-schema": "prisma validate", "dep-graph": "nx dep-graph", "e2e": "ng e2e", "extract-locales": "nx run client:extract-i18n --output-path ./apps/client/src/locales", diff --git a/prisma/migrations/20240221201438_added_missing_indexes/migration.sql b/prisma/migrations/20240221201438_added_missing_indexes/migration.sql new file mode 100644 index 000000000..7de6885bd --- /dev/null +++ b/prisma/migrations/20240221201438_added_missing_indexes/migration.sql @@ -0,0 +1,86 @@ +-- CreateIndex +CREATE INDEX "Access_alias_idx" ON "Access"("alias"); + +-- CreateIndex +CREATE INDEX "Access_granteeUserId_idx" ON "Access"("granteeUserId"); + +-- CreateIndex +CREATE INDEX "Access_userId_idx" ON "Access"("userId"); + +-- CreateIndex +CREATE INDEX "Account_currency_idx" ON "Account"("currency"); + +-- CreateIndex +CREATE INDEX "Account_name_idx" ON "Account"("name"); + +-- CreateIndex +CREATE INDEX "Account_userId_idx" ON "Account"("userId"); + +-- CreateIndex +CREATE INDEX "AccountBalance_accountId_idx" ON "AccountBalance"("accountId"); + +-- CreateIndex +CREATE INDEX "AccountBalance_date_idx" ON "AccountBalance"("date"); + +-- CreateIndex +CREATE INDEX "Analytics_updatedAt_idx" ON "Analytics"("updatedAt"); + +-- CreateIndex +CREATE INDEX "AuthDevice_userId_idx" ON "AuthDevice"("userId"); + +-- CreateIndex +CREATE INDEX "MarketData_marketPrice_idx" ON "MarketData"("marketPrice"); + +-- CreateIndex +CREATE INDEX "MarketData_state_idx" ON "MarketData"("state"); + +-- CreateIndex +CREATE INDEX "Order_date_idx" ON "Order"("date"); + +-- CreateIndex +CREATE INDEX "Order_isDraft_idx" ON "Order"("isDraft"); + +-- CreateIndex +CREATE INDEX "Order_userId_idx" ON "Order"("userId"); + +-- CreateIndex +CREATE INDEX "Platform_name_idx" ON "Platform"("name"); + +-- CreateIndex +CREATE INDEX "Subscription_userId_idx" ON "Subscription"("userId"); + +-- CreateIndex +CREATE INDEX "SymbolProfile_assetClass_idx" ON "SymbolProfile"("assetClass"); + +-- CreateIndex +CREATE INDEX "SymbolProfile_currency_idx" ON "SymbolProfile"("currency"); + +-- CreateIndex +CREATE INDEX "SymbolProfile_dataSource_idx" ON "SymbolProfile"("dataSource"); + +-- CreateIndex +CREATE INDEX "SymbolProfile_isin_idx" ON "SymbolProfile"("isin"); + +-- CreateIndex +CREATE INDEX "SymbolProfile_name_idx" ON "SymbolProfile"("name"); + +-- CreateIndex +CREATE INDEX "SymbolProfile_symbol_idx" ON "SymbolProfile"("symbol"); + +-- CreateIndex +CREATE INDEX "Tag_name_idx" ON "Tag"("name"); + +-- CreateIndex +CREATE INDEX "User_accessToken_idx" ON "User"("accessToken"); + +-- CreateIndex +CREATE INDEX "User_createdAt_idx" ON "User"("createdAt"); + +-- CreateIndex +CREATE INDEX "User_provider_idx" ON "User"("provider"); + +-- CreateIndex +CREATE INDEX "User_role_idx" ON "User"("role"); + +-- CreateIndex +CREATE INDEX "User_thirdPartyId_idx" ON "User"("thirdPartyId"); diff --git a/prisma/schema.prisma b/prisma/schema.prisma index ae36b00bf..4457254ba 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -19,6 +19,10 @@ model Access { userId String GranteeUser User? @relation("accessGet", fields: [granteeUserId], references: [id]) User User @relation("accessGive", fields: [userId], references: [id]) + + @@index([alias]) + @@index([granteeUserId]) + @@index([userId]) } model Account { @@ -39,7 +43,10 @@ model Account { Order Order[] @@id([id, userId]) + @@index([currency]) @@index([id]) + @@index([name]) + @@index([userId]) } model AccountBalance { @@ -51,6 +58,9 @@ model AccountBalance { userId String value Float Account Account @relation(fields: [accountId, userId], onDelete: Cascade, references: [id, userId]) + + @@index([accountId]) + @@index([date]) } model Analytics { @@ -59,6 +69,8 @@ model Analytics { updatedAt DateTime @updatedAt userId String @id User User @relation(fields: [userId], references: [id]) + + @@index([updatedAt]) } model AuthDevice { @@ -70,6 +82,8 @@ model AuthDevice { updatedAt DateTime @updatedAt userId String User User @relation(fields: [userId], references: [id]) + + @@index([userId]) } model MarketData { @@ -84,6 +98,8 @@ model MarketData { @@unique([dataSource, date, symbol]) @@index([dataSource]) @@index([date]) + @@index([marketPrice]) + @@index([state]) @@index([symbol]) } @@ -108,6 +124,9 @@ model Order { tags Tag[] @@index([accountId]) + @@index([date]) + @@index([isDraft]) + @@index([userId]) } model Platform { @@ -115,6 +134,8 @@ model Platform { name String? url String @unique Account Account[] + + @@index([name]) } model Property { @@ -153,6 +174,12 @@ model SymbolProfile { SymbolProfileOverrides SymbolProfileOverrides? @@unique([dataSource, symbol]) + @@index([assetClass]) + @@index([currency]) + @@index([dataSource]) + @@index([isin]) + @@index([name]) + @@index([symbol]) } model SymbolProfileOverrides { @@ -175,12 +202,16 @@ model Subscription { updatedAt DateTime @updatedAt userId String User User @relation(fields: [userId], references: [id]) + + @@index([userId]) } model Tag { id String @id @default(uuid()) name String @unique orders Order[] + + @@index([name]) } model User { @@ -200,6 +231,12 @@ model User { Order Order[] Settings Settings? Subscription Subscription[] + + @@index([accessToken]) + @@index([createdAt]) + @@index([provider]) + @@index([role]) + @@index([thirdPartyId]) } enum AccessPermission {