mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 09:25:06 +03:00
Organize pg meta queries for studio (#43562)
## Context
We reached to a consensus that we'll keep manually written queries
within the `pg-meta` package
I'll shift queries over in several PRs but wanted to double check if the
changes here is a good folder structure
## Changes involved
- Am organizing dashboard queries in `pg-meta` based on product
- So folder structure will be `/sql/studio/[product]/*.ts`
- Every constant will be exported directly from `pg-meta`'s index
- So consumption in dashboard will just be `import { xxx } from
'@supabase/pg-meta`
cc @avallete and @soedirgo on this one - lemme know if this is alright,
or if there's a preferred way to do this
This commit is contained in:
1 parent
3570abad4d
commit
fc7fb50aa2
20 files changed
+38
-37
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { type OptimizedSearchColumns } from '@supabase/pg-meta'
|
||||
import { BASE_PATH } from 'lib/constants'
|
||||
|
||||
import { PROVIDER_PHONE, PROVIDERS_SCHEMAS } from '../AuthProvidersFormValidation'
|
||||
import { OptimizedSearchColumns } from '@supabase/pg-meta/src/sql/studio/get-users-types'
|
||||
|
||||
export type Filter = 'all' | 'verified' | 'unverified' | 'anonymous'
|
||||
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import { OptimizedSearchColumns } from '@supabase/pg-meta'
|
||||
import { THRESHOLD_COUNT } from '@supabase/pg-meta/src/sql/studio/get-count-estimate'
|
||||
import { keepPreviousData } from '@tanstack/react-query'
|
||||
import { HelpCircle, Loader2 } from 'lucide-react'
|
||||
import { useEffect, useState } from 'react'
|
||||
|
||||
import { OptimizedSearchColumns } from '@supabase/pg-meta/src/sql/studio/get-users-types'
|
||||
import { useParams } from 'common'
|
||||
import { formatEstimatedCount } from 'components/grid/components/footer/pagination/Pagination.utils'
|
||||
import { useUsersCountQuery } from 'data/auth/users-count-query'
|
||||
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
|
||||
import { HelpCircle, Loader2 } from 'lucide-react'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { Button, Tooltip, TooltipContent, TooltipTrigger } from 'ui'
|
||||
import ConfirmationModal from 'ui-patterns/Dialogs/ConfirmationModal'
|
||||
|
||||
import type { Filter, SpecificFilterColumn } from './Users.constants'
|
||||
|
||||
interface UsersFooterProps {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import pgMeta from '@supabase/pg-meta'
|
||||
import type { OptimizedSearchColumns } from '@supabase/pg-meta/src/sql/studio/get-users-types'
|
||||
import { USER_SEARCH_INDEXES } from '@supabase/pg-meta'
|
||||
import type { OptimizedSearchColumns } from '@supabase/pg-meta'
|
||||
import { keepPreviousData, useQueryClient } from '@tanstack/react-query'
|
||||
import AwesomeDebouncePromise from 'awesome-debounce-promise'
|
||||
import { LOCAL_STORAGE_KEYS, useFlag, useParams } from 'common'
|
||||
@@ -246,7 +246,7 @@ export const UsersV2 = () => {
|
||||
const userSearchIndexesAreValidAndReady =
|
||||
!isUserSearchIndexesError &&
|
||||
!isUserSearchIndexesLoading &&
|
||||
userSearchIndexes?.length === pgMeta.USER_SEARCH_INDEXES.length &&
|
||||
userSearchIndexes?.length === USER_SEARCH_INDEXES.length &&
|
||||
userSearchIndexes?.every((index) => index.is_valid && index.is_ready)
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import pgMeta from '@supabase/pg-meta'
|
||||
import { getIndexWorkerStatusSQL } from '@supabase/pg-meta'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
|
||||
import { executeSql, type ExecuteSqlError } from 'data/sql/execute-sql-query'
|
||||
import { UseCustomQueryOptions } from 'types'
|
||||
|
||||
import { authKeys } from './keys'
|
||||
|
||||
type IndexWorkerStatusVariables = {
|
||||
@@ -18,7 +18,7 @@ export async function getIndexWorkerStatus(
|
||||
{ projectRef, connectionString }: IndexWorkerStatusVariables,
|
||||
signal?: AbortSignal
|
||||
): Promise<IndexWorkerStatusData> {
|
||||
const sql = pgMeta.getIndexWorkerStatusSQL()
|
||||
const sql = getIndexWorkerStatusSQL()
|
||||
|
||||
const { result } = await executeSql<IndexWorkerStatusData[]>(
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { OptimizedSearchColumns } from '@supabase/pg-meta/src/sql/studio/get-users-types'
|
||||
import type { OptimizedSearchColumns } from '@supabase/pg-meta'
|
||||
|
||||
export const authKeys = {
|
||||
user: (projectRef: string | undefined, userId?: string | null) =>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { getUserSQL } from '@supabase/pg-meta'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { executeSql, type ExecuteSqlError } from 'data/sql/execute-sql-query'
|
||||
import { UseCustomQueryOptions } from 'types'
|
||||
|
||||
import { getUserSQL } from './auth.sql'
|
||||
import { authKeys } from './keys'
|
||||
import { User } from './users-infinite-query'
|
||||
import { UUID_REGEX } from '@/lib/constants'
|
||||
@@ -21,6 +21,7 @@ export async function getUser(
|
||||
if (!UUID_REGEX.test(userId)) throw new Error('Invalid user ID format')
|
||||
|
||||
const sql = getUserSQL(userId)
|
||||
|
||||
const { result } = await executeSql(
|
||||
{ projectRef, connectionString, sql, queryKey: [`user-${userId}`] },
|
||||
signal
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import pgMeta from '@supabase/pg-meta'
|
||||
import { getIndexStatusesSQL } from '@supabase/pg-meta'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
|
||||
import { executeSql, type ExecuteSqlError } from 'data/sql/execute-sql-query'
|
||||
import { UseCustomQueryOptions } from 'types'
|
||||
|
||||
import { authKeys } from './keys'
|
||||
|
||||
type UsersIndexStatusesVariables = {
|
||||
@@ -20,7 +20,7 @@ export async function getUserIndexStatuses(
|
||||
{ projectRef, connectionString }: UsersIndexStatusesVariables,
|
||||
signal?: AbortSignal
|
||||
): Promise<UsersIndexStatusesData> {
|
||||
const sql = pgMeta.getIndexStatusesSQL()
|
||||
const sql = getIndexStatusesSQL()
|
||||
|
||||
const { result } = await executeSql<UsersIndexStatusesData>(
|
||||
{
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { OptimizedSearchColumns } from '@supabase/pg-meta/src/sql/studio/get-users-types'
|
||||
import { getUsersCountSQL } from '@supabase/pg-meta/src/sql/studio/get-users-count'
|
||||
import type { OptimizedSearchColumns } from '@supabase/pg-meta'
|
||||
import { getUsersCountSQL } from '@supabase/pg-meta'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
|
||||
import { executeSql, type ExecuteSqlError } from 'data/sql/execute-sql-query'
|
||||
import { UseCustomQueryOptions } from 'types'
|
||||
|
||||
import { authKeys } from './keys'
|
||||
import { type Filter } from './users-infinite-query'
|
||||
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
import {
|
||||
getPaginatedUsersSQL,
|
||||
UsersCursor,
|
||||
} from '@supabase/pg-meta/src/sql/studio/get-users-paginated'
|
||||
import { getPaginatedUsersSQL, OptimizedSearchColumns, UsersCursor } from '@supabase/pg-meta'
|
||||
import { InfiniteData, useInfiniteQuery } from '@tanstack/react-query'
|
||||
|
||||
import { OptimizedSearchColumns } from '@supabase/pg-meta/src/sql/studio/get-users-types'
|
||||
import type { components } from 'data/api'
|
||||
import { executeSql, ExecuteSqlError } from 'data/sql/execute-sql-query'
|
||||
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
|
||||
import { PROJECT_STATUS } from 'lib/constants'
|
||||
import { UseCustomInfiniteQueryOptions } from 'types'
|
||||
|
||||
import { authKeys } from './keys'
|
||||
|
||||
const USERS_PAGE_LIMIT = 50
|
||||
|
||||
@@ -17,8 +17,14 @@ import types from './pg-meta-types'
|
||||
import version from './pg-meta-version'
|
||||
import views from './pg-meta-views'
|
||||
import * as query from './query/index'
|
||||
import { getIndexStatusesSQL, USER_SEARCH_INDEXES } from './sql/studio/get-index-statuses'
|
||||
import { getIndexWorkerStatusSQL } from './sql/studio/get-index-worker-status'
|
||||
|
||||
// Studio SQL queries
|
||||
export { getUserSQL } from './sql/studio/auth/get-user'
|
||||
export { getIndexStatusesSQL, USER_SEARCH_INDEXES } from './sql/studio/auth/get-index-statuses'
|
||||
export { getIndexWorkerStatusSQL } from './sql/studio/auth/get-index-worker-status'
|
||||
export { type OptimizedSearchColumns } from './sql/studio/auth/get-users-types'
|
||||
export { getPaginatedUsersSQL, type UsersCursor } from './sql/studio/auth/get-users-paginated'
|
||||
export { getUsersCountSQL } from './sql/studio/auth/get-users-count'
|
||||
|
||||
export default {
|
||||
roles,
|
||||
@@ -40,7 +46,4 @@ export default {
|
||||
indexes,
|
||||
columnPrivileges,
|
||||
query,
|
||||
getIndexWorkerStatusSQL,
|
||||
getIndexStatusesSQL,
|
||||
USER_SEARCH_INDEXES,
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
import { literal } from '../../pg-format'
|
||||
import { literal } from '../../../pg-format'
|
||||
|
||||
export const USER_SEARCH_INDEXES = [
|
||||
'idx_users_email',
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
+2
-2
@@ -1,5 +1,5 @@
|
||||
import { literal } from '../../pg-format'
|
||||
import { COUNT_ESTIMATE_SQL, THRESHOLD_COUNT } from './get-count-estimate'
|
||||
import { literal } from '../../../pg-format'
|
||||
import { COUNT_ESTIMATE_SQL, THRESHOLD_COUNT } from '../get-count-estimate'
|
||||
import { prefixToUUID, stringRange } from './get-users-common'
|
||||
import type { OptimizedSearchColumns } from './get-users-types'
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
import { ident, literal } from '../../pg-format'
|
||||
import { ident, literal } from '../../../pg-format'
|
||||
import { prefixToUUID, stringRange } from './get-users-common'
|
||||
import { OptimizedSearchColumns } from './get-users-types'
|
||||
|
||||
File renamed without changes.
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, test } from 'vitest'
|
||||
|
||||
import { prefixToUUID, stringRange } from '../../../src/sql/studio/get-users-common'
|
||||
import { prefixToUUID, stringRange } from '../../../src/sql/studio/auth/get-users-common'
|
||||
|
||||
describe('prefixToUUID', () => {
|
||||
test('returns UUID template with no prefix', () => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { randomUUID } from 'crypto'
|
||||
import { afterAll, expect, test } from 'vitest'
|
||||
|
||||
import { getUsersCountSQL } from '../../../src/sql/studio/get-users-count'
|
||||
import { getUsersCountSQL } from '../../../src/sql/studio/auth/get-users-count'
|
||||
import { cleanupRoot, createDatabaseWithAuthSchema, createTestDatabase } from '../../db/utils'
|
||||
|
||||
afterAll(async () => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { randomUUID } from 'crypto'
|
||||
import { afterAll, expect, test } from 'vitest'
|
||||
|
||||
import { getPaginatedUsersSQL } from '../../../src/sql/studio/get-users-paginated'
|
||||
import { getPaginatedUsersSQL } from '../../../src/sql/studio/auth/get-users-paginated'
|
||||
import { cleanupRoot, createDatabaseWithAuthSchema, createTestDatabase } from '../../db/utils'
|
||||
|
||||
afterAll(async () => {
|
||||
|
||||
Reference in new issue
Block a user