From 99cb613f4c91a8988609c781d5fe7af83b176510 Mon Sep 17 00:00:00 2001 From: Aidan McAlister Date: Fri, 5 Sep 2025 13:33:21 -0400 Subject: [PATCH 1/2] railway example proejct created --- deployment-platforms/railway/.gitignore | 3 + deployment-platforms/railway/README.md | 18 +++ deployment-platforms/railway/package.json | 19 +++ .../20250905152121_init/migration.sql | 25 ++++ .../prisma/migrations/migration_lock.toml | 3 + .../railway/prisma/schema.prisma | 25 ++++ deployment-platforms/railway/src/index.ts | 126 ++++++++++++++++++ deployment-platforms/railway/tsconfig.json | 14 ++ 8 files changed, 233 insertions(+) create mode 100644 deployment-platforms/railway/.gitignore create mode 100644 deployment-platforms/railway/README.md create mode 100644 deployment-platforms/railway/package.json create mode 100644 deployment-platforms/railway/prisma/migrations/20250905152121_init/migration.sql create mode 100644 deployment-platforms/railway/prisma/migrations/migration_lock.toml create mode 100644 deployment-platforms/railway/prisma/schema.prisma create mode 100644 deployment-platforms/railway/src/index.ts create mode 100644 deployment-platforms/railway/tsconfig.json diff --git a/deployment-platforms/railway/.gitignore b/deployment-platforms/railway/.gitignore new file mode 100644 index 000000000000..faa2eb754a49 --- /dev/null +++ b/deployment-platforms/railway/.gitignore @@ -0,0 +1,3 @@ +/node_modules +src/generated/prisma +.env \ No newline at end of file diff --git a/deployment-platforms/railway/README.md b/deployment-platforms/railway/README.md new file mode 100644 index 000000000000..9a8d6e55a0a5 --- /dev/null +++ b/deployment-platforms/railway/README.md @@ -0,0 +1,18 @@ +# Railway deployment example + +[Deployment guide](https://www.prisma.io/docs/guides/deployment/deploying-to-railway) + +## Download manually + +```bash +curl https://codeload.github.com/prisma/prisma-examples/tar.gz/latest | tar -xz --strip=2 prisma-examples-latest/deployment-platforms/railway +cd railway +``` + +## Resources + +- Check out the [Prisma docs](https://www.prisma.io/docs) +- [Join our community on Discord](https://pris.ly/discord?utm_source=github&utm_medium=prisma_examples&utm_content=next_steps_section) to share feedback and interact with other users. +- [Subscribe to our YouTube channel](https://pris.ly/youtube?utm_source=github&utm_medium=prisma_examples&utm_content=next_steps_section) for live demos and video tutorials. +- [Follow us on X](https://pris.ly/x?utm_source=github&utm_medium=prisma_examples&utm_content=next_steps_section) for the latest updates. +- Report issues or ask [questions on GitHub](https://pris.ly/github?utm_source=github&utm_medium=prisma_examples&utm_content=next_steps_section). diff --git a/deployment-platforms/railway/package.json b/deployment-platforms/railway/package.json new file mode 100644 index 000000000000..bb0dc5e985cb --- /dev/null +++ b/deployment-platforms/railway/package.json @@ -0,0 +1,19 @@ +{ + "name": "railway", + "type": "module", + "scripts": { + "dev": "tsx watch src/index.ts", + "start": "tsx src/index.ts" + }, + "dependencies": { + "@hono/node-server": "^1.11.2", + "@prisma/client": "^6.15.0", + "dotenv": "^17.2.2", + "hono": "^4.9.6" + }, + "devDependencies": { + "@types/node": "^22.10.5", + "prisma": "^6.15.0", + "tsx": "^4.20.5" + } +} diff --git a/deployment-platforms/railway/prisma/migrations/20250905152121_init/migration.sql b/deployment-platforms/railway/prisma/migrations/20250905152121_init/migration.sql new file mode 100644 index 000000000000..2aaf2d0054ac --- /dev/null +++ b/deployment-platforms/railway/prisma/migrations/20250905152121_init/migration.sql @@ -0,0 +1,25 @@ +-- CreateTable +CREATE TABLE "public"."User" ( + "email" TEXT NOT NULL, + "id" SERIAL NOT NULL, + "name" TEXT, + + CONSTRAINT "User_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "public"."Post" ( + "authorId" INTEGER, + "content" TEXT, + "id" SERIAL NOT NULL, + "published" BOOLEAN NOT NULL DEFAULT false, + "title" TEXT NOT NULL, + + CONSTRAINT "Post_pkey" PRIMARY KEY ("id") +); + +-- CreateIndex +CREATE UNIQUE INDEX "User_email_key" ON "public"."User"("email"); + +-- AddForeignKey +ALTER TABLE "public"."Post" ADD CONSTRAINT "Post_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "public"."User"("id") ON DELETE SET NULL ON UPDATE CASCADE; diff --git a/deployment-platforms/railway/prisma/migrations/migration_lock.toml b/deployment-platforms/railway/prisma/migrations/migration_lock.toml new file mode 100644 index 000000000000..044d57cdb0d5 --- /dev/null +++ b/deployment-platforms/railway/prisma/migrations/migration_lock.toml @@ -0,0 +1,3 @@ +# Please do not edit this file manually +# It should be added in your version-control system (e.g., Git) +provider = "postgresql" diff --git a/deployment-platforms/railway/prisma/schema.prisma b/deployment-platforms/railway/prisma/schema.prisma new file mode 100644 index 000000000000..a914655c16d1 --- /dev/null +++ b/deployment-platforms/railway/prisma/schema.prisma @@ -0,0 +1,25 @@ +generator client { + provider = "prisma-client" + output = "../src/generated/prisma" +} + +datasource db { + provider = "postgresql" + url = env("DATABASE_URL") +} + +model User { + email String @unique + id Int @id @default(autoincrement()) + name String? + posts Post[] +} + +model Post { + authorId Int? + content String? + id Int @id @default(autoincrement()) + published Boolean @default(false) + title String + author User? @relation(fields: [authorId], references: [id]) +} diff --git a/deployment-platforms/railway/src/index.ts b/deployment-platforms/railway/src/index.ts new file mode 100644 index 000000000000..6f5d934ff126 --- /dev/null +++ b/deployment-platforms/railway/src/index.ts @@ -0,0 +1,126 @@ +import "dotenv/config"; +import { Hono } from "hono"; +import { PrismaClient } from "./generated/prisma/client"; +import { serve } from "@hono/node-server"; + +const prisma = new PrismaClient(); +const app = new Hono(); + +app.get("/", (c) => { + const html = ` + + + + Prisma + Railway Example + + + +

API Endpoints

+ +
+ GET /api + +
+ +
+ GET /api/feed + +
+ +
+ GET /api/seed + +
+ +
Click a button to test an endpoint
+ + + + + `; + return c.html(html); +}); + +app.get("/api", async (c) => { + return c.json({ up: true }); +}); + +app.get("/api/seed", async (c) => { + try { + await prisma.post.deleteMany({}); + await prisma.user.deleteMany({}); + + const author1 = await prisma.user.create({ + data: { + email: "jane@prisma.io", + name: "Jane Doe", + posts: { + create: { + title: "Comparing Database Types", + content: + "https://www.prisma.io/blog/comparison-of-database-models-1iz9u29nwn37/", + published: true, + }, + }, + }, + include: { posts: true }, + }); + + const author2 = await prisma.user.create({ + data: { + email: "john@prisma.io", + name: "John Smith", + posts: { + create: { + title: "Getting Started with Prisma", + content: "https://www.prisma.io/docs/getting-started", + published: true, + }, + }, + }, + include: { posts: true }, + }); + + return c.json({ + message: "Database seeded successfully", + authors: [author1, author2], + }); + } catch (e) { + return c.json({ error: "Failed to seed database" }, 500); + } +}); + +app.get("/api/feed", async (c) => { + const posts = await prisma.post.findMany({ + where: { published: true }, + include: { author: true }, + }); + return c.json(posts); +}); + +const port = process.env.PORT ? Number(process.env.PORT) : 3000; +console.log(`Server is running on port http://localhost:${port}`); + +serve({ + fetch: app.fetch, + port, +}); diff --git a/deployment-platforms/railway/tsconfig.json b/deployment-platforms/railway/tsconfig.json new file mode 100644 index 000000000000..23345376b79c --- /dev/null +++ b/deployment-platforms/railway/tsconfig.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "target": "ESNext", + "module": "ESNext", + "moduleResolution": "Bundler", + "strict": true, + "skipLibCheck": true, + "lib": [ + "ESNext" + ], + "jsx": "react-jsx", + "jsxImportSource": "hono/jsx" + }, +} \ No newline at end of file From d1b5a7b215c99aa9313c5a2f5076e5cdcc9c5791 Mon Sep 17 00:00:00 2001 From: Aidan McAlister Date: Fri, 5 Sep 2025 13:52:16 -0400 Subject: [PATCH 2/2] coderabbit changes --- deployment-platforms/railway/.gitignore | 2 +- deployment-platforms/railway/src/index.ts | 74 +++++++++++------------ 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/deployment-platforms/railway/.gitignore b/deployment-platforms/railway/.gitignore index faa2eb754a49..47466b149398 100644 --- a/deployment-platforms/railway/.gitignore +++ b/deployment-platforms/railway/.gitignore @@ -1,3 +1,3 @@ /node_modules -src/generated/prisma +src/generated/prisma/ .env \ No newline at end of file diff --git a/deployment-platforms/railway/src/index.ts b/deployment-platforms/railway/src/index.ts index 6f5d934ff126..b3c44e7076dd 100644 --- a/deployment-platforms/railway/src/index.ts +++ b/deployment-platforms/railway/src/index.ts @@ -1,12 +1,12 @@ -import "dotenv/config"; -import { Hono } from "hono"; -import { PrismaClient } from "./generated/prisma/client"; -import { serve } from "@hono/node-server"; +import 'dotenv/config' +import { Hono } from 'hono' +import { PrismaClient } from './generated/prisma/client' +import { serve } from '@hono/node-server' -const prisma = new PrismaClient(); -const app = new Hono(); +const prisma = new PrismaClient() +const app = new Hono() -app.get("/", (c) => { +app.get('/', (c) => { const html = ` @@ -56,71 +56,71 @@ app.get("/", (c) => { - `; - return c.html(html); -}); + ` + return c.html(html) +}) -app.get("/api", async (c) => { - return c.json({ up: true }); -}); +app.get('/api', async (c) => { + return c.json({ up: true }) +}) -app.get("/api/seed", async (c) => { +app.get('/api/seed', async (c) => { try { - await prisma.post.deleteMany({}); - await prisma.user.deleteMany({}); + await prisma.post.deleteMany({}) + await prisma.user.deleteMany({}) const author1 = await prisma.user.create({ data: { - email: "jane@prisma.io", - name: "Jane Doe", + email: 'jane@prisma.io', + name: 'Jane Doe', posts: { create: { - title: "Comparing Database Types", + title: 'Comparing Database Types', content: - "https://www.prisma.io/blog/comparison-of-database-models-1iz9u29nwn37/", + 'https://www.prisma.io/blog/comparison-of-database-models-1iz9u29nwn37/', published: true, }, }, }, include: { posts: true }, - }); + }) const author2 = await prisma.user.create({ data: { - email: "john@prisma.io", - name: "John Smith", + email: 'john@prisma.io', + name: 'John Smith', posts: { create: { - title: "Getting Started with Prisma", - content: "https://www.prisma.io/docs/getting-started", + title: 'Getting Started with Prisma', + content: 'https://www.prisma.io/docs/getting-started', published: true, }, }, }, include: { posts: true }, - }); + }) return c.json({ - message: "Database seeded successfully", + message: 'Database seeded successfully', authors: [author1, author2], - }); + }) } catch (e) { - return c.json({ error: "Failed to seed database" }, 500); + return c.json({ error: 'Failed to seed database' }, 500) } -}); +}) -app.get("/api/feed", async (c) => { +app.get('/api/feed', async (c) => { const posts = await prisma.post.findMany({ where: { published: true }, include: { author: true }, - }); - return c.json(posts); -}); + }) + return c.json(posts) +}) -const port = process.env.PORT ? Number(process.env.PORT) : 3000; -console.log(`Server is running on port http://localhost:${port}`); +const port = process.env.PORT ? Number(process.env.PORT) : 3000 +console.log(`Server is running at http://localhost:${port}`) serve({ fetch: app.fetch, port, -}); +})