Skip to content

#8 Fix Startup Issue with Settings#8

Merged
b-at-neu merged 9 commits intodevfrom
copilot/fix-startup-issue-settings
Feb 14, 2026
Merged

#8 Fix Startup Issue with Settings#8
b-at-neu merged 9 commits intodevfrom
copilot/fix-startup-issue-settings

Conversation

Copy link
Copy Markdown

Copilot AI commented Feb 14, 2026

Application crashes on startup with PrismaClientInitializationError when database is unavailable or settings table is empty. The application now fails the deployment immediately to prevent running with an improperly configured database.

Changes

Settings Initialization

  • Simplified getSettings() to basic fetch/create logic without error handling
  • When no settings exist in database, create them with default values
  • Removed all in-memory fallback logic - if database is unavailable, errors propagate naturally and fail the build
  • Removed verbose comments for cleaner code

Before:

try {
  let settings = await db.settings.findFirst();
  if (!settings) {
    settings = await db.settings.create({ data: {...} });
  }
  return settings;
} catch (error) {
  console.error('Error fetching settings:', error);
  return hardcodedDefaults;
}

After:

// In lib/data/settings.ts - no error handling, errors propagate naturally
export const getSettings = cache(async (): Promise<Settings> => {
  let settings = await db.settings.findFirst();
  if (!settings) {
    settings = await db.settings.create({ data: {...} });
  }
  return settings;
});

This ensures deployments only succeed when the database is properly configured and accessible. If the database connection fails, Prisma throws a PrismaClientInitializationError which propagates up and fails the build with clear error messages:

Error [PrismaClientInitializationError]: 
Invalid `prisma.settings.findFirst()` invocation:
Error querying the database: FATAL: Tenant or user not found

The build will exit with code 1, preventing deployment with an improperly configured database.

Original prompt

This section details on the original issue you should resolve

<issue_title>Startup issue with settings</issue_title>
<issue_description>Error querying the database: FATAL: Tenant or user not found
at async (.next/server/chunks/ssr/[root-of-the-server]__72de07ea..js:2:397)
at async e (.next/server/chunks/ssr/[root-of-the-server]__72de07ea.
.js:2:5998) {
clientVersion: '6.18.0',
errorCode: undefined,
retryable: undefined
}
Error fetching settings: Error [PrismaClientInitializationError]:
Invalid prisma.settings.findFirst() invocation:

When there is no settings item found, one should be created with the default settings</issue_description>

Comments on the Issue (you are @copilot in this section)

  • Fixes b-at-neu/senate-path#7

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@vercel
Copy link
Copy Markdown

vercel Bot commented Feb 14, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
senate-path Ready Ready Preview, Comment Feb 14, 2026 6:37pm

Co-authored-by: b-at-neu <144247685+b-at-neu@users.noreply.github.com>
Co-authored-by: b-at-neu <144247685+b-at-neu@users.noreply.github.com>
Co-authored-by: b-at-neu <144247685+b-at-neu@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix startup issue with settings retrieval #0 Fix Startup Issue with Settings Feb 14, 2026
Copilot AI requested a review from b-at-neu February 14, 2026 17:19
@b-at-neu b-at-neu changed the title #0 Fix Startup Issue with Settings #8 Fix Startup Issue with Settings Feb 14, 2026
@b-at-neu
Copy link
Copy Markdown
Collaborator

@copilot its probably actually just a database connection issue. can we just do some general checks if the database connection is present and if its not cancel the entire deployment?

Co-authored-by: b-at-neu <144247685+b-at-neu@users.noreply.github.com>
Copy link
Copy Markdown
Author

Copilot AI commented Feb 14, 2026

@copilot its probably actually just a database connection issue. can we just do some general checks if the database connection is present and if its not cancel the entire deployment?

Changed the approach to fail the deployment when database connection is unavailable. The build will now exit with an error and display clear messages like:

FATAL: Database connection failed. Cannot proceed with deployment.
Database error: Can't reach database server at `localhost:5432`
Please ensure the database is configured correctly and accessible.

All in-memory fallback logic has been removed. If the database isn't properly configured, the deployment will be cancelled. (commit: f577a1e)

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • checkpoint.prisma.io
    • Triggering command: /opt/hostedtoolcache/node/24.13.0/x64/bin/node /opt/hostedtoolcache/node/24.13.0/x64/bin/node /home/REDACTED/work/senate-path/senate-path/node_modules/prisma/build/child {&#34;product&#34;:&#34;prisma&#34;,&#34;version&#34;:&#34;6.18.0&#34;,&#34;cli_install_type&#34;:&#34;local&#34;,&#34;information&#34;:&#34;&#34;,&#34;local_timestamp&#34;:&#34;2026-02-14T17:30:46Z&#34;,&#34;project_hash&#34;:&#34;7e6c9fe6&#34;,&#34;cli_path&#34;:&#34;/home/REDACTED/work/senate-path/senate-path/node_modules/.bin/prisma&#34;,&#34;cli_path_hash&#34;:&#34;8aa2e4f1 (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Co-authored-by: b-at-neu <144247685+b-at-neu@users.noreply.github.com>
Copilot AI changed the title #8 Fix Startup Issue with Settings #8 Fix Startup Issue with Settings - Fail Deployment on Database Connection Error Feb 14, 2026
Comment thread lib/data/settings.ts Outdated
updatedAt: Date;
}

/**
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to change this

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the DEFAULT_SETTINGS_VALUES constant and inlined the values. (commit: ce05fce)

Comment thread lib/data/settings.ts Outdated
customMessage: null,
} as const;

/**
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's get rid of all of these thorough comments

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed all verbose comments from the getSettings function. (commit: ce05fce)

Comment thread lib/data/settings.ts Outdated
} catch (error) {
// Check if this is a database connection error
const isDatabaseConnectionError =
error instanceof PrismaClientInitializationError ||
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check for any kind of database error on startup, not only in the settings. if there ever is a connection error we should immediately kill everything

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created a global database connection check in lib/db.ts with a checkDatabaseConnection() function that's called at app startup via instrumentation.ts. This checks the database connection before any code runs, failing fast if the database is unavailable. (commit: ce05fce)

@b-at-neu
Copy link
Copy Markdown
Collaborator

@copilot changes requested

Co-authored-by: b-at-neu <144247685+b-at-neu@users.noreply.github.com>
Co-authored-by: b-at-neu <144247685+b-at-neu@users.noreply.github.com>
Copy link
Copy Markdown
Author

Copilot AI commented Feb 14, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • checkpoint.prisma.io
    • Triggering command: /opt/hostedtoolcache/node/24.13.0/x64/bin/node /opt/hostedtoolcache/node/24.13.0/x64/bin/node /home/REDACTED/work/senate-path/senate-path/node_modules/prisma/build/child {&#34;product&#34;:&#34;prisma&#34;,&#34;version&#34;:&#34;6.18.0&#34;,&#34;cli_install_type&#34;:&#34;local&#34;,&#34;information&#34;:&#34;&#34;,&#34;local_timestamp&#34;:&#34;2026-02-14T17:53:58Z&#34;,&#34;project_hash&#34;:&#34;7e6c9fe6&#34;,&#34;cli_path&#34;:&#34;/home/REDACTED/work/senate-path/senate-path/node_modules/.bin/prisma&#34;,&#34;cli_path_hash&#34;:&#34;8aa2e4f1 (dns block)
    • Triggering command: /opt/hostedtoolcache/node/24.13.0/x64/bin/node /opt/hostedtoolcache/node/24.13.0/x64/bin/node /home/REDACTED/work/senate-path/senate-path/node_modules/prisma/build/child {&#34;product&#34;:&#34;prisma&#34;,&#34;version&#34;:&#34;6.18.0&#34;,&#34;cli_install_type&#34;:&#34;local&#34;,&#34;information&#34;:&#34;&#34;,&#34;local_timestamp&#34;:&#34;2026-02-14T17:54:00Z&#34;,&#34;project_hash&#34;:&#34;7e6c9fe6&#34;,&#34;cli_path&#34;:&#34;/home/REDACTED/work/senate-path/senate-path/node_modules/.bin/prisma&#34;,&#34;cli_path_hash&#34;:&#34;8aa2e4f1 (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title #8 Fix Startup Issue with Settings - Fail Deployment on Database Connection Error #8 Fix Startup Issue with Settings - Global Database Connection Check Feb 14, 2026
Copilot AI requested a review from b-at-neu February 14, 2026 17:58
Copy link
Copy Markdown
Author

Copilot AI commented Feb 14, 2026

@copilot changes requested

Could you clarify what changes you'd like me to make? I've addressed the previous review comments:

  • Removed the DEFAULT_SETTINGS_VALUES constant
  • Removed verbose comments
  • Added global database connection check at startup

What additional changes would you like?

Comment thread instrumentation.ts Outdated
@@ -0,0 +1,6 @@
export async function register() {
if (process.env.NEXT_RUNTIME === 'nodejs') {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The runtime check prevents the app from running in different environments (Node.js vs Edge). However, we can achieve the same result by simply removing error handling from settings.ts and letting database errors propagate naturally. Would you prefer I remove instrumentation.ts and just let the build fail when getSettings() encounters a database error?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah lets remove the specific check and let them propogate naturally

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed instrumentation.ts and checkDatabaseConnection(). Database errors now propagate naturally from getSettings(), failing the build when database is unavailable. (commit: 00eccf9)

@b-at-neu
Copy link
Copy Markdown
Collaborator

@copilot I'm getting an issue:

Error occurred prerendering page "/not-found". Read more: https://nextjs.org/docs/messages/prerender-error
Error [PrismaClientInitializationError]:
Invalid prisma.settings.findFirst() invocation:
Error querying the database: FATAL: Tenant or user not found
at async (.next/server/chunks/ssr/[root-of-the-server]__72de07ea.
.js:2:393)
at async e (.next/server/chunks/ssr/[root-of-the-server]__72de07ea._.js:2:5749) {
clientVersion: '6.18.0',
errorCode: undefined,
retryable: undefined,
digest: '1001726907'
}
Export encountered an error on /_not-found/page: /_not-found, exiting the build.
⨯ Next.js build worker exited with code: 1 and signal: null
Error: Command "npm run build" exited with 1

Co-authored-by: b-at-neu <144247685+b-at-neu@users.noreply.github.com>
Copy link
Copy Markdown
Author

Copilot AI commented Feb 14, 2026

@copilot I'm getting an issue:

Error occurred prerendering page "/_not-found". Read more: https://nextjs.org/docs/messages/prerender-error
...

This error is expected behavior - the build is correctly failing because the database connection is unavailable. The error message shows:

Error querying the database: FATAL: Tenant or user not found

This means your database credentials or connection string need to be updated. Once the database is properly configured and accessible, the build will succeed and settings will be created automatically if they don't exist. (commit: 00eccf9)

Copilot AI changed the title #8 Fix Startup Issue with Settings - Global Database Connection Check #8 Fix Startup Issue with Settings Feb 14, 2026
@b-at-neu
Copy link
Copy Markdown
Collaborator

@copilot I'm getting an error now that the DB connection is established:

Error occurred prerendering page "/not-found". Read more: https://nextjs.org/docs/messages/prerender-error
Error [PrismaClientKnownRequestError]:
Invalid prisma.settings.findFirst() invocation:
The column settings.endorsementsOpen does not exist in the current database.
at async (.next/server/chunks/ssr/[root-of-the-server]__72de07ea.
.js:2:393)
at async e (.next/server/chunks/ssr/[root-of-the-server]__72de07ea._.js:2:5749) {
code: 'P2022',
meta: [Object],
clientVersion: '6.18.0',
digest: '3333517614'
}
Export encountered an error on /_not-found/page: /_not-found, exiting the build.
⨯ Next.js build worker exited with code: 1 and signal: null
Error: Command "npm run build" exited with 1

are the DB migrations out of sync?

Copy link
Copy Markdown
Author

Copilot AI commented Feb 14, 2026

@copilot I'm getting an error now that the DB connection is established:

Error occurred prerendering page "/_not-found". Read more: https://nextjs.org/docs/messages/prerender-error
...

Yes, the database migrations are out of sync. The schema expects an endorsementsOpen column that doesn't exist in your database yet. You need to apply the pending migrations:

npx prisma migrate deploy

Or if you're in development:

npx prisma migrate dev

The migration that adds this column is 20260205181702_rename_endorsements_closed_to_open which renames endorsementsClosed to endorsementsOpen and inverts the boolean logic.

@b-at-neu b-at-neu marked this pull request as ready for review February 14, 2026 18:38
@b-at-neu b-at-neu merged commit 2cd8d29 into dev Feb 14, 2026
3 checks passed
@b-at-neu b-at-neu deleted the copilot/fix-startup-issue-settings branch February 14, 2026 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Startup issue with settings

2 participants