Skip to content

Commit

Permalink
database is now seeded succesfully
Browse files Browse the repository at this point in the history
  • Loading branch information
ShubhAgarwal-dev committed Jun 20, 2023
1 parent f2f587c commit c008b0d
Show file tree
Hide file tree
Showing 6 changed files with 308 additions and 16 deletions.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,30 @@ from the creators of Next.js.
Check out our
[Next.js deployment documentation](https://nextjs.org/docs/deployment) for more
details.

## Note

Change `schema.prisma` from

```prisma
model Codeforces {
id Int @id @default(autoincrement())
handle String @unique
rating Int
num_participants Int
member Members @relation(fields: [member_id], references: [id])
member_id String @unique
}
```

to

```prisma
model Codeforces {
id Int @id @default(autoincrement())
handle String @unique
rating Int
member Members @relation(fields: [member_id], references: [id])
member_id String @unique
}
```
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
"lint": "next lint",
"format": "npx prettier --write ."
},
"prisma": {
"seed": "ts-node --compiler-options {\"module\":\"CommonJS\"} prisma/seed.ts"
},
"dependencies": {
"@prisma/client": "^4.16.0",
"@types/node": "20.2.5",
"@prisma/client": "4.15.0",
"@types/node": "^20.3.1",
"@types/react": "18.2.7",
"@types/react-dom": "18.2.4",
"autoprefixer": "10.4.14",
Expand All @@ -25,6 +28,7 @@
"react": "18.2.0",
"react-dom": "18.2.0",
"tailwindcss": "3.3.2",
"ts-node": "^10.9.1",
"typescript": "5.0.4"
},
"devDependencies": {
Expand Down
96 changes: 96 additions & 0 deletions prisma/migrations/20230620181653_init/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
-- CreateEnum
CREATE TYPE "Wing" AS ENUM ('FOSS', 'GAME_DEV', 'CP', 'NETWORKING', 'CYBERSECURITY');

-- CreateEnum
CREATE TYPE "Role" AS ENUM ('DEVELOPER', 'ASSET_DES', 'MUSIC_COMP', 'STORY_WRITING', 'ENV_DES');

-- CreateTable
CREATE TABLE "Members" (
"id" TEXT NOT NULL,
"name" TEXT NOT NULL,
"roll_number" INTEGER NOT NULL,
"wing" "Wing" NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,

CONSTRAINT "Members_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Codeforces" (
"id" SERIAL NOT NULL,
"handle" TEXT NOT NULL,
"rating" INTEGER NOT NULL,
"num_participants" INTEGER NOT NULL,
"member_id" TEXT NOT NULL,

CONSTRAINT "Codeforces_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Leetcode" (
"id" SERIAL NOT NULL,
"handle" TEXT NOT NULL,
"rank" INTEGER NOT NULL,
"solved" INTEGER NOT NULL,
"member_id" TEXT NOT NULL,

CONSTRAINT "Leetcode_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "GameDev" (
"id" SERIAL NOT NULL,
"role" "Role" NOT NULL,
"member_id" TEXT NOT NULL,

CONSTRAINT "GameDev_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "FOSS" (
"id" SERIAL NOT NULL,
"github_uname" TEXT NOT NULL,
"member_id" TEXT NOT NULL,

CONSTRAINT "FOSS_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "Members_roll_number_key" ON "Members"("roll_number");

-- CreateIndex
CREATE INDEX "Members_roll_number_idx" ON "Members"("roll_number");

-- CreateIndex
CREATE UNIQUE INDEX "Codeforces_handle_key" ON "Codeforces"("handle");

-- CreateIndex
CREATE UNIQUE INDEX "Codeforces_member_id_key" ON "Codeforces"("member_id");

-- CreateIndex
CREATE UNIQUE INDEX "Leetcode_handle_key" ON "Leetcode"("handle");

-- CreateIndex
CREATE UNIQUE INDEX "Leetcode_member_id_key" ON "Leetcode"("member_id");

-- CreateIndex
CREATE UNIQUE INDEX "GameDev_member_id_key" ON "GameDev"("member_id");

-- CreateIndex
CREATE UNIQUE INDEX "FOSS_github_uname_key" ON "FOSS"("github_uname");

-- CreateIndex
CREATE UNIQUE INDEX "FOSS_member_id_key" ON "FOSS"("member_id");

-- AddForeignKey
ALTER TABLE "Codeforces" ADD CONSTRAINT "Codeforces_member_id_fkey" FOREIGN KEY ("member_id") REFERENCES "Members"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Leetcode" ADD CONSTRAINT "Leetcode_member_id_fkey" FOREIGN KEY ("member_id") REFERENCES "Members"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "GameDev" ADD CONSTRAINT "GameDev_member_id_fkey" FOREIGN KEY ("member_id") REFERENCES "Members"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "FOSS" ADD CONSTRAINT "FOSS_member_id_fkey" FOREIGN KEY ("member_id") REFERENCES "Members"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
3 changes: 3 additions & 0 deletions prisma/migrations/migration_lock.toml
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 (i.e. Git)
provider = "postgresql"
68 changes: 68 additions & 0 deletions prisma/seed.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,71 @@
import { PrismaClient } from '@prisma/client'

const prisma = new PrismaClient()

async function main() {
const shubh = await prisma.members.upsert({
where: { roll_number: 210020047 },
update: {},
create: {
roll_number: 210020047,
name: 'Shubh Agarwal',
wing: 'FOSS',
leetcode: {
create: {
handle: 'shubhagarwal539',
solved: 83,
rank: 754120,
},
},
foss: {
create: {
github_uname: 'ShubhAgarwal-dev',
},
},
},
})

const saksham = await prisma.members.upsert({
where: { roll_number: 210010046 },
update: {},
create: {
name: 'Saksham Chhimwal',
roll_number: 210010046,
wing: 'FOSS',
codeforces: {
create: {
handle: 'saksham',
rating: 969,
num_participants: 10,
},
},
},
})

const ayush = await prisma.members.upsert({
where: { roll_number: 210020048 },
update: {},
create: {
name: 'Ayush Singhi',
roll_number: 210020048,
wing: 'GAME_DEV',
game_dev: {
create: {
role: 'ASSET_DES',
},
},
},
})

console.log(shubh, saksham, ayush)
}

main()
.then(async () => {
await prisma.$disconnect()
})
.catch(async e => {
console.error(e)
await prisma.$disconnect()
process.exit(1)
})
Loading

0 comments on commit c008b0d

Please sign in to comment.