Skip to content

Commit ce9d138

Browse files
authored
Merge pull request #215 from Miracle656/feature/issue-154-database-setup
feat: Add database setup and schema for User and Preferences (#154)
2 parents a374a84 + af8617c commit ce9d138

File tree

10 files changed

+1055
-638
lines changed

10 files changed

+1055
-638
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ The frontend includes placeholder pages and components for:
3636
# Install dependencies
3737
npm install
3838

39+
# Setup Database
40+
# 1. Ensure you have `.env` file with `DATABASE_URL="file:./dev.db"`
41+
# 2. Run initial Prisma migration
42+
npx prisma migrate dev
43+
3944
# Run development server
4045
npm run dev
4146
```

lib/db.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { PrismaClient } from "@prisma/client";
2+
3+
declare global {
4+
// eslint-disable-next-line no-var
5+
var prisma: PrismaClient | undefined;
6+
}
7+
8+
const prisma = global.prisma || new PrismaClient();
9+
10+
if (process.env.NODE_ENV !== "production") {
11+
global.prisma = prisma;
12+
}
13+
14+
export default prisma;

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"test:e2e": "playwright test"
1111
},
1212
"dependencies": {
13+
"@prisma/client": "^5.22.0",
1314
"@radix-ui/react-icons": "^1.3.2",
1415
"@stellar/stellar-sdk": "^11.2.2",
1516
"clsx": "^2.1.1",
@@ -30,6 +31,7 @@
3031
"eslint": "^9.39.2",
3132
"eslint-config-next": "^16.1.6",
3233
"postcss": "^8.4.0",
34+
"prisma": "^5.22.0",
3335
"tailwindcss": "^3.3.0",
3436
"typescript": "^5.0.0"
3537
}

pnpm-lock.yaml

Lines changed: 968 additions & 638 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

prisma/dev.db

36 KB
Binary file not shown.

prisma/dev.db-journal

8.52 KB
Binary file not shown.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
-- CreateTable
2+
CREATE TABLE "User" (
3+
"id" TEXT NOT NULL PRIMARY KEY,
4+
"stellar_address" TEXT NOT NULL,
5+
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
6+
"updatedAt" DATETIME NOT NULL
7+
);
8+
9+
-- CreateTable
10+
CREATE TABLE "UserPreference" (
11+
"id" TEXT NOT NULL PRIMARY KEY,
12+
"userId" TEXT NOT NULL,
13+
"currency" TEXT NOT NULL DEFAULT 'USD',
14+
"language" TEXT NOT NULL DEFAULT 'en',
15+
"notifications_enabled" BOOLEAN NOT NULL DEFAULT true,
16+
CONSTRAINT "UserPreference_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE CASCADE ON UPDATE CASCADE
17+
);
18+
19+
-- CreateIndex
20+
CREATE UNIQUE INDEX "User_stellar_address_key" ON "User"("stellar_address");
21+
22+
-- CreateIndex
23+
CREATE UNIQUE INDEX "UserPreference_userId_key" ON "UserPreference"("userId");
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Please do not edit this file manually
2+
# It should be added in your version-control system (i.e. Git)
3+
provider = "sqlite"

prisma/schema.prisma

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
datasource db {
2+
provider = "sqlite"
3+
url = env("DATABASE_URL")
4+
}
5+
6+
generator client {
7+
provider = "prisma-client-js"
8+
}
9+
10+
model User {
11+
id String @id @default(cuid())
12+
stellar_address String @unique
13+
createdAt DateTime @default(now())
14+
updatedAt DateTime @updatedAt
15+
preferences UserPreference?
16+
}
17+
18+
model UserPreference {
19+
id String @id @default(cuid())
20+
userId String @unique
21+
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
22+
currency String @default("USD")
23+
language String @default("en")
24+
notifications_enabled Boolean @default(true)
25+
}

prisma_err.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Prisma schema loaded from prisma\schema.prisma.
2+
3+
Error: Prisma schema validation - (validate wasm)
4+
Error code: P1012
5+
error: The datasource property `url` is no longer supported in schema files. Move connection URLs for Migrate to `prisma.config.ts` and pass either `adapter` for a direct database connection or `accelerateUrl` for Accelerate to the `PrismaClient` constructor. See https://pris.ly/d/config-datasource and https://pris.ly/d/prisma7-client-config
6+
--> prisma\schema.prisma:3
7+
|
8+
2 | provider = "sqlite"
9+
3 | url = env("DATABASE_URL")
10+
|
11+
12+
Validation Error Count: 1
13+
[Context: validate]
14+
15+
Prisma CLI Version : 7.4.1

0 commit comments

Comments
 (0)