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

fix: upgrade t3 stack since 10-26-2024 #9

Merged
merged 1 commit into from
Oct 26, 2024
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
10 changes: 7 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
# If you are cloning this repo, create a copy of this file named `.env` and populate it with your secrets.

# The database URL is used to connect to your Supabase database.
POSTGRES_URL="postgres://postgres.[USERNAME]:[PASSWORD]@aws-0-eu-central-1.pooler.supabase.com:6543/postgres?workaround=supabase-pooler.vercel"

DATABASE_URL='mongodb+srv://<username>:<password>@<cluster>/<database>?retryWrites=true&w=majority'

# You can generate the secret via 'openssl rand -base64 32' on Unix
# @see https://next-auth.js.org/configuration/options#secret
Expand All @@ -18,4 +17,9 @@ AUTH_DISCORD_ID=''
AUTH_DISCORD_SECRET=''

# In case you're using the Auth Proxy (apps/auth-proxy)
# AUTH_REDIRECT_PROXY_URL='https://auth.your-server.com/r'
# AUTH_REDIRECT_PROXY_URL='https://auth.your-server.com/r'

# When deploying your application behind a reverse proxy,
# you'll need to set AUTH_TRUST_HOST equal to true
# @see https://authjs.dev/getting-started/deployment#auth_trust_host
AUTH_TRUST_HOST=true
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
>
> Make sure to follow the system requirements specified in [`package.json#engines`](./package.json#L4) before proceeding.

There are two ways of initializing an app using the `create-t3-turbo` starter. You can either use this repository as a template:
There are two ways of initializing an app using the `create-t3-turbo-with-prisma` starter. You can either use this repository as a template:

![use-as-template](https://github.com/t3-oss/create-t3-turbo/assets/51714798/bb6c2e5d-d8b6-416e-aeb3-b3e50e2ca994)

or use Turbo's CLI to init your project (use PNPM as package manager):

```bash
npx create-turbo@latest -e https://github.com/t3-oss/create-t3-turbo
npx create-turbo@latest -e https://github.com/Security2431/create-t3-turbo-with-prisma
```

## About
Expand Down Expand Up @@ -57,7 +57,7 @@ packages
├─ auth
| └─ Authentication using next-auth.
├─ db
| └─ Typesafe db calls using Drizzle & Supabase
| └─ Typesafe db calls using Prisma & MongoDB
└─ ui
└─ Start of a UI package for the webapp using shadcn-ui
tooling
Expand All @@ -76,7 +76,7 @@ tooling
## Quick Start

> **Note**
> The [db](./packages/db) package is preconfigured to use Supabase and is **edge-bound** with the [Vercel Postgres](https://github.com/vercel/storage/tree/main/packages/postgres) driver. If you're using something else, make the necessary modifications to the [schema](./packages/db/src/schema) as well as the [client](./packages/db/src/index.ts) and the [drizzle config](./packages/db/drizzle.config.ts). If you want to switch to non-edge database driver, remove `export const runtime = "edge";` [from all pages and api routes](https://github.com/t3-oss/create-t3-turbo/issues/634#issuecomment-1730240214).
> The [db](./packages/db) package is preconfigured to use [MongoDB](https://www.mongodb.com/) database. If you're using something else, update the schema.prisma provider in [prisma](./packages/db/prisma).

To get it running, follow the steps below:

Expand All @@ -90,7 +90,7 @@ pnpm i
# There is an `.env.example` in the root directory you can use for reference
cp .env.example .env

# Push the Drizzle schema to the database
# Push the Prisma schema to the database
pnpm db:push
```

Expand Down Expand Up @@ -200,7 +200,7 @@ Deploying your Expo application works slightly differently compared to Next.js o

1. Make sure to modify the `getBaseUrl` function to point to your backend's production URL:

<https://github.com/t3-oss/create-t3-turbo/blob/656965aff7db271e5e080242c4a3ce4dad5d25f8/apps/expo/src/utils/api.tsx#L20-L37>
<https://github.com/Security2431/create-t3-turbo-with-prisma/blob/main/apps/expo/src/utils/api.tsx#L20-L40>

2. Let's start by setting up [EAS Build](https://docs.expo.dev/build/introduction), which is short for Expo Application Services. The build service helps you create builds of your app, without requiring a full native development setup. The commands below are a summary of [Creating your first build](https://docs.expo.dev/build/setup).

Expand Down
78 changes: 78 additions & 0 deletions apps/nextjs/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
ARG NODE_VERSION=20
ARG APP_DIRNAME=nextjs
ARG PROJECT=@acme/nextjs

# 1. Alpine image
FROM node:${NODE_VERSION}-alpine AS alpine
RUN apk update
RUN apk add --no-cache libc6-compat

# Setup pnpm and turbo on the alpine base
FROM alpine AS base
RUN corepack enable
# Replace <your-major-version> with the major version installed in your repository. For example:
# RUN npm install [email protected] --global
RUN npm install turbo --global

RUN pnpm config set store-dir ~/.pnpm-store

# 2. Prune projects
FROM base AS pruner
# https://stackoverflow.com/questions/49681984/how-to-get-version-value-of-package-json-inside-of-dockerfile
# RUN export VERSION=$(npm run version)

ARG PROJECT

# Set working directory
WORKDIR /app

# It might be the path to <ROOT> turborepo
COPY . .

# Generate a partial monorepo with a pruned lockfile for a target workspace.
# Assuming "@acme/nextjs" is the name entered in the project's package.json: { name: "@acme/nextjs" }
RUN turbo prune --scope=${PROJECT} --docker

# 3. Build the project
FROM base AS builder
ARG PROJECT

# Environment to skip .env validation on build
ENV CI=true

WORKDIR /app

# Copy lockfile and package.json's of isolated subworkspace
COPY --from=pruner /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
COPY --from=pruner /app/out/pnpm-workspace.yaml ./pnpm-workspace.yaml
COPY --from=pruner /app/out/json/ .

# First install the dependencies (as they change less often)
RUN --mount=type=cache,id=pnpm,target=~/.pnpm-store pnpm install --frozen-lockfile

# Copy source code of isolated subworkspace
COPY --from=pruner /app/out/full/ .

RUN pnpm build --filter=${PROJECT}

# 4. Final image - runner stage to run the application
FROM base AS runner
ARG APP_DIRNAME

# Don't run production as root
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
USER nextjs

WORKDIR /app

ENV NODE_ENV=production

COPY --from=builder --chown=nodejs:nextjs /app .
WORKDIR /app/apps/${APP_DIRNAME}

ARG PORT=3000
ENV PORT=${PORT}
EXPOSE ${PORT}

CMD ["pnpm", "start"]
2 changes: 1 addition & 1 deletion apps/nextjs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ If you are not familiar with the different technologies used in this project, pl

- [Next.js](https://nextjs.org)
- [NextAuth.js](https://next-auth.js.org)
- [Drizzle](https://orm.drizzle.team)
- [Prisma](https://prisma.io)
- [Tailwind CSS](https://tailwindcss.com)
- [tRPC](https://trpc.io)

Expand Down
2 changes: 1 addition & 1 deletion apps/nextjs/src/app/_components/posts.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"use client";

import type { RouterOutputs } from "@acme/api";
import { CreatePostSchema } from "@acme/db/schema";
import { cn } from "@acme/ui";
import { Button } from "@acme/ui/button";
import {
Expand All @@ -14,6 +13,7 @@ import {
} from "@acme/ui/form";
import { Input } from "@acme/ui/input";
import { toast } from "@acme/ui/toast";
import { CreatePostSchema } from "@acme/validators";

import { api } from "~/trpc/react";

Expand Down
2 changes: 1 addition & 1 deletion apps/nextjs/src/app/api/auth/[...nextauth]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { NextRequest, NextResponse } from "next/server";

import { handlers, isSecureContext } from "@acme/auth";

export const runtime = "edge";
// export const runtime = "edge";

const EXPO_COOKIE_NAME = "__acme-expo-redirect-state";
const AUTH_COOKIE_PATTERN = /authjs\.session-token=([^;]+)/;
Expand Down
2 changes: 1 addition & 1 deletion apps/nextjs/src/app/api/trpc/[trpc]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { fetchRequestHandler } from "@trpc/server/adapters/fetch";
import { appRouter, createTRPCContext } from "@acme/api";
import { auth } from "@acme/auth";

export const runtime = "edge";
// export const runtime = "edge";

/**
* Configure basic CORS headers
Expand Down
2 changes: 1 addition & 1 deletion apps/nextjs/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
PostList,
} from "./_components/posts";

export const runtime = "edge";
// export const runtime = "edge";

export default function HomePage() {
// You can await this here if you don't want to show Suspense fallback below
Expand Down
2 changes: 1 addition & 1 deletion apps/nextjs/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const env = createEnv({
* This way you can ensure the app isn't built with invalid env vars.
*/
server: {
POSTGRES_URL: z.string().url(),
DATABASE_URL: z.string().url(),
},

/**
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"build": "turbo run build",
"clean": "git clean -xdf node_modules",
"clean:workspaces": "turbo run clean",
"db:generate": "turbo -F @acme/db generate",
"db:push": "turbo -F @acme/db push",
"db:studio": "turbo -F @acme/db studio",
"dev": "turbo watch dev --continue",
Expand Down
25 changes: 5 additions & 20 deletions packages/api/src/router/post.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,25 @@
import type { TRPCRouterRecord } from "@trpc/server";
import { z } from "zod";

import { desc, eq } from "@acme/db";
import { CreatePostSchema, Post } from "@acme/db/schema";
import { CreatePostSchema } from "@acme/validators";

import { protectedProcedure, publicProcedure } from "../trpc";

export const postRouter = {
all: publicProcedure.query(({ ctx }) => {
// return ctx.db.select().from(schema.post).orderBy(desc(schema.post.id));
return ctx.db.query.Post.findMany({
orderBy: desc(Post.id),
limit: 10,
});
return ctx.db.post.findMany({ orderBy: { id: "desc" } });

Check failure on line 10 in packages/api/src/router/post.ts

View workflow job for this annotation

GitHub Actions / lint

Unsafe return of a value of type `any`

Check failure on line 10 in packages/api/src/router/post.ts

View workflow job for this annotation

GitHub Actions / lint

Unsafe call of a(n) `any` typed value

Check failure on line 10 in packages/api/src/router/post.ts

View workflow job for this annotation

GitHub Actions / lint

Unsafe member access .post on an `any` value
}),

byId: publicProcedure
.input(z.object({ id: z.string() }))
.query(({ ctx, input }) => {
// return ctx.db
// .select()
// .from(schema.post)
// .where(eq(schema.post.id, input.id));

return ctx.db.query.Post.findFirst({
where: eq(Post.id, input.id),
});
return ctx.db.post.findFirst({ where: { id: input.id } });

Check failure on line 15 in packages/api/src/router/post.ts

View workflow job for this annotation

GitHub Actions / lint

Unsafe return of a value of type `any`

Check failure on line 15 in packages/api/src/router/post.ts

View workflow job for this annotation

GitHub Actions / lint

Unsafe call of a(n) `any` typed value

Check failure on line 15 in packages/api/src/router/post.ts

View workflow job for this annotation

GitHub Actions / lint

Unsafe member access .post on an `any` value
}),

create: protectedProcedure
.input(CreatePostSchema)
.mutation(({ ctx, input }) => {
return ctx.db.insert(Post).values(input);
return ctx.db.post.create({ data: input });

Check failure on line 20 in packages/api/src/router/post.ts

View workflow job for this annotation

GitHub Actions / lint

Unsafe return of a value of type `any`

Check failure on line 20 in packages/api/src/router/post.ts

View workflow job for this annotation

GitHub Actions / lint

Unsafe call of a(n) `any` typed value

Check failure on line 20 in packages/api/src/router/post.ts

View workflow job for this annotation

GitHub Actions / lint

Unsafe member access .post on an `any` value
}),

delete: protectedProcedure.input(z.string()).mutation(({ ctx, input }) => {
return ctx.db.delete(Post).where(eq(Post.id, input));
return ctx.db.post.delete({ where: { id: input } });
}),
} satisfies TRPCRouterRecord;
2 changes: 1 addition & 1 deletion packages/api/src/trpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { ZodError } from "zod";

import type { Session } from "@acme/auth";
import { auth, validateToken } from "@acme/auth";
import { db } from "@acme/db/client";
import { db } from "@acme/db";

/**
* Isomorphic Session getter for API requests
Expand Down
2 changes: 1 addition & 1 deletion packages/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"dependencies": {
"@acme/db": "workspace:*",
"@auth/core": "0.34.2",
"@auth/drizzle-adapter": "1.4.2",
"@auth/prisma-adapter": "^2.7.2",
"@t3-oss/env-nextjs": "^0.11.1",
"next": "^14.2.15",
"next-auth": "5.0.0-beta.20",
Expand Down
11 changes: 3 additions & 8 deletions packages/auth/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
Session as NextAuthSession,
} from "next-auth";
import { skipCSRFCheck } from "@auth/core";
import { DrizzleAdapter } from "@auth/drizzle-adapter";
import { PrismaAdapter } from "@auth/prisma-adapter";
import Discord from "next-auth/providers/discord";

import { db } from "@acme/db/client";
import { Account, Session, User } from "@acme/db/schema";
import { db } from "@acme/db";

import { env } from "../env";

Expand All @@ -20,11 +19,7 @@
}
}

const adapter = DrizzleAdapter(db, {
usersTable: User,
accountsTable: Account,
sessionsTable: Session,
});
const adapter = PrismaAdapter(db);

Check failure on line 22 in packages/auth/src/config.ts

View workflow job for this annotation

GitHub Actions / lint

Unsafe argument of type `any` assigned to a parameter of type `PrismaClient<PrismaClientOptions, never, DefaultArgs> | DynamicClientExtensionThis<TypeMap<InternalArgs & InternalArgs<{ [x: string]: { [x: string]: unknown; }; }, { ...; }, { ...; }, { ...; }>, PrismaClientOptions>, TypeMapCb, InternalArgs<...>, {}>`

export const isSecureContext = env.NODE_ENV !== "development";

Expand Down
14 changes: 0 additions & 14 deletions packages/db/drizzle.config.ts

This file was deleted.

24 changes: 10 additions & 14 deletions packages/db/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,38 @@
".": {
"types": "./dist/index.d.ts",
"default": "./src/index.ts"
},
"./client": {
"types": "./dist/client.d.ts",
"default": "./src/client.ts"
},
"./schema": {
"types": "./dist/schema.d.ts",
"default": "./src/schema.ts"
}
},
"license": "MIT",
"prisma": {
"schema": "./src/schema.prisma"
},
"scripts": {
"build": "tsc",
"clean": "git clean -xdf .cache .turbo dist node_modules",
"dev": "tsc",
"format": "prettier --check . --ignore-path ../../.gitignore",
"lint": "eslint",
"push": "pnpm with-env drizzle-kit push",
"studio": "pnpm with-env drizzle-kit studio",
"generate": "pnpm with-env prisma generate",
"push": "pnpm with-env prisma db push --skip-generate",
"studio": "pnpm with-env prisma studio --port 5556",
"typecheck": "tsc --noEmit --emitDeclarationOnly false",
"with-env": "dotenv -e ../../.env --"
},
"dependencies": {
"@vercel/postgres": "^0.10.0",
"drizzle-orm": "^0.35.1",
"drizzle-zod": "^0.5.1",
"@prisma/client": "^5.21.1",
"@prisma/extension-accelerate": "^1.2.1",
"@t3-oss/env-core": "^0.11.1",
"zod": "catalog:"
},
"devDependencies": {
"@acme/eslint-config": "workspace:*",
"@acme/prettier-config": "workspace:*",
"@acme/tsconfig": "workspace:*",
"dotenv-cli": "^7.4.2",
"drizzle-kit": "^0.26.2",
"eslint": "catalog:",
"prettier": "catalog:",
"prisma": "^5.19.1",
"typescript": "catalog:"
},
"prettier": "@acme/prettier-config"
Expand Down
10 changes: 0 additions & 10 deletions packages/db/src/client.ts

This file was deleted.

Loading
Loading