console: Add readOnly: true in a few places where necessary.

I set up a local PostgreSQL read replica, loaded the Chinook dataset, and poked around finding bugs here and there. I added `read_only: true` to the relevant SQL queries to mitigate these.

I did not test exhaustively or even that well, and I only tried this with PostgreSQL, so I am sure that I have missed some, but this at least seems to make the console's Data tab usable.

Note that this removes the check for the `READ_ONLY_RUN_SQL_QUERIES` feature flag, which seems pointless, as it's checking whether we're running v1.1.0 of the HGE server or later. I sincerely hope no one is actually running such an old version.

If this change is acceptable, we can probably remove the feature flag logic entirely, but that is not something I want to do here.

[DSF-218]: https://hasurahq.atlassian.net/browse/DSF-218?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/8451
Co-authored-by: Luca Restagno <59067245+lucarestagno@users.noreply.github.com>
GitOrigin-RevId: 5f4ebfa8f44e2921071699085b877db78aaa4e24
This commit is contained in:
Samir Talwar 2023-03-28 00:55:17 +02:00 committed by hasura-bot
parent bdfea39de2
commit b167aa84d1
5 changed files with 13 additions and 5 deletions

View File

@ -48,10 +48,6 @@ import {
import { getRunSqlQuery } from '../../Common/utils/v1QueryUtils';
import { services } from '../../../dataSources/services';
import insertReducer from './TableInsertItem/InsertActions';
import {
checkFeatureSupport,
READ_ONLY_RUN_SQL_QUERIES,
} from '../../../helpers/versionUtils';
import { FiRefreshCw } from 'react-icons/fi';
const SET_TABLE = 'Data/SET_TABLE';
@ -1078,7 +1074,7 @@ export const fetchTableIndexDetails = tableInfo => {
dataSource.tableIndexSql({ table, schema }),
currentDataSource,
false,
checkFeatureSupport(READ_ONLY_RUN_SQL_QUERIES) || false
true
);
const options = {
credentials: globalCookiePolicy,

View File

@ -33,6 +33,7 @@ export const runMetadataQuery = async <ResponseType>({
type RunSqlArgs = {
source: Pick<Source, 'kind' | 'name'>;
sql: string;
readOnly?: boolean;
};
export type RunSQLSelectResponse = {
@ -96,9 +97,14 @@ export const runGraphQL = async ({
export const runSQL = async ({
source,
sql,
readOnly,
httpClient,
}: RunSqlArgs & NetworkArgs): Promise<RunSQLResponse> => {
const type = getRunSqlType(source.kind as NativeDrivers);
const readOnlyArg =
readOnly === null || readOnly === undefined ? {} : { read_only: readOnly };
const result = await runQuery<RunSQLResponse>({
httpClient,
body: {
@ -106,6 +112,7 @@ export const runSQL = async ({
args: {
sql,
source: source.name,
...readOnlyArg,
},
},
});

View File

@ -50,6 +50,7 @@ export const getTableColumns = async ({
kind: 'citus',
},
sql,
readOnly: true,
httpClient,
});
@ -106,6 +107,7 @@ export const getTableColumns = async ({
kind: 'postgres',
},
sql: primaryKeySql,
readOnly: true,
httpClient,
});

View File

@ -36,6 +36,7 @@ export const getTableColumns = async ({
kind: 'cockroach',
},
sql,
readOnly: true,
httpClient,
});

View File

@ -48,6 +48,7 @@ export const getTableColumns = async ({
kind: 'postgres',
},
sql,
readOnly: true,
httpClient,
});
@ -105,6 +106,7 @@ export const getTableColumns = async ({
kind: 'postgres',
},
sql: primaryKeySql,
readOnly: true,
httpClient,
});