Skip to content

Commit 40a86c2

Browse files
committed
feat: db prisma migrations
1 parent 9345768 commit 40a86c2

File tree

10 files changed

+193
-244
lines changed

10 files changed

+193
-244
lines changed

.env.example

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
# Prisma
1313
# https://www.prisma.io/docs/reference/database-reference/connection-urls#env
14-
DATABASE_URL="file:./db.sqlite"
14+
DATABASE_URL="file:./db.sqlite" # unnused now for postgres
1515

1616
# Next Auth
1717
# You can generate a new secret on the command line with:
@@ -20,6 +20,10 @@ DATABASE_URL="file:./db.sqlite"
2020
# NEXTAUTH_SECRET=""
2121
NEXTAUTH_URL="http://localhost:3000"
2222

23-
# Next Auth Discord Provider
24-
DISCORD_CLIENT_ID=""
25-
DISCORD_CLIENT_SECRET=""
23+
POSTGRES_URL=
24+
POSTGRES_PRISMA_URL=
25+
POSTGRES_URL_NON_POOLING=
26+
POSTGRES_USER=
27+
POSTGRES_HOST=
28+
POSTGRES_PASSWORD=
29+
POSTGRES_DATABASE=

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"@trpc/next": "^10.33.0",
2424
"@trpc/react-query": "^10.33.0",
2525
"@trpc/server": "^10.33.0",
26+
"@vercel/postgres": "^0.4.0",
2627
"ethers": "^6",
2728
"framer-motion": "^10.12.17",
2829
"next": "^13.4.7",
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
-- CreateTable
2+
CREATE TABLE "Todo" (
3+
"id" TEXT NOT NULL,
4+
"task" TEXT NOT NULL,
5+
"userId" TEXT NOT NULL,
6+
"completed" BOOLEAN NOT NULL DEFAULT false,
7+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
8+
"updatedAt" TIMESTAMP(3) NOT NULL,
9+
10+
CONSTRAINT "Todo_pkey" PRIMARY KEY ("id")
11+
);
12+
13+
-- CreateTable
14+
CREATE TABLE "Account" (
15+
"id" TEXT NOT NULL,
16+
"userId" TEXT NOT NULL,
17+
"type" TEXT NOT NULL,
18+
"provider" TEXT NOT NULL,
19+
"providerAccountId" TEXT NOT NULL,
20+
"refresh_token" TEXT,
21+
"access_token" TEXT,
22+
"expires_at" INTEGER,
23+
"token_type" TEXT,
24+
"scope" TEXT,
25+
"id_token" TEXT,
26+
"session_state" TEXT,
27+
28+
CONSTRAINT "Account_pkey" PRIMARY KEY ("id")
29+
);
30+
31+
-- CreateTable
32+
CREATE TABLE "User" (
33+
"id" TEXT NOT NULL,
34+
"name" TEXT,
35+
"address" TEXT,
36+
"email" TEXT,
37+
"emailVerified" TIMESTAMP(3),
38+
"image" TEXT,
39+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
40+
41+
CONSTRAINT "User_pkey" PRIMARY KEY ("id")
42+
);
43+
44+
-- CreateIndex
45+
CREATE UNIQUE INDEX "Account_provider_providerAccountId_key" ON "Account"("provider", "providerAccountId");
46+
47+
-- CreateIndex
48+
CREATE UNIQUE INDEX "User_address_key" ON "User"("address");
49+
50+
-- CreateIndex
51+
CREATE UNIQUE INDEX "User_email_key" ON "User"("email");
52+
53+
-- AddForeignKey
54+
ALTER TABLE "Todo" ADD CONSTRAINT "Todo_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
55+
56+
-- AddForeignKey
57+
ALTER TABLE "Account" ADD CONSTRAINT "Account_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
58+

prisma/migrations/20230408212409_init/migration.sql

Lines changed: 0 additions & 63 deletions
This file was deleted.

prisma/migrations/20230409205305_create_siwe_structure/migration.sql

Lines changed: 0 additions & 40 deletions
This file was deleted.

prisma/migrations/20230630104642_/migration.sql

Lines changed: 0 additions & 45 deletions
This file was deleted.

prisma/migrations/migration_lock.toml

Lines changed: 0 additions & 3 deletions
This file was deleted.

prisma/schema.prisma

Lines changed: 37 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,51 @@
1-
// This is your Prisma schema file,
2-
// learn more about it in the docs: https://pris.ly/d/prisma-schema
3-
41
generator client {
5-
provider = "prisma-client-js"
2+
provider = "prisma-client-js"
3+
previewFeatures = ["jsonProtocol"]
64
}
75

86
datasource db {
9-
provider = "sqlite"
10-
// NOTE: When using postgresql, mysql or sqlserver, uncomment the @db.Text annotations in model Account below
11-
// Further reading:
12-
// https://next-auth.js.org/adapters/prisma#create-the-prisma-schema
13-
// https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#string
14-
url = env("DATABASE_URL")
7+
provider = "postgresql"
8+
url = env("POSTGRES_PRISMA_URL")
9+
directUrl = env("POSTGRES_URL_NON_POOLING")
10+
shadowDatabaseUrl = env("POSTGRES_URL_NON_POOLING")
1511
}
1612

17-
// Revised Example table
1813
model Todo {
19-
id String @id @default(cuid())
20-
task String
21-
userId String
22-
completed Boolean @default(false)
23-
createdAt DateTime @default(now())
24-
updatedAt DateTime @updatedAt
25-
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
26-
Student Student? @relation(fields: [studentId], references: [id])
27-
studentId String?
14+
id String @id @default(cuid())
15+
task String
16+
userId String
17+
completed Boolean @default(false)
18+
createdAt DateTime @default(now())
19+
updatedAt DateTime @updatedAt
20+
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
2821
}
2922

30-
// Necessary for Next auth
3123
model Account {
32-
id String @id @default(cuid())
33-
userId String
34-
type String
35-
provider String
36-
providerAccountId String
37-
refresh_token String? // @db.Text
38-
access_token String? // @db.Text
39-
expires_at Int?
40-
token_type String?
41-
scope String?
42-
id_token String? // @db.Text
43-
session_state String?
44-
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
45-
Student Student[]
46-
47-
@@unique([provider, providerAccountId])
24+
id String @id @default(cuid())
25+
userId String
26+
type String
27+
provider String
28+
providerAccountId String
29+
refresh_token String?
30+
access_token String?
31+
expires_at Int?
32+
token_type String?
33+
scope String?
34+
id_token String?
35+
session_state String?
36+
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
37+
38+
@@unique([provider, providerAccountId])
4839
}
4940

5041
model User {
51-
id String @id @default(cuid())
52-
name String?
53-
// New address
54-
address String? @unique
55-
email String? @unique
56-
emailVerified DateTime?
57-
image String?
58-
accounts Account[]
59-
todos Todo[]
60-
}
61-
62-
model Student {
63-
id String @id @default(cuid())
64-
account Account @relation(fields: [accountId], references: [id])
65-
accountId String
66-
bio String? @unique
67-
twitter_url String?
68-
github_url String?
69-
image String?
70-
Todo Todo[]
71-
Quizzes Quiz[]
72-
}
73-
74-
model Quiz {
75-
id String @id @default(cuid())
76-
studentId String
77-
Student Student @relation(fields: [studentId], references: [id])
78-
correct_answers Int
79-
incorrect_answers Int
80-
score Int
81-
started_at DateTime
82-
ended_at DateTime
83-
completed Boolean @default(false)
42+
id String @id @default(cuid())
43+
name String?
44+
address String? @unique
45+
email String? @unique
46+
emailVerified DateTime?
47+
image String?
48+
createdAt DateTime @default(now())
49+
accounts Account[]
50+
Todo Todo[]
8451
}

0 commit comments

Comments
 (0)