Compare commits

..

2 Commits

Author SHA1 Message Date
Morten Olsen
130bfec468 fix reconciliation of db 2025-08-11 20:00:01 +02:00
Morten Olsen
ddb3c79657 fix pg db 2025-08-11 15:00:06 +02:00
3 changed files with 8 additions and 3 deletions

View File

@@ -9,6 +9,7 @@ const postgresDatabaseSecretSchema = z.object({
port: z.string(),
user: z.string(),
password: z.string(),
database: z.string().optional(),
});
const postgresDatabaseConnectionSecretSchema = z.object({

View File

@@ -95,6 +95,7 @@ class PostgresDatabaseResource extends CustomResource<typeof postgresDatabaseSpe
port: serverSecretData.data.port,
user: this.#userName,
database: this.#dbName,
...databaseSecretData.data,
};
if (!isDeepSubset(databaseSecretData.data, expectedSecret)) {
@@ -132,7 +133,7 @@ class PostgresDatabaseResource extends CustomResource<typeof postgresDatabaseSpe
};
}
const secretData = postgresDatabaseConnectionSecretSchema.safeParse(decodeSecret(this.#serverSecret.current?.data));
const secretData = postgresDatabaseConnectionSecretSchema.safeParse(decodeSecret(this.#databaseSecret.data));
if (!secretData.success || !secretData.data) {
return {
ready: false,
@@ -145,6 +146,7 @@ class PostgresDatabaseResource extends CustomResource<typeof postgresDatabaseSpe
const database = postgresService.get({
...connectionSecretData.data,
port: connectionSecretData.data.port ? Number(connectionSecretData.data.port) : 5432,
database: connectionSecretData.data.database,
});
await database.upsertRole({
name: secretData.data.user,
@@ -166,8 +168,8 @@ class PostgresDatabaseResource extends CustomResource<typeof postgresDatabaseSpe
}
this.#updateSecret();
await Promise.allSettled([
await this.reconcileSubresource(DATABASE_READY_CONDITION, this.#reconcileDatabase),
await this.reconcileSubresource(SECRET_READY_CONDITION, this.#reconcileSecret),
this.reconcileSubresource(DATABASE_READY_CONDITION, this.#reconcileDatabase),
this.reconcileSubresource(SECRET_READY_CONDITION, this.#reconcileSecret),
]);
const secretReady = this.conditions.get(SECRET_READY_CONDITION)?.status === 'True';

View File

@@ -10,6 +10,7 @@ type PostgresInstanceOptions = {
port?: number;
user: string;
password: string;
database?: string;
};
class PostgresInstance {
@@ -23,6 +24,7 @@ class PostgresInstance {
user: process.env.FORCE_PG_USER ?? options.user,
password: process.env.FORCE_PG_PASSWORD ?? options.password,
port: process.env.FORCE_PG_PORT ? parseInt(process.env.FORCE_PG_PORT) : options.port,
database: options.database,
},
});
}