diff --git a/frontend/src/lib/components/DBIndexManager.svelte b/frontend/src/lib/components/DBIndexManager.svelte new file mode 100644 index 0000000000..8aa313dc27 --- /dev/null +++ b/frontend/src/lib/components/DBIndexManager.svelte @@ -0,0 +1,358 @@ + + +
+ +
+
+ Indexes + {#if indexes.loading} + + {/if} +
+ + {#if indexes.error} +

{indexes.error}

+ {:else if !indexes.current?.length && !indexes.loading} +

No indexes on this table.

+ {:else} + + + + Name + Definition + Size + + + + + {#each indexes.current ?? [] as idx (idx.name)} + + +
+ {idx.name} +
+ {#if idx.isPrimary} + primary + {/if} + {#if idx.isUnique && !idx.isPrimary} + unique + {/if} + {#if idx.method} + + {idx.method} + + {/if} + {#if !idx.isValid} + invalid + {/if} +
+
+
+ + + {idx.definition} + + + + + {formatIndexSize(idx.sizeBytes)} + + + + {#if idx.backsConstraint} +
+ +
+ {:else} +
+ + +
+ Create index + + + +
+ + + (confirm = undefined)} + > + {#if confirm?.code} +
+ +
{confirm.code}
+
+ {/if} +
+
diff --git a/frontend/src/lib/components/DBManager.svelte b/frontend/src/lib/components/DBManager.svelte index 46177bc494..2f05a96fec 100644 --- a/frontend/src/lib/components/DBManager.svelte +++ b/frontend/src/lib/components/DBManager.svelte @@ -3,6 +3,7 @@ import { ChevronDownIcon, EditIcon, + ListTree, Loader2, Plus, Table2, @@ -14,7 +15,8 @@ import { sendUserToast } from '$lib/toast' import { type ColumnDef } from './apps/components/display/dbtable/utils' import DBTable from './DBTable.svelte' - import type { IDbSchemaOps, IDbTableOps } from './dbOps' + import type { IDbIndexOps, IDbSchemaOps, IDbTableOps } from './dbOps' + import DBIndexManager from './DBIndexManager.svelte' import DropdownV2 from './DropdownV2.svelte' import ConfirmationModal from './common/confirmationModal/ConfirmationModal.svelte' import Button from './common/button/Button.svelte' @@ -48,6 +50,7 @@ colDefs: Record | undefined dbTableOpsFactory: (params: { colDefs: ColumnDef[]; tableKey: string }) => IDbTableOps dbSchemaOps: IDbSchemaOps + dbIndexOps?: IDbIndexOps refresh?: () => void initialSchemaKey?: string initialTableKey?: string @@ -69,6 +72,7 @@ dbSchema, dbTableOpsFactory, dbSchemaOps, + dbIndexOps, dbSupportsSchemas, databaseIsEmpty, colDefs, @@ -232,6 +236,8 @@ } ) + let dbIndexManagerState: { open: boolean; tableKey?: string } = $state({ open: false }) + let newSchemaDialogOpen = $state(false) let newSchemaName = $state('') @@ -513,7 +519,18 @@ alterTableKey: tableKey } } - } + }, + ...(features?.indexes && dbIndexOps + ? [ + { + displayName: 'Manage indexes', + icon: ListTree, + action: () => { + dbIndexManagerState = { open: true, tableKey } + } + } + ] + : []) ]} class="w-fit" btnId={'db-manager-table-actions-' + onlyAlphaNumAndUnderscore(tableKey)} @@ -655,6 +672,30 @@ + (dbIndexManagerState = { open: false })} +> + (dbIndexManagerState = { open: false })} + title={dbIndexManagerState.tableKey ? `Indexes of ${dbIndexManagerState.tableKey}` : 'Indexes'} + > + {#if dbIndexManagerState.tableKey && dbIndexOps} + {@const indexTableKey = dbIndexManagerState.tableKey} + + {/if} + + +