diff --git a/deployment-platforms/railway/.gitignore b/deployment-platforms/railway/.gitignore new file mode 100644 index 000000000000..47466b149398 --- /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..b3c44e7076dd --- /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 = ` + + +
+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 at 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