Skip to content

Commit

Permalink
fix: Fix case where Postgres URL is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
sharat87 committed Feb 7, 2025
1 parent 1b43c4c commit 9ff1b9c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
15 changes: 13 additions & 2 deletions app/client/packages/rts/src/ctl/backup/backup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,19 @@ describe("Backup Tests", () => {
test("Test postgres dump CMD generation", async () => {
const dest = "/dest";
const url = "postgresql://username:password@host/appsmith";
const cmd =
"pg_dump postgresql://username:password@host/appsmith --schema=appsmith --format=custom --file=/dest/pg-data";
const cmd = [
"pg_dump --host=host",
"--port=5432",
"--username=username",
"--dbname=appsmith",
"--schema=appsmith",
"--schema=public",
"--schema=temporal",
"--file=/dest/pg-data.sql",
"--verbose",
"--serializable-deferrable",
].join(" ");

const res = await executePostgresDumpCMD(dest, {
host: "host",
port: 5432,
Expand Down
19 changes: 12 additions & 7 deletions app/client/packages/rts/src/ctl/backup/links/PostgresDumpLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,26 @@ export class PostgresDumpLink implements Link {
}

if (process.env.APPSMITH_KEYCLOAK_DB_URL) {
if (process.env.APPSMITH_KEYCLOAK_DB_URL.startsWith("postgresql://")) {
this.postgresUrl = parsePostgresUrl(
process.env.APPSMITH_KEYCLOAK_DB_URL,
);
} else {
const dbUrlFromEnv = process.env.APPSMITH_KEYCLOAK_DB_URL;

if (dbUrlFromEnv.startsWith("postgresql://")) {
this.postgresUrl = parsePostgresUrl(dbUrlFromEnv);
} else if (dbUrlFromEnv.includes("/")) {
// then it's just the hostname and database in there
const [host, database] =
process.env.APPSMITH_KEYCLOAK_DB_URL.split("/");
const [host, database] = dbUrlFromEnv.split("/");
this.postgresUrl = {
host,
port: 5432,
username: process.env.APPSMITH_KEYCLOAK_DB_USERNAME,
password: process.env.APPSMITH_KEYCLOAK_DB_PASSWORD,
database,
};
} else {
// Identify this as an invalid value for this env variable.
// But we ignore this fact for now, since Postgres itself is not a critical component yet.
console.warn(
"APPSMITH_KEYCLOAK_DB_URL is set, but it doesn't start with postgresql://. This is not a valid value for this env variable. But we ignore this fact for now, since Postgres itself is not a critical component yet.",
);
}
} else if (process.env.APPSMITH_ENABLE_EMBEDDED_DB !== "0") {
this.postgresUrl = {
Expand Down

0 comments on commit 9ff1b9c

Please sign in to comment.