mirror of https://github.com/ghostfolio/ghostfolio
Browse Source
* Initial setup * Support account balance in export * Handle account balance update * Add schema migration * Update changelogpull/2168/head
Thomas Kaul
2 years ago
committed by
GitHub
12 changed files with 189 additions and 62 deletions
@ -0,0 +1,10 @@ |
|||
import { AccountBalanceService } from '@ghostfolio/api/services/account-balance/account-balance.service'; |
|||
import { PrismaModule } from '@ghostfolio/api/services/prisma/prisma.module'; |
|||
import { Module } from '@nestjs/common'; |
|||
|
|||
@Module({ |
|||
exports: [AccountBalanceService], |
|||
imports: [PrismaModule], |
|||
providers: [AccountBalanceService] |
|||
}) |
|||
export class AccountBalanceModule {} |
@ -0,0 +1,16 @@ |
|||
import { PrismaService } from '@ghostfolio/api/services/prisma/prisma.service'; |
|||
import { Injectable } from '@nestjs/common'; |
|||
import { AccountBalance, Prisma } from '@prisma/client'; |
|||
|
|||
@Injectable() |
|||
export class AccountBalanceService { |
|||
public constructor(private readonly prismaService: PrismaService) {} |
|||
|
|||
public async createAccountBalance( |
|||
data: Prisma.AccountBalanceCreateInput |
|||
): Promise<AccountBalance> { |
|||
return this.prismaService.accountBalance.create({ |
|||
data |
|||
}); |
|||
} |
|||
} |
@ -0,0 +1,27 @@ |
|||
-- CreateTable |
|||
CREATE TABLE "AccountBalance" ( |
|||
"accountId" TEXT NOT NULL, |
|||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, |
|||
"date" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, |
|||
"id" TEXT NOT NULL, |
|||
"updatedAt" TIMESTAMP(3) NOT NULL, |
|||
"userId" TEXT NOT NULL, |
|||
"value" DOUBLE PRECISION NOT NULL, |
|||
|
|||
CONSTRAINT "AccountBalance_pkey" PRIMARY KEY ("id") |
|||
); |
|||
|
|||
-- AddForeignKey |
|||
ALTER TABLE "AccountBalance" ADD CONSTRAINT "AccountBalance_accountId_userId_fkey" FOREIGN KEY ("accountId", "userId") REFERENCES "Account"("id", "userId") ON DELETE CASCADE ON UPDATE CASCADE; |
|||
|
|||
-- Migrate current account balance to time series (AccountBalance[]) |
|||
INSERT INTO "AccountBalance" ("accountId", "createdAt", "date", "id", "updatedAt", "userId", "value") |
|||
SELECT |
|||
"id", |
|||
"updatedAt", |
|||
"updatedAt", |
|||
"id", |
|||
"updatedAt", |
|||
"userId", |
|||
"balance" |
|||
FROM "Account"; |
Loading…
Reference in new issue