File tree Expand file tree Collapse file tree
migrations/20260201014000-add-query-indexes Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22import { type LoaderFunctionArgs } from 'react-router'
33import { prisma } from '#app/utils/db.server.ts'
44
5- export async function loader ( { request } : LoaderFunctionArgs ) {
6- const host =
7- request . headers . get ( 'X-Forwarded-Host' ) ?? request . headers . get ( 'host' )
8-
5+ export async function loader ( _args : LoaderFunctionArgs ) {
96 try {
10- // if we can connect to the database and make a simple query
11- // and make a HEAD request to ourselves, then we're good.
12- await Promise . all ( [
13- prisma . user . count ( ) ,
14- fetch ( `${ new URL ( request . url ) . protocol } ${ host } ` , {
15- method : 'HEAD' ,
16- headers : { 'X-Healthcheck' : 'true' } ,
17- } ) . then ( ( r ) => {
18- if ( ! r . ok ) return Promise . reject ( r )
19- } ) ,
20- ] )
7+ // If we can connect and run a trivial query, then we're good.
8+ await prisma . $queryRaw `SELECT 1`
219 return new Response ( 'OK' )
2210 } catch ( error : unknown ) {
2311 console . log ( 'healthcheck ❌' , { error } )
Original file line number Diff line number Diff line change @@ -116,18 +116,9 @@ tls_skip_verify = false
116116
117117` ` ` typescript
118118// app/routes/resources/healthcheck.tsx
119- export async function loader({ request }: Route.LoaderArgs) {
120- const host =
121- request.headers.get('X-Forwarded-Host') ?? request.headers.get('host')
122-
119+ export async function loader(_args: Route.LoaderArgs) {
123120 try {
124- await Promise.all([
125- prisma.user.count(), // Verify DB
126- fetch(` ${new URL(request.url).protocol}${host}`, {
127- method: 'HEAD',
128- headers: { 'X-Healthcheck': 'true' },
129- }),
130- ])
121+ await prisma.$queryRaw` SELECT 1` // Verify DB connectivity
131122 return new Response('OK')
132123 } catch (error) {
133124 console.log('healthcheck ❌', { error })
Original file line number Diff line number Diff line change @@ -200,19 +200,10 @@ Resource routes don't render UI; they only return data or perform actions.
200200
201201``` typescript
202202// app/routes/resources/healthcheck.tsx
203- export async function loader({ request } : Route .LoaderArgs ) {
203+ export async function loader(_args : Route .LoaderArgs ) {
204204 // Check application health
205- const host =
206- request .headers .get (' X-Forwarded-Host' ) ?? request .headers .get (' host' )
207-
208205 try {
209- await Promise .all ([
210- prisma .user .count (), // Check DB
211- fetch (` ${new URL (request .url ).protocol }${host } ` , {
212- method: ' HEAD' ,
213- headers: { ' X-Healthcheck' : ' true' },
214- }),
215- ])
206+ await prisma .$queryRaw ` SELECT 1 ` // Check DB connectivity
216207 return new Response (' OK' )
217208 } catch (error ) {
218209 return new Response (' ERROR' , { status: 500 })
Original file line number Diff line number Diff line change 1+ -- CreateIndex
2+ CREATE INDEX "User_stripeId_idx " ON " User" (" stripeId" );
3+
4+ -- CreateIndex
5+ CREATE INDEX "Recipient_verified_disabled_idx " ON " Recipient" (" verified" , " disabled" );
6+
7+ -- CreateIndex
8+ CREATE INDEX "Message_recipientId_sentAt_order_idx " ON " Message" (" recipientId" , " sentAt" , " order" );
Original file line number Diff line number Diff line change @@ -24,6 +24,8 @@ model User {
2424 roles Role []
2525 sessions Session []
2626 recipients Recipient []
27+
28+ @@index ([stripeId ] )
2729}
2830
2931model Password {
@@ -125,6 +127,7 @@ model Recipient {
125127
126128 // non-unique foreign key
127129 @@index ([userId ] )
130+ @@index ([verified , disabled ] )
128131}
129132
130133model Message {
@@ -142,6 +145,7 @@ model Message {
142145
143146 // non-unique foreign key
144147 @@index ([recipientId ] )
148+ @@index ([recipientId , sentAt , order ] )
145149}
146150
147151model SourceNumber {
You can’t perform that action at this time.
0 commit comments