initial commit

This commit is contained in:
2026-04-03 18:25:54 +01:00
commit 17e26fc87f
35 changed files with 4716 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
-- CreateTable
CREATE TABLE `User` (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`email` VARCHAR(191) NOT NULL,
`name` VARCHAR(191) NULL,
UNIQUE INDEX `User_email_key`(`email`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `Post` (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`title` VARCHAR(191) NOT NULL,
`content` TEXT NULL,
`published` BOOLEAN NOT NULL DEFAULT false,
`authorId` INTEGER NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- AddForeignKey
ALTER TABLE `Post` ADD CONSTRAINT `Post_authorId_fkey` FOREIGN KEY (`authorId`) REFERENCES `User`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

View File

@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (e.g., Git)
provider = "mysql"

43
prisma/schema.prisma Normal file
View File

@@ -0,0 +1,43 @@
generator client {
provider = "prisma-client"
output = "../generated/prisma"
}
datasource db {
provider = "mysql"
}
model Pet {
id Int @id @default(autoincrement())
name String
species String
userId String
posts Post[] // One pet can have many posts
sentRequests Friendship[] @relation("sentRequests")
receivedRequests Friendship[] @relation("receivedRequests")
}
model Friendship {
id Int @id @default(autoincrement())
petId Int
friendId Int
pet Pet @relation("sentRequests", fields: [petId], references: [id])
friend Pet @relation("receivedRequests", fields: [friendId], references: [id])
accepted Boolean @default(false)
createdAt DateTime @default(now())
// 3. Safety: A pet can't friend the same pet twice
@@unique([petId, friendId])
}
model Post {
id Int @id @default(autoincrement())
content String
petId Int @map("pet_id")
pet Pet @relation(fields: [petId], references: [id])
}

95
prisma/seed.ts Normal file
View File

@@ -0,0 +1,95 @@
import { prisma } from '../lib/prisma';
async function main() {
console.log("Begin seeding...");
const userBob = await prisma.pet.create({
data: {
name: "bob",
species: "dog",
userId: "1001",
}
});
const userSam = await prisma.pet.create({
data: {
name: "Sam",
species: "cat",
userId: "1002",
}
});
const userJess = await prisma.pet.create({
data: {
name: "Jess",
species: "dog",
userId: "1003",
}
});
const userSid = await prisma.pet.create({
data: {
name: "sid",
species: "sloth",
userId: "1004",
}
});
const friendShipOne = await prisma.friendship.create({
data: {
petId: userJess.id,
friendId: userSid.id,
accepted: true
}
});
const friendShipTwo = await prisma.friendship.create({
data: {
petId: userJess.id,
friendId: userSam.id,
accepted: true
}
});
const friendShipThree = await prisma.friendship.create({
data: {
petId: userBob.id,
friendId: userSam.id,
accepted: true
}
});
const postOne = await prisma.post.createMany({
data: [{
content: "Hello, I'm bob and this is my first post!",
petId: userBob.id,
},
{
content: "Woof, it's a lovely day to go for a walk!",
petId: userBob.id,
},
{
content: "Hi Everyone, My name is sid, and i'm a lazy sloth",
petId: userSid.id,
},
{
content: "I think we should all dig holes and live underground, screw the sun",
petId: userSam.id,
},
{
content: "That's it, i'm taking a holiday to China! I know they dogs but i'm sure they'll like me",
petId: userSid.id,
}]
})
}
main()
.then(async () => {
await prisma.$disconnect();
})
.catch(async (e) => {
console.error(e);
await prisma.$disconnect();
process.exit(1);
});