Skip to content

Commit

Permalink
fix(create): Supporting SSL enforced PostgreSQL databases
Browse files Browse the repository at this point in the history
    If a db has mandatory ssl when connecting the current @vendure/create fails.
    Implemented SSL Option for PostgreSQL
    Added SSL option to populate function
  • Loading branch information
tomh4 committed Jun 16, 2024
1 parent 5a38f42 commit 043b6b9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/create/src/gather-user-responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface PromptAnswers {
dbSchema?: string | symbol;
dbUserName: string | symbol;
dbPassword: string | symbol;
dbSSL?: boolean | symbol;
superadminIdentifier: string | symbol;
superadminPassword: string | symbol;
populateProducts: boolean | symbol;
Expand Down Expand Up @@ -72,6 +73,18 @@ export async function gatherUserResponses(
})
: '';
checkCancel(dbSchema);
const dbSSL =
dbType === 'postgres'
? await select({
message: 'Use SSL to connect to the database?',
options: [
{ label: 'no', value: false },
{ label: 'yes', value: true },
],
initialValue: false,
})
: false;
checkCancel(dbSSL);
const dbUserName = hasConnection
? await text({
message: "What's the database user name?",
Expand Down Expand Up @@ -113,6 +126,7 @@ export async function gatherUserResponses(
dbSchema,
dbUserName,
dbPassword,
dbSSL,
superadminIdentifier,
superadminPassword,
populateProducts,
Expand Down
1 change: 1 addition & 0 deletions packages/create/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ async function checkPostgresDbExists(options: any, root: string): Promise<true>
port: options.port,
database: options.database,
schema: options.schema,
ssl: options.ssl,
};
const client = new Client(connectionOptions);

Expand Down
3 changes: 3 additions & 0 deletions packages/create/templates/vendure-config.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ export const config: VendureConfig = {
{{#if dbSchema}}
schema: process.env.DB_SCHEMA,
{{/if}}
{{#if dbSSL}}
ssl: true,
{{/if}}
{{#if isSQLjs}}
location: path.join(__dirname, 'vendure.sqlite'),
autoSave: true,
Expand Down

0 comments on commit 043b6b9

Please sign in to comment.