Thomas Kaul c9353d0a39
Support account balance time series (#2166)
* Initial setup

* Support account balance in export

* Handle account balance update

* Add schema migration

* Update changelog
2023-07-23 15:55:58 +02:00

28 lines
898 B
SQL

-- 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";