-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
setup prisma, setup database, created a database schemas and migrate …
…them using prisma
- Loading branch information
1 parent
c2bb38b
commit d3b4c29
Showing
5 changed files
with
287 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
prisma/migrations/20241224233636_create_models/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
-- CreateEnum | ||
CREATE TYPE "TransactionType" AS ENUM ('INCOME', 'EXPENSE'); | ||
|
||
-- CreateEnum | ||
CREATE TYPE "RecurringInterval" AS ENUM ('DAILY', 'WEEKLY', 'MONTHLY', 'YEARLY'); | ||
|
||
-- CreateEnum | ||
CREATE TYPE "TransactionStatus" AS ENUM ('PENDING', 'COMPLETED', 'FAILED'); | ||
|
||
-- CreateEnum | ||
CREATE TYPE "AccountType" AS ENUM ('CURRENT', 'SAVINGS'); | ||
|
||
-- CreateTable | ||
CREATE TABLE "users" ( | ||
"id" TEXT NOT NULL, | ||
"clerkUserId" TEXT NOT NULL, | ||
"email" TEXT NOT NULL, | ||
"name" TEXT, | ||
"imageUrl" TEXT, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" TIMESTAMP(3) NOT NULL, | ||
|
||
CONSTRAINT "users_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "accounts" ( | ||
"id" TEXT NOT NULL, | ||
"name" TEXT NOT NULL, | ||
"type" "AccountType" NOT NULL, | ||
"balance" DECIMAL(65,30) NOT NULL DEFAULT 0, | ||
"isDefault" BOOLEAN NOT NULL DEFAULT false, | ||
"userId" TEXT NOT NULL, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" TIMESTAMP(3) NOT NULL, | ||
|
||
CONSTRAINT "accounts_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "transactions" ( | ||
"id" TEXT NOT NULL, | ||
"type" "TransactionType" NOT NULL, | ||
"amount" DECIMAL(65,30) NOT NULL, | ||
"description" TEXT, | ||
"date" TIMESTAMP(3) NOT NULL, | ||
"category" TEXT NOT NULL, | ||
"receiptUrl" TEXT, | ||
"isRecurring" BOOLEAN NOT NULL DEFAULT false, | ||
"recurringInterval" "RecurringInterval", | ||
"nextRecurringDate" TIMESTAMP(3), | ||
"lastProcessed" TIMESTAMP(3), | ||
"status" "TransactionStatus" NOT NULL DEFAULT 'COMPLETED', | ||
"userId" TEXT NOT NULL, | ||
"accountId" TEXT NOT NULL, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" TIMESTAMP(3) NOT NULL, | ||
|
||
CONSTRAINT "transactions_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "budgets" ( | ||
"id" TEXT NOT NULL, | ||
"amount" DECIMAL(65,30) NOT NULL, | ||
"lastAlertSent" TIMESTAMP(3), | ||
"userId" TEXT NOT NULL, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" TIMESTAMP(3) NOT NULL, | ||
|
||
CONSTRAINT "budgets_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "users_clerkUserId_key" ON "users"("clerkUserId"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "users_email_key" ON "users"("email"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "accounts_userId_idx" ON "accounts"("userId"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "transactions_userId_idx" ON "transactions"("userId"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "transactions_accountId_idx" ON "transactions"("accountId"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "budgets_userId_key" ON "budgets"("userId"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "budgets_userId_idx" ON "budgets"("userId"); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "accounts" ADD CONSTRAINT "accounts_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "transactions" ADD CONSTRAINT "transactions_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "transactions" ADD CONSTRAINT "transactions_accountId_fkey" FOREIGN KEY ("accountId") REFERENCES "accounts"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "budgets" ADD CONSTRAINT "budgets_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Please do not edit this file manually | ||
# It should be added in your version-control system (e.g., Git) | ||
provider = "postgresql" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
// This is your Prisma schema file, | ||
// learn more about it in the docs: https://pris.ly/d/prisma-schema | ||
|
||
// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions? | ||
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init | ||
|
||
generator client { | ||
provider = "prisma-client-js" | ||
} | ||
|
||
datasource db { | ||
provider = "postgresql" | ||
url = env("DATABASE_URL") | ||
directUrl = env("DIRECT_URL") | ||
} | ||
|
||
model User { | ||
id String @id @default(uuid()) | ||
clerkUserId String @unique // clerk user id | ||
email String @unique | ||
name String? | ||
imageUrl String? | ||
transactions Transaction[] | ||
accounts Account[] | ||
budgets Budget[] | ||
createdAt DateTime @default(now()) | ||
updatedAt DateTime @updatedAt | ||
@@map("users") | ||
} | ||
|
||
model Account { | ||
id String @id @default(uuid()) | ||
name String | ||
type AccountType | ||
balance Decimal @default(0) // will ask inital balance while creating an account | ||
isDefault Boolean @default(false) | ||
userId String | ||
user User @relation(fields: [userId], references: [id], onDelete: Cascade) | ||
transactions Transaction[] | ||
createdAt DateTime @default(now()) | ||
updatedAt DateTime @updatedAt | ||
@@index([userId]) | ||
@@map("accounts") | ||
} | ||
|
||
model Transaction { | ||
id String @id @default(uuid()) | ||
type TransactionType | ||
amount Decimal | ||
description String? | ||
date DateTime | ||
category String | ||
receiptUrl String? | ||
isRecurring Boolean @default(false) // Only used if isRecurring is true | ||
recurringInterval RecurringInterval? | ||
nextRecurringDate DateTime? // Next date for recurring transaction | ||
lastProcessed DateTime? // Last time this recurring transaction was processed | ||
status TransactionStatus @default(COMPLETED) | ||
userId String | ||
user User @relation(fields: [userId], references: [id], onDelete: Cascade) | ||
accountId String | ||
account Account @relation(fields: [accountId], references: [id], onDelete: Cascade) | ||
createdAt DateTime @default(now()) | ||
updatedAt DateTime @updatedAt | ||
@@index([userId]) | ||
@@index([accountId]) | ||
@@map("transactions") | ||
} | ||
|
||
enum TransactionType { | ||
INCOME | ||
EXPENSE | ||
} | ||
|
||
enum RecurringInterval { | ||
DAILY | ||
WEEKLY | ||
MONTHLY | ||
YEARLY | ||
} | ||
|
||
enum TransactionStatus { | ||
PENDING | ||
COMPLETED | ||
FAILED | ||
} | ||
|
||
enum AccountType { | ||
CURRENT | ||
SAVINGS | ||
} | ||
|
||
model Budget { | ||
id String @id @default(uuid()) | ||
amount Decimal | ||
lastAlertSent DateTime? // Track when the last alert was sent | ||
userId String @unique | ||
user User @relation(fields: [userId], references: [id], onDelete: Cascade) | ||
createdAt DateTime @default(now()) | ||
updatedAt DateTime @updatedAt | ||
@@index([userId]) | ||
@@map("budgets") | ||
} |