Skip to content
Merged
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
3 changes: 3 additions & 0 deletions deployment-platforms/railway/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/node_modules
src/generated/prisma/
.env
18 changes: 18 additions & 0 deletions deployment-platforms/railway/README.md
Original file line number Diff line number Diff line change
@@ -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).
19 changes: 19 additions & 0 deletions deployment-platforms/railway/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
Original file line number Diff line number Diff line change
@@ -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;
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 (e.g., Git)
provider = "postgresql"
25 changes: 25 additions & 0 deletions deployment-platforms/railway/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -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])
}
126 changes: 126 additions & 0 deletions deployment-platforms/railway/src/index.ts
Original file line number Diff line number Diff line change
@@ -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 = `
<!DOCTYPE html>
<html>
<head>
<title>Prisma + Railway Example</title>
<style>
body { font-family: Arial, sans-serif; max-width: 800px; margin: 0 auto; padding: 20px; }
h1 { color: #333; }
.endpoint { margin: 10px 0; padding: 10px; background: #f5f5f5; border-radius: 4px; }
button { margin-left: 10px; padding: 4px 8px; cursor: pointer; }
pre { margin-top: 20px; padding: 10px; border: 1px solid #ddd; background: #f9f9f9; }
</style>
</head>
<body>
<h1>API Endpoints</h1>

<div class="endpoint">
<code>GET /api</code>
<button onclick="testEndpoint('/api')">Test</button>
</div>

<div class="endpoint">
<code>GET /api/feed</code>
<button onclick="testEndpoint('/api/feed')">Test</button>
</div>

<div class="endpoint">
<code>GET /api/seed</code>
<button onclick="testEndpoint('/api/seed')">Test</button>
</div>

<pre><code id="result">Click a button to test an endpoint</code></pre>

<script>
async function testEndpoint(endpoint) {
const resultDiv = document.getElementById('result');
resultDiv.textContent = 'Loading...';

try {
const response = await fetch(endpoint);
const data = await response.json();
resultDiv.textContent = JSON.stringify(data, null, 2);
} catch (error) {
resultDiv.textContent = 'Error: ' + error.message;
}
}
</script>
</body>
</html>
`
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: '[email protected]',
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: '[email protected]',
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 at http://localhost:${port}`)

serve({
fetch: app.fetch,
port,
})
14 changes: 14 additions & 0 deletions deployment-platforms/railway/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "Bundler",
"strict": true,
"skipLibCheck": true,
"lib": [
"ESNext"
],
"jsx": "react-jsx",
"jsxImportSource": "hono/jsx"
},
}