From 3f24a57974ed9730274353340a126e666960e9fd Mon Sep 17 00:00:00 2001 From: Victor Meng Date: Wed, 5 Oct 2022 23:19:24 -0700 Subject: [PATCH] Make PSQL shell work end-to-end --- src/Contracts/DataModels.ts | 1 + .../Controls/Notebook/NotebookTerminalComponent.tsx | 2 +- src/Explorer/Notebook/useNotebook.ts | 10 +++++++--- src/Explorer/Quickstart/PostgreQuickstartCommands.ts | 8 ++++---- src/Explorer/Quickstart/QuickstartGuide.tsx | 11 +++++------ src/Explorer/SplashScreen/SplashScreen.tsx | 6 ++++-- 6 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/Contracts/DataModels.ts b/src/Contracts/DataModels.ts index acf58baaf..d128256c1 100644 --- a/src/Contracts/DataModels.ts +++ b/src/Contracts/DataModels.ts @@ -33,6 +33,7 @@ export interface DatabaseAccountExtendedProperties { privateEndpointConnections?: unknown[]; capacity?: { totalThroughputLimit: number }; locations?: DatabaseAccountResponseLocation[]; + postgresqlEndpoint?: string; } export interface DatabaseAccountResponseLocation { diff --git a/src/Explorer/Controls/Notebook/NotebookTerminalComponent.tsx b/src/Explorer/Controls/Notebook/NotebookTerminalComponent.tsx index e1fe48cbb..082979a23 100644 --- a/src/Explorer/Controls/Notebook/NotebookTerminalComponent.tsx +++ b/src/Explorer/Controls/Notebook/NotebookTerminalComponent.tsx @@ -77,7 +77,7 @@ export class NotebookTerminalComponent extends React.Component = create((set, get) => ({ } const firstWriteLocation = - databaseAccount?.properties?.writeLocations && - databaseAccount?.properties?.writeLocations[0]?.locationName.toLowerCase(); + userContext.apiType === "Postgres" + ? databaseAccount?.location + : databaseAccount?.properties?.writeLocations?.[0]?.locationName.toLowerCase(); const disallowedLocationsUri = `${configContext.BACKEND_ENDPOINT}/api/disallowedLocations`; const authorizationHeader = getAuthorizationHeader(); try { @@ -313,7 +314,10 @@ export const useNotebook: UseStore = create((set, get) => ({ if (dbAccountAllowedInfo.status === HttpStatusCodes.OK) { if (dbAccountAllowedInfo?.type === PhoenixErrorType.PhoenixFlightFallback) { isPhoenixNotebooks = isPublicInternetAllowed && userContext.features.phoenixNotebooks === true; - isPhoenixFeatures = isPublicInternetAllowed && userContext.features.phoenixFeatures === true; + isPhoenixFeatures = + isPublicInternetAllowed && + // phoenix needs to be enabled for Postgres accounts since the PSQL shell requires phoenix containers + (userContext.features.phoenixFeatures === true || userContext.apiType === "Postgres"); } else { isPhoenixNotebooks = isPhoenixFeatures = isPublicInternetAllowed; } diff --git a/src/Explorer/Quickstart/PostgreQuickstartCommands.ts b/src/Explorer/Quickstart/PostgreQuickstartCommands.ts index 0544d068c..d70028885 100644 --- a/src/Explorer/Quickstart/PostgreQuickstartCommands.ts +++ b/src/Explorer/Quickstart/PostgreQuickstartCommands.ts @@ -71,16 +71,16 @@ SELECT create_distributed_table('github_users', 'user_id'); SELECT create_distributed_table('github_events', 'user_id');`; export const loadDataCommand = `SET search_path to cosmosdb_tutorial; -\\COPY github_users FROM PROGRAM 'curl https://examples.citusdata.com/users.csv' WITH (FORMAT CSV) -\\COPY github_events FROM PROGRAM 'curl https://examples.citusdata.com/events.csv' WITH (FORMAT CSV) +\\COPY github_users FROM PROGRAM 'wget -q -O - "$@" "https://examples.citusdata.com/users.csv"' WITH (FORMAT CSV); +\\COPY github_events FROM PROGRAM 'wget -q -O - "$@" "https://examples.citusdata.com/events.csv"' WITH (FORMAT CSV); `; export const loadDataCommandForDisplay = `-- Using schema created for the tutorial SET search_path to cosmosdb_tutorial; -- download users and store in table -\\COPY github_users FROM PROGRAM 'curl https://examples.citusdata.com/users.csv' WITH (FORMAT CSV) -\\COPY github_events FROM PROGRAM 'curl https://examples.citusdata.com/events.csv' WITH (FORMAT CSV)`; +\\COPY github_users FROM PROGRAM 'wget -q -O - "$@" "https://examples.citusdata.com/users.csv"' WITH (FORMAT CSV); +\\COPY github_events FROM PROGRAM 'wget -q -O - "$@" "https://examples.citusdata.com/events.csv"' WITH (FORMAT CSV);`; export const queryCommand = `SET search_path to cosmosdb_tutorial; SELECT count(*) FROM github_users; diff --git a/src/Explorer/Quickstart/QuickstartGuide.tsx b/src/Explorer/Quickstart/QuickstartGuide.tsx index e62aa5007..46ed22d8b 100644 --- a/src/Explorer/Quickstart/QuickstartGuide.tsx +++ b/src/Explorer/Quickstart/QuickstartGuide.tsx @@ -95,7 +95,6 @@ export const QuickstartGuide: React.FC = (): JSX.Element => { Quick start guide - Gettings started in Cosmos DB {currentStep < 5 && ( {
To begin, please enter the cluster's password in the PostgreSQL terminal. - +
{ onClick={() => onCopyBtnClicked("#newTableCommand")} />
- + { onClick={() => onCopyBtnClicked("#distributeTableCommand")} /> - + { onClick={() => onCopyBtnClicked("#loadDataCommand")} /> - + { onClick={() => onCopyBtnClicked("#queryCommand")} /> - + diff --git a/src/Explorer/SplashScreen/SplashScreen.tsx b/src/Explorer/SplashScreen/SplashScreen.tsx index b9c1286b2..e67a169e1 100644 --- a/src/Explorer/SplashScreen/SplashScreen.tsx +++ b/src/Explorer/SplashScreen/SplashScreen.tsx @@ -117,7 +117,9 @@ export class SplashScreen extends React.Component {
- {userContext.apiType === "Postgres" ? "Welcome to Cosmos DB - PostgreSQL" : "Welcome to Cosmos DB"} + {userContext.apiType === "Postgres" + ? "Welcome to Azure Cosmos DB for PostgreSQL" + : "Welcome to Cosmos DB"}
@@ -327,7 +329,7 @@ export class SplashScreen extends React.Component { iconSrc: PowerShellIcon, title: "PostgreSQL Shell", description: "Create table and interact with data using PostgreSQL’s shell interface", - onClick: () => this.container.openNotebookTerminal(TerminalKind.Mongo), + onClick: () => this.container.openNotebookTerminal(TerminalKind.Postgres), }; heroes.push(postgreShellBtn); } else {