-
Notifications
You must be signed in to change notification settings - Fork 1.4k
railway example project #8299
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
Merged
Merged
railway example project #8299
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/node_modules | ||
src/generated/prisma/ | ||
.env |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
}, | ||
aidankmcalister marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"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" | ||
} | ||
aidankmcalister marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
25 changes: 25 additions & 0 deletions
25
deployment-platforms/railway/prisma/migrations/20250905152121_init/migration.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
); | ||
aidankmcalister marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
-- 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; | ||
aidankmcalister marked this conversation as resolved.
Show resolved
Hide resolved
|
3 changes: 3 additions & 0 deletions
3
deployment-platforms/railway/prisma/migrations/migration_lock.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
generator client { | ||
provider = "prisma-client" | ||
aidankmcalister marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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[] | ||
} | ||
aidankmcalister marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
model Post { | ||
authorId Int? | ||
content String? | ||
id Int @id @default(autoincrement()) | ||
published Boolean @default(false) | ||
title String | ||
author User? @relation(fields: [authorId], references: [id]) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
aidankmcalister marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
<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, | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
aidankmcalister marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.