Compare commits

..

3 Commits

Author SHA1 Message Date
github-actions[bot]
e2646cab55 chore: update versions (#2709)
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @nhost/dashboard@1.16.0

### Minor Changes

- c6d5c5c: feat: add toggle switch to enable/disable public access in
the database settings

## @nhost/docs@2.12.0

### Minor Changes

-   d5077c7: feat: added docs about how to connect to postgres

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2024-05-15 09:36:54 +01:00
David Barroso
d5077c7ca4 feat (docs): added docs about how to connect to postgres (#2708) 2024-05-15 10:15:23 +02:00
Hassan Ben Jobrane
c6d5c5cc8c feat: dashboard: add toggle switch to enable/disable database public access (#2707) 2024-05-15 09:12:06 +01:00
12 changed files with 238 additions and 69 deletions

View File

@@ -1,5 +1,11 @@
# @nhost/dashboard
## 1.16.0
### Minor Changes
- c6d5c5c: feat: add toggle switch to enable/disable public access in the database settings
## 1.15.2
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "@nhost/dashboard",
"version": "1.15.2",
"version": "1.16.0",
"private": true,
"scripts": {
"preinstall": "npx only-allow pnpm",

View File

@@ -1,3 +1,7 @@
import { ApplyLocalSettingsDialog } from '@/components/common/ApplyLocalSettingsDialog';
import { useDialog } from '@/components/common/DialogProvider';
import { useUI } from '@/components/common/UIProvider';
import { Form } from '@/components/form/Form';
import { SettingsContainer } from '@/components/layout/SettingsContainer';
import { ActivityIndicator } from '@/components/ui/v2/ActivityIndicator';
import { Alert } from '@/components/ui/v2/Alert';
@@ -7,11 +11,32 @@ import type { InputProps } from '@/components/ui/v2/Input';
import { Input } from '@/components/ui/v2/Input';
import { InputAdornment } from '@/components/ui/v2/InputAdornment';
import { useCurrentWorkspaceAndProject } from '@/features/projects/common/hooks/useCurrentWorkspaceAndProject';
import { useIsPlatform } from '@/features/projects/common/hooks/useIsPlatform';
import { generateAppServiceUrl } from '@/features/projects/common/utils/generateAppServiceUrl';
import { useLocalMimirClient } from '@/hooks/useLocalMimirClient';
import { copy } from '@/utils/copy';
import { useGetPostgresSettingsQuery } from '@/utils/__generated__/graphql';
import { execPromiseWithErrorToast } from '@/utils/execPromiseWithErrorToast';
import {
useGetPostgresSettingsQuery,
useUpdateConfigMutation,
} from '@/utils/__generated__/graphql';
import { yupResolver } from '@hookform/resolvers/yup';
import { FormProvider, useForm } from 'react-hook-form';
import * as Yup from 'yup';
const databasePublicAccessValidationSchema = Yup.object({
enablePublicAccess: Yup.bool(),
});
type DatabasePublicAccessFormValues = Yup.InferType<
typeof databasePublicAccessValidationSchema
>;
export default function DatabaseConnectionInfo() {
const { openDialog } = useDialog();
const isPlatform = useIsPlatform();
const { maintenanceActive } = useUI();
const localMimirClient = useLocalMimirClient();
const { currentProject } = useCurrentWorkspaceAndProject();
const { data, loading, error } = useGetPostgresSettingsQuery({
@@ -19,6 +44,61 @@ export default function DatabaseConnectionInfo() {
fetchPolicy: 'cache-only',
});
const [updateConfig] = useUpdateConfigMutation({
...(!isPlatform ? { client: localMimirClient } : {}),
});
const enablePublicAccess =
!!data?.config?.postgres?.resources?.enablePublicAccess;
const form = useForm<DatabasePublicAccessFormValues>({
reValidateMode: 'onSubmit',
defaultValues: {
enablePublicAccess,
},
resolver: yupResolver(databasePublicAccessValidationSchema),
});
async function handleSubmit(formValues: DatabasePublicAccessFormValues) {
const updateConfigPromise = updateConfig({
variables: {
appId: currentProject.id,
config: {
postgres: {
resources: {
enablePublicAccess: formValues.enablePublicAccess,
},
},
},
},
});
await execPromiseWithErrorToast(
async () => {
await updateConfigPromise;
form.reset(formValues);
if (!isPlatform) {
openDialog({
title: 'Apply your changes',
component: <ApplyLocalSettingsDialog />,
props: {
PaperProps: {
className: 'max-w-2xl',
},
},
});
}
},
{
loadingMessage: 'Database settings are being updated...',
successMessage: 'Database settings have been updated successfully.',
errorMessage:
"An error occurred while trying to update the project's database settings.",
},
);
}
if (loading) {
return (
<ActivityIndicator
@@ -76,49 +156,72 @@ export default function DatabaseConnectionInfo() {
},
];
return (
<SettingsContainer
title="Connection Info"
description="Connect directly to the Postgres database with this information."
slotProps={{ footer: { className: 'hidden' } }}
className="grid grid-cols-6 gap-4 pb-2"
>
{settingsDatabaseCustomInputs.map(
({ name, label, className, value: inputValue }) => (
<Input
key={name}
label={label}
required
disabled
value={inputValue}
className={className}
slotProps={{ inputRoot: { className: '!pr-8 truncate' } }}
fullWidth
hideEmptyHelperText
endAdornment={
<InputAdornment position="end" className="absolute right-2">
<Button
sx={{ minWidth: 0, padding: 0 }}
color="secondary"
variant="borderless"
onClick={(e) => {
e.stopPropagation();
copy(inputValue as string, `${label}`);
}}
>
<CopyIcon className="h-4 w-4" />
</Button>
</InputAdornment>
}
/>
),
)}
const { formState } = form;
<Alert severity="info" className="col-span-6 text-left">
To connect to the Postgres database directly, generate a new password,
securely save it, and then modify your connection string with the newly
created password.
</Alert>
</SettingsContainer>
return (
<FormProvider {...form}>
<Form onSubmit={handleSubmit}>
<SettingsContainer
title="Public access"
description={
enablePublicAccess
? 'Connect directly to the Postgres database with this information.'
: 'Enable public access to your Postgres database.'
}
slotProps={{
submitButton: {
disabled: !formState.isDirty || maintenanceActive,
loading: formState.isSubmitting,
},
}}
className="grid grid-cols-6 gap-4 pb-2"
switchId="enablePublicAccess"
showSwitch
>
{enablePublicAccess && (
<>
{settingsDatabaseCustomInputs.map(
({ name, label, className, value: inputValue }) => (
<Input
key={name}
label={label}
required
disabled
value={inputValue}
className={className}
slotProps={{ inputRoot: { className: '!pr-8 truncate' } }}
fullWidth
hideEmptyHelperText
endAdornment={
<InputAdornment
position="end"
className="absolute right-2"
>
<Button
sx={{ minWidth: 0, padding: 0 }}
color="secondary"
variant="borderless"
onClick={(e) => {
e.stopPropagation();
copy(inputValue as string, `${label}`);
}}
>
<CopyIcon className="w-4 h-4" />
</Button>
</InputAdornment>
}
/>
),
)}
<Alert severity="info" className="col-span-6 text-left">
To connect to the Postgres database directly, generate a new
password, securely save it, and then modify your connection
string with the newly created password.
</Alert>
</>
)}
</SettingsContainer>
</Form>
</FormProvider>
);
}

View File

@@ -13,6 +13,7 @@ query GetPostgresSettings($appId: uuid!) {
storage {
capacity
}
enablePublicAccess
}
}
}

View File

@@ -6,6 +6,7 @@ mutation UpdateConfig($appId: uuid!, $config: ConfigConfigUpdateInput!) {
storage {
capacity
}
enablePublicAccess
}
}
ai {

View File

@@ -1804,6 +1804,7 @@ export type ConfigPostgresInsertInput = {
export type ConfigPostgresResources = {
__typename?: 'ConfigPostgresResources';
compute?: Maybe<ConfigResourcesCompute>;
enablePublicAccess?: Maybe<Scalars['Boolean']>;
networking?: Maybe<ConfigNetworking>;
/** Number of replicas for a service */
replicas?: Maybe<Scalars['ConfigUint8']>;
@@ -1815,6 +1816,7 @@ export type ConfigPostgresResourcesComparisonExp = {
_not?: InputMaybe<ConfigPostgresResourcesComparisonExp>;
_or?: InputMaybe<Array<ConfigPostgresResourcesComparisonExp>>;
compute?: InputMaybe<ConfigResourcesComputeComparisonExp>;
enablePublicAccess?: InputMaybe<ConfigBooleanComparisonExp>;
networking?: InputMaybe<ConfigNetworkingComparisonExp>;
replicas?: InputMaybe<ConfigUint8ComparisonExp>;
storage?: InputMaybe<ConfigPostgresStorageComparisonExp>;
@@ -1822,6 +1824,7 @@ export type ConfigPostgresResourcesComparisonExp = {
export type ConfigPostgresResourcesInsertInput = {
compute?: InputMaybe<ConfigResourcesComputeInsertInput>;
enablePublicAccess?: InputMaybe<Scalars['Boolean']>;
networking?: InputMaybe<ConfigNetworkingInsertInput>;
replicas?: InputMaybe<Scalars['ConfigUint8']>;
storage?: InputMaybe<ConfigPostgresStorageInsertInput>;
@@ -1829,6 +1832,7 @@ export type ConfigPostgresResourcesInsertInput = {
export type ConfigPostgresResourcesUpdateInput = {
compute?: InputMaybe<ConfigResourcesComputeUpdateInput>;
enablePublicAccess?: InputMaybe<Scalars['Boolean']>;
networking?: InputMaybe<ConfigNetworkingUpdateInput>;
replicas?: InputMaybe<Scalars['ConfigUint8']>;
storage?: InputMaybe<ConfigPostgresStorageUpdateInput>;
@@ -2526,6 +2530,7 @@ export type ConfigSystemConfigPostgres = {
database: Scalars['String'];
disk?: Maybe<ConfigSystemConfigPostgresDisk>;
enabled?: Maybe<Scalars['Boolean']>;
majorVersion?: Maybe<Scalars['String']>;
};
export type ConfigSystemConfigPostgresComparisonExp = {
@@ -2536,6 +2541,7 @@ export type ConfigSystemConfigPostgresComparisonExp = {
database?: InputMaybe<ConfigStringComparisonExp>;
disk?: InputMaybe<ConfigSystemConfigPostgresDiskComparisonExp>;
enabled?: InputMaybe<ConfigBooleanComparisonExp>;
majorVersion?: InputMaybe<ConfigStringComparisonExp>;
};
export type ConfigSystemConfigPostgresConnectionString = {
@@ -2599,6 +2605,7 @@ export type ConfigSystemConfigPostgresInsertInput = {
database: Scalars['String'];
disk?: InputMaybe<ConfigSystemConfigPostgresDiskInsertInput>;
enabled?: InputMaybe<Scalars['Boolean']>;
majorVersion?: InputMaybe<Scalars['String']>;
};
export type ConfigSystemConfigPostgresUpdateInput = {
@@ -2606,6 +2613,7 @@ export type ConfigSystemConfigPostgresUpdateInput = {
database?: InputMaybe<Scalars['String']>;
disk?: InputMaybe<ConfigSystemConfigPostgresDiskUpdateInput>;
enabled?: InputMaybe<Scalars['Boolean']>;
majorVersion?: InputMaybe<Scalars['String']>;
};
export type ConfigSystemConfigUpdateInput = {
@@ -2687,14 +2695,6 @@ export type Metrics = {
value: Scalars['float64'];
};
export type StatsDailyLiveFreeApps = {
__typename?: 'StatsDailyLiveFreeApps';
avg: Scalars['Int'];
max: Scalars['Int'];
min: Scalars['Int'];
raw: Array<Scalars['Int']>;
};
export type StatsLiveApps = {
__typename?: 'StatsLiveApps';
appID: Array<Scalars['uuid']>;
@@ -11826,6 +11826,7 @@ export type Mutation_Root = {
billingUpdatePersistentVolume: Scalars['Boolean'];
billingUpdateReports: Scalars['Boolean'];
billingUploadReports: Scalars['Boolean'];
changeDatabaseVersion: Scalars['Boolean'];
/** delete single row from the table: "apps" */
deleteApp?: Maybe<Apps>;
/** delete single row from the table: "app_states" */
@@ -12511,6 +12512,14 @@ export type Mutation_RootBillingUpdateReportsArgs = {
};
/** mutation root */
export type Mutation_RootChangeDatabaseVersionArgs = {
appID: Scalars['uuid'];
force?: InputMaybe<Scalars['Boolean']>;
version: Scalars['String'];
};
/** mutation root */
export type Mutation_RootDeleteAppArgs = {
id: Scalars['uuid'];
@@ -16016,12 +16025,6 @@ export type Query_Root = {
softwareVersions: Array<Software_Versions>;
/** fetch aggregated fields from the table: "software_versions" */
softwareVersionsAggregate: Software_Versions_Aggregate;
/**
* Returns the per-day number of free live apps in the given time range, as well as the min, max and avg.
*
* Requests that returned a 4xx or 5xx status code are not counted as live traffic.
*/
statsDailyLiveFreeApps: StatsDailyLiveFreeApps;
/**
* Returns lists of apps that have some live traffic in the give time range.
* From defaults to 24 hours ago and to defaults to now.
@@ -16031,6 +16034,8 @@ export type Query_Root = {
statsLiveApps: StatsLiveApps;
systemConfig?: Maybe<ConfigSystemConfig>;
systemConfigs: Array<ConfigAppSystemConfig>;
/** Returns system logs for a given application */
systemLogs: Array<Log>;
/** fetch data from the table: "auth.users" using primary key columns */
user?: Maybe<Users>;
/** fetch data from the table: "auth.users" */
@@ -17079,12 +17084,6 @@ export type Query_RootSoftwareVersionsAggregateArgs = {
};
export type Query_RootStatsDailyLiveFreeAppsArgs = {
from?: InputMaybe<Scalars['Timestamp']>;
to?: InputMaybe<Scalars['Timestamp']>;
};
export type Query_RootStatsLiveAppsArgs = {
from?: InputMaybe<Scalars['Timestamp']>;
to?: InputMaybe<Scalars['Timestamp']>;
@@ -17101,6 +17100,14 @@ export type Query_RootSystemConfigsArgs = {
};
export type Query_RootSystemLogsArgs = {
action: Scalars['String'];
appID: Scalars['String'];
from?: InputMaybe<Scalars['Timestamp']>;
to?: InputMaybe<Scalars['Timestamp']>;
};
export type Query_RootUserArgs = {
id: Scalars['uuid'];
};
@@ -22690,7 +22697,7 @@ export type GetPostgresSettingsQueryVariables = Exact<{
}>;
export type GetPostgresSettingsQuery = { __typename?: 'query_root', systemConfig?: { __typename?: 'ConfigSystemConfig', postgres: { __typename?: 'ConfigSystemConfigPostgres', database: string } } | null, config?: { __typename: 'ConfigConfig', id: 'ConfigConfig', postgres?: { __typename?: 'ConfigPostgres', version?: string | null, resources?: { __typename?: 'ConfigPostgresResources', storage?: { __typename?: 'ConfigPostgresStorage', capacity: any } | null } | null } | null } | null };
export type GetPostgresSettingsQuery = { __typename?: 'query_root', systemConfig?: { __typename?: 'ConfigSystemConfig', postgres: { __typename?: 'ConfigSystemConfigPostgres', database: string } } | null, config?: { __typename: 'ConfigConfig', id: 'ConfigConfig', postgres?: { __typename?: 'ConfigPostgres', version?: string | null, resources?: { __typename?: 'ConfigPostgresResources', enablePublicAccess?: boolean | null, storage?: { __typename?: 'ConfigPostgresStorage', capacity: any } | null } | null } | null } | null };
export type ResetDatabasePasswordMutationVariables = Exact<{
appId: Scalars['String'];
@@ -22922,7 +22929,7 @@ export type UpdateConfigMutationVariables = Exact<{
}>;
export type UpdateConfigMutation = { __typename?: 'mutation_root', updateConfig: { __typename?: 'ConfigConfig', id: 'ConfigConfig', postgres?: { __typename?: 'ConfigPostgres', resources?: { __typename?: 'ConfigPostgresResources', storage?: { __typename?: 'ConfigPostgresStorage', capacity: any } | null } | null } | null, ai?: { __typename?: 'ConfigAI', version?: string | null, webhookSecret: string, autoEmbeddings?: { __typename?: 'ConfigAIAutoEmbeddings', synchPeriodMinutes?: any | null } | null, openai: { __typename?: 'ConfigAIOpenai', organization?: string | null, apiKey: string }, resources: { __typename?: 'ConfigAIResources', compute: { __typename?: 'ConfigComputeResources', cpu: any, memory: any } } } | null } };
export type UpdateConfigMutation = { __typename?: 'mutation_root', updateConfig: { __typename?: 'ConfigConfig', id: 'ConfigConfig', postgres?: { __typename?: 'ConfigPostgres', resources?: { __typename?: 'ConfigPostgresResources', enablePublicAccess?: boolean | null, storage?: { __typename?: 'ConfigPostgresStorage', capacity: any } | null } | null } | null, ai?: { __typename?: 'ConfigAI', version?: string | null, webhookSecret: string, autoEmbeddings?: { __typename?: 'ConfigAIAutoEmbeddings', synchPeriodMinutes?: any | null } | null, openai: { __typename?: 'ConfigAIOpenai', organization?: string | null, apiKey: string }, resources: { __typename?: 'ConfigAIResources', compute: { __typename?: 'ConfigComputeResources', cpu: any, memory: any } } } | null } };
export type UnpauseApplicationMutationVariables = Exact<{
appId: Scalars['uuid'];
@@ -24065,6 +24072,7 @@ export const GetPostgresSettingsDocument = gql`
storage {
capacity
}
enablePublicAccess
}
}
}
@@ -25428,6 +25436,7 @@ export const UpdateConfigDocument = gql`
storage {
capacity
}
enablePublicAccess
}
}
ai {

View File

@@ -1,5 +1,11 @@
# @nhost/docs
## 2.12.0
### Minor Changes
- d5077c7: feat: added docs about how to connect to postgres
## 2.11.0
### Minor Changes

View File

@@ -0,0 +1,43 @@
---
title: Accessing the Database
description: How to access the database directly using the connection string
icon: key
---
In most cases you will not need to access the database directly, choosing to interact with the data via the Graphql API, however, if you need direct access to postgres you can access it via the connection string.
# Nhost Run
You can find details on how to connect to the database from an [Nhost Run](/product/run) service [here](/guides/run/networking#connecting-to-the-nhost-stack). If you don't know the password you can set a new password in the dashboard:
**Project Dashboard -> Settings -> Database**
![reset password](/images/guides/database/access/reset.png)
# Public Access
For security reasons, by default your database won't be accessible online. If you need to access it directly from the Internet, first you will need to enable public access (enabling public access will also show the connection details):
<Tabs>
<Tab title="Dashboard">
**Project Dashboard -> Settings -> Database**
![public access](/images/guides/database/access/public.png)
</Tab>
<Tab title="Config">
```toml
[postgres.resources]
enablePublicAccess = true
```
</Tab>
</Tabs>
<Note>
Public access to your database utilizes [pgbouncer](http://www.pgbouncer.org). As this pooler is shared infrastructure the pooler will still be available even if your database has no public access configured. The pooler will simply not have access to your database.
</Note>
# Functions
[Functions](/product/functions) run on a separate network, which means in order to access the database you will first need to [make it public](#public-access).

Binary file not shown.

After

Width:  |  Height:  |  Size: 426 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 382 KiB

View File

@@ -96,7 +96,7 @@
},
{
"group": "Database",
"pages": ["guides/database/configuring-postgres", "guides/database/extensions", "guides/database/performance"]
"pages": ["guides/database/configuring-postgres", "guides/database/access", "guides/database/extensions", "guides/database/performance"]
},
{
"group": "AI",

View File

@@ -1,6 +1,6 @@
{
"name": "@nhost/docs",
"version": "2.11.0",
"version": "2.12.0",
"private": true,
"scripts": {
"start": "mintlify dev"