Skip to content

Commit 4ddba06

Browse files
author
Lasim
committed
Add check for existing database configuration in setup handler
1 parent 37cb9a9 commit 4ddba06

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

services/backend/src/routes/db/setup.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { type FastifyInstance, type FastifyRequest, type FastifyReply } from 'fastify';
22
import { setupNewDatabase } from '../../db';
3+
import { getDbConfig } from '../../db/config';
34
import {
45
InternalDbConfigSchema,
56
DbSetupRequestBodySchema,
@@ -16,6 +17,13 @@ async function setupDbHandler(
1617
server: FastifyInstance
1718
) {
1819
try {
20+
// Check if DB is already configured
21+
const existingConfig = await getDbConfig();
22+
if (existingConfig) {
23+
server.log.warn('Attempt to set up an already configured database.');
24+
return reply.status(409).send({ message: 'Database setup has already been performed.' });
25+
}
26+
1927
const clientRequestBody = DbSetupRequestBodySchema.parse(request.body);
2028

2129
let internalConfigObject: InternalDbConfig;

0 commit comments

Comments
 (0)