Skip to content

Commit 49f0854

Browse files
committed
update to prisma v6, prisma config, and rust-less prisma
1 parent 927e76b commit 49f0854

File tree

16 files changed

+667
-77
lines changed

16 files changed

+667
-77
lines changed

.dockerignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
2-
Dockerfile
2+
Dockerfile
3+
app/utils/prisma-generated.server

.env.example

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
# We try to mock as much as possible so you don't have to have these set to anything real to contribute
2+
23
# We also only use these variables when you're trying to use the APIs that need them (lazy initialization)
4+
35
# If you need to work on the feature that uses the API, it must be set.
46
# If it's mocked in development, then you can set its value to nonsense.
57
# We'll label them by what feature you need them for and whether it's mocked.
68

79
SENTRY_DSN="https://[email protected]/5878963"
10+
811
SENTRY_AUTH_TOKEN=some_token
912
SENTRY_ORG=some_org
1013
SENTRY_PROJECT=some_project
@@ -13,6 +16,7 @@ SENTRY_PROJECT_ID=5878963
1316
# Feature: /contact and /login
1417
# Mocked: yes
1518
# Check the logs which print out the content of every "email" sent for any manual verification you need to do or links you need to open
19+
1620
MAILGUN_SENDING_KEY=key-some-mailgun-key
1721
MAILGUN_DOMAIN=some.domain.com
1822

@@ -27,13 +31,14 @@ TITO_API_SECRET=secret_live_some_long_thing
2731
# Feature: authentication
2832
# Mocked: Unnecessary (any value can be used)
2933
# Technically we have a fallback in development so this doesn't even need to be set
34+
3035
SESSION_SECRET=anything_works_here
3136
MAGIC_LINK_SECRET=whatever_stuff
3237

3338
# Feature: basically everything
3439
# Mocked: No, must run sqlite locally
3540
DATABASE_FILENAME="sqlite.db"
36-
DATABASE_URL="file:./sqlite.db?connection_limit=1"
41+
DATABASE_URL="file:./prisma/sqlite.db"
3742
CACHE_DATABASE_PATH="other/cache.db"
3843
LITEFS_DIR="./prisma"
3944

@@ -91,4 +96,4 @@ REFRESH_CACHE_SECRET=really_whatever
9196
VERIFIER_API_KEY=some_api_key
9297

9398
# Feature: Cloudflare OAuth
94-
CF_INTERNAL_SECRET=some_long_random_string
99+
CF_INTERNAL_SECRET=some_long_random_string

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ node_modules/
1010
tsconfig.tsbuildinfo
1111
/prisma/sqlite.db
1212
/prisma/sqlite.db-journal
13+
/app/utils/prisma-generated.server
1314

1415
other/postcss.ignored
1516

Dockerfile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ WORKDIR /app/
1616

1717
ADD package.json .npmrc package-lock.json ./
1818
ADD other/patches ./other/patches
19+
ADD prisma /app/prisma
20+
ADD prisma.config.ts /app/prisma.config.ts
1921
RUN npm install
2022

2123
# setup production node_modules
@@ -27,6 +29,7 @@ WORKDIR /app/
2729
COPY --from=deps /app/node_modules /app/node_modules
2830
ADD package.json .npmrc package-lock.json /app/
2931
RUN npm prune --omit=dev
32+
RUN npm rebuild better-sqlite3
3033

3134
# build app
3235
FROM base as build
@@ -44,6 +47,7 @@ ADD other/runfile.js /app/other/runfile.js
4447

4548
# schema doesn't change much so these will stay cached
4649
ADD prisma /app/prisma
50+
ADD prisma.config.ts /app/prisma.config.ts
4751

4852
RUN npx prisma generate
4953

@@ -81,14 +85,14 @@ RUN echo "#!/bin/sh\nset -x\nsqlite3 \$CACHE_DATABASE_PATH" > /usr/local/bin/cac
8185
RUN mkdir /app/
8286
WORKDIR /app/
8387

88+
ADD . .
89+
8490
COPY --from=production-deps /app/node_modules /app/node_modules
85-
COPY --from=build /app/node_modules/.prisma /app/node_modules/.prisma
91+
COPY --from=build /app/app/utils/prisma-generated.server /app/app/utils/prisma-generated.server
8692
COPY --from=build /app/build /app/build
8793
COPY --from=build /app/public /app/public
8894
COPY --from=build /app/server-build /app/server-build
8995

90-
ADD . .
91-
9296
# prepare for litefs
9397
COPY --from=flyio/litefs:0.5.11 /usr/local/bin/litefs /usr/local/bin/litefs
9498
ADD other/litefs.yml /etc/litefs.yml

app/routes/resources+/webauthn+/verify-registration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export async function action({ request }: ActionFunctionArgs) {
8989
data: {
9090
id: credential.id,
9191
aaguid,
92-
publicKey: Buffer.from(credential.publicKey),
92+
publicKey: new Uint8Array(credential.publicKey),
9393
userId: user.id,
9494
webauthnUserId,
9595
counter: credential.counter,

app/utils/prisma.server.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { remember } from '@epic-web/remember'
2-
import { PrismaClient } from '@prisma/client'
2+
import { PrismaBetterSQLite3 } from '@prisma/adapter-better-sqlite3'
33
import chalk from 'chalk'
44
import pProps from 'p-props'
55
import { type Session } from '#app/types.ts'
66
import { ensurePrimary } from '#app/utils/litefs-js.server.ts'
77
import { decrypt, encrypt } from './encryption.server.ts'
8+
import { PrismaClient } from './prisma-generated.server/client.ts'
89
import { time, type Timings } from './timing.server.ts'
910

1011
const logThreshold = 500
@@ -15,7 +16,14 @@ function getClient(): PrismaClient {
1516
// NOTE: during development if you change anything in this function, remember
1617
// that this only runs once per server restart and won't automatically be
1718
// re-run per request like everything else is.
19+
const url = process.env.DATABASE_URL
20+
if (!url) {
21+
throw new Error(
22+
'DATABASE_URL is required (expected a file: URL for SQLite).',
23+
)
24+
}
1825
const client = new PrismaClient({
26+
adapter: new PrismaBetterSQLite3({ url }),
1927
log: [
2028
{ level: 'query', emit: 'event' },
2129
{ level: 'error', emit: 'stdout' },

app/utils/session.server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { type User } from '@prisma/client'
21
import { createCookieSessionStorage, redirect } from '@remix-run/node'
32
import { z } from 'zod'
43
import { ensurePrimary } from '#app/utils/litefs-js.server.ts'
4+
import { type User } from '#app/utils/prisma-generated.server/client.ts'
55
import { getLoginInfoSession } from './login.server.ts'
66
import { getRequiredServerEnvVar } from './misc.tsx'
77
import {

e2e/utils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import path from 'path'
22
import { test as base } from '@playwright/test'
3-
import { PrismaClient, type User } from '@prisma/client'
43
import { parse } from 'cookie'
54
import fsExtra from 'fs-extra'
65
import invariant from 'tiny-invariant'
6+
import {
7+
PrismaClient,
8+
type User,
9+
} from '#app/utils/prisma-generated.server/client.ts'
710
import '../app/entry.server.tsx'
811
import { getSession } from '../app/utils/session.server.ts'
912
import { createUser } from '../prisma/seed-utils.ts'

eslint.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { config as defaultConfig } from '@epic-web/config/eslint'
33
/** @type {import("eslint").Linter.Config[]} */
44
export default [
55
{
6-
ignores: ['./oauth'],
6+
ignores: ['./oauth', './app/utils/prisma-generated.server'],
77
},
88
...defaultConfig,
99
]

0 commit comments

Comments
 (0)