Next.js Discord

Discord Forum

Postgres database not updating until vercel --prod

Unanswered
Toyger posted this in #help-forum
Open in Discord
ToygerOP
Hello, I've created a Next project to serve an API that connects to Postgres Vercel. I push data to the database like this:

import { sql } from '@vercel/postgres';
import { NextResponse } from 'next/server';

export async function POST(request) {
const { property_name, property_status_code, username } = await request.json();

const statusResult = await sqlSELECT propertystatus_id FROM PropertyStatus WHERE code = ${property_status_code};

if (statusResult.count === 0) {
return NextResponse.json({ error: 'Status not found' }, { status: 404 });
}

const propertystatus_id = statusResult.rows[0].propertystatus_id;

const updateResult = await sqlUPDATE Property SET property_status_id = ${propertystatus_id} WHERE property_name = ${property_name};

if (updateResult.count === 0) {
return NextResponse.json({ error: 'Property not found or update failed' }, { status: 404 });
}

return NextResponse.json({ message: 'Property status updated successfully' }, { status: 200 });
}

The issue is that the query is executed successfully but the new data is not shown when I query the results using my own app or the pgAdmin 4 app.
I can see the new data only when I execute vercel --prod in my Next Project.
The strange thing is that when I use the pgAdmin 4 app to create new records, these are also NOT shown until I run vercel --prod

Any idea of what's causing this?

0 Replies