Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: init prisma schema #62

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DATABASE_URL=
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ node_modules

# Local Netlify folder
.netlify
.DS_Store
.DS_Store
34 changes: 34 additions & 0 deletions app/routes/event.$slug.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { LoaderFunctionArgs } from "@remix-run/node";
import { json, useLoaderData } from "@remix-run/react";

import { prisma } from "~/utils/db.server";

export const loader = async ({ params }: LoaderFunctionArgs) => {
if (!params.slug) {
throw new Error("Missing event slug");
}
const event = await prisma.event.findFirst({
where: {
slug: params.slug,
},
});
if (!event) {
throw new Response(null, {
status: 404,
statusText: "Event Not Found",
});
}
return json({ event });
};

export default function Event() {
const { event } = useLoaderData<typeof loader>();
return (
<div className="w-full max-w-6xl mx-auto">
<h1>{event.title}</h1>
<h2>Deskripsi</h2>
<img src={event.imageUrl} alt={event.title} />
<p>{event.description}</p>
</div>
);
}
25 changes: 25 additions & 0 deletions app/utils/db.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { PrismaClient } from "@prisma/client";

let prisma: PrismaClient;

declare global {
var __db__: PrismaClient | undefined; // eslint-disable-line no-var
}

/**
* This is needed because in development we don't want to restart
* the server with every change, but we want to make sure we don't
* create a new connection to the DB with every change either.
* In production, we'll have a single connection to the DB.
*/
if (process.env.NODE_ENV === "production") {
prisma = new PrismaClient();
} else {
if (!global.__db__) {
global.__db__ = new PrismaClient();
}
prisma = global.__db__;
prisma.$connect();
}

export { prisma };
Binary file modified bun.lockb
Binary file not shown.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@fontsource/geist-sans": "^5.0.3",
"@netlify/functions": "^2.6.0",
"@netlify/remix-adapter": "^2.3.1",
"@prisma/client": "^5.18.0",
"@radix-ui/react-avatar": "^1.1.0",
"@radix-ui/react-dialog": "^1.1.1",
"@radix-ui/react-select": "^2.1.1",
Expand All @@ -28,6 +29,7 @@
"dayjs": "^1.11.12",
"isbot": "^4.1.0",
"lucide-react": "^0.403.0",
"prisma": "^5.17.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"simple-icons": "^13.1.0",
Expand Down
22 changes: 22 additions & 0 deletions prisma/migrations/20240819094423_init/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
-- CreateTable
CREATE TABLE "Event" (
"id" TEXT NOT NULL,
"slug" TEXT NOT NULL,
"title" TEXT NOT NULL,
"imageUrl" TEXT NOT NULL,
"dateTimeStart" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"dateTimeEnd" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"url" TEXT NOT NULL,
"description" TEXT NOT NULL,
"locationName" TEXT NOT NULL,
"locationAddress" TEXT NOT NULL,
"agendas" TEXT[],
"registrationInfo" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateIndex
CREATE UNIQUE INDEX "Event_slug_key" ON "Event"("slug");
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"
31 changes: 31 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
provider = "prisma-client-js"
previewFeatures = ["driverAdapters"]
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

model Event {
id String @id @default(cuid())

slug String @unique
title String @db.Text
imageUrl String
dateTimeStart DateTime @default(now())
dateTimeEnd DateTime @default(now())
url String // Url for online or hybrid
description String @db.Text
locationName String
locationAddress String
agendas String[]
registrationInfo String @db.Text

createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
Loading