mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-08-19 08:01:25 +00:00
fix col def
This commit is contained in:
@@ -132,7 +132,6 @@ export async function runDbManagerAlterTableTest(page: Page, dbType: _DbType) {
|
||||
// Bigquery cannot rename a table with primary keys
|
||||
await friendCol.setPrimaryKey(true)
|
||||
await createdAtCol.setPrimaryKey(true)
|
||||
await contentColumn.setPrimaryKey(true)
|
||||
}
|
||||
if (dbFeatures.foreignKeys) await tableEditor.deleteForeignKey()
|
||||
await tableEditor.alterTable()
|
||||
@@ -157,7 +156,7 @@ export async function runDbManagerAlterTableTest(page: Page, dbType: _DbType) {
|
||||
if (dbFeatures.primaryKeys && dbType !== 'bigquery') {
|
||||
await friendCol.checkPrimaryKeyIs(true)
|
||||
await createdAtCol.checkPrimaryKeyIs(true)
|
||||
await contentColumn.checkPrimaryKeyIs(true)
|
||||
await contentColumn.checkPrimaryKeyIs(false)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
dbType: DbType
|
||||
dbSchema: DBSchema
|
||||
dbSupportsSchemas: boolean
|
||||
getColDefs: (tableKey: string) => Promise<ColumnDef[]>
|
||||
colDefs: Record<string, ColumnDef[]> | undefined
|
||||
dbTableOpsFactory: (params: { colDefs: ColumnDef[]; tableKey: string }) => IDbTableOps
|
||||
dbSchemaOps: IDbSchemaOps
|
||||
refresh?: () => void
|
||||
@@ -56,8 +56,8 @@
|
||||
dbSchema,
|
||||
dbTableOpsFactory,
|
||||
dbSchemaOps,
|
||||
getColDefs,
|
||||
dbSupportsSchemas,
|
||||
colDefs,
|
||||
refresh,
|
||||
initialSchemaKey,
|
||||
initialTableKey,
|
||||
@@ -207,10 +207,11 @@
|
||||
if (!table) return
|
||||
let tableKey2 =
|
||||
dbSupportsSchemas && selected.schemaKey ? `${selected.schemaKey}.${table}` : table
|
||||
if (!colDefs?.[tableKey2]) return
|
||||
return await dbSchemaOps.onFetchTableEditorDefinition({
|
||||
table: table,
|
||||
schema: selected.schemaKey,
|
||||
getColDefs: () => getColDefs(tableKey2)
|
||||
colDefs: colDefs[tableKey2]
|
||||
})
|
||||
}
|
||||
)
|
||||
@@ -506,13 +507,9 @@
|
||||
{/if}
|
||||
</Pane>
|
||||
<Pane class="p-3 pt-1">
|
||||
{#if tableKey}
|
||||
{#await getColDefs(tableKey) then colDefs}
|
||||
{#if colDefs && colDefs?.length}
|
||||
{@const dbTableOps = dbTableOpsFactory({ colDefs, tableKey })}
|
||||
<DBTable {dbTableOps} />
|
||||
{/if}
|
||||
{/await}
|
||||
{#if tableKey && colDefs?.[tableKey]?.length}
|
||||
{@const dbTableOps = dbTableOpsFactory({ colDefs: colDefs[tableKey], tableKey })}
|
||||
<DBTable {dbTableOps} />
|
||||
{/if}
|
||||
</Pane>
|
||||
</Splitpanes>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import { dbSchemas, workspaceStore, type DBSchema } from '$lib/stores'
|
||||
import { sendUserToast, sortArray } from '$lib/utils'
|
||||
import { Loader2 } from 'lucide-svelte'
|
||||
import { dbSupportsSchemas, type TableMetadata } from './apps/components/display/dbtable/utils'
|
||||
import { dbSupportsSchemas } from './apps/components/display/dbtable/utils'
|
||||
import DbManager from './DBManager.svelte'
|
||||
import {
|
||||
dbSchemaOpsWithPreviewScripts,
|
||||
@@ -15,14 +15,11 @@
|
||||
import SimpleAgTable from './SimpleAgTable.svelte'
|
||||
import { untrack, type Snippet } from 'svelte'
|
||||
import type { DbInput } from './dbTypes'
|
||||
import {
|
||||
getDbSchemas,
|
||||
loadAllTablesMetaData,
|
||||
loadTableMetaData
|
||||
} from './apps/components/display/dbtable/metadata'
|
||||
import { getDbSchemas, loadAllTablesMetaData } from './apps/components/display/dbtable/metadata'
|
||||
|
||||
import type { SelectedTable } from './DBManager.svelte'
|
||||
import { getDbFeatures } from './apps/components/display/dbtable/dbFeatures'
|
||||
import { resource } from 'runed'
|
||||
|
||||
interface Props {
|
||||
input?: DbInput
|
||||
@@ -90,29 +87,23 @@
|
||||
async function getSchema() {
|
||||
if (!input) return
|
||||
const dbSchemasPath = getDbSchemasPath(input)
|
||||
await Promise.all([
|
||||
(async () => {
|
||||
if ($dbSchemas[dbSchemasPath] && !refreshing) return
|
||||
if ($dbSchemas[dbSchemasPath] && !refreshing) return
|
||||
|
||||
$dbSchemas[dbSchemasPath]
|
||||
if (input.type == 'database') {
|
||||
$dbSchemas[dbSchemasPath] = await getDbSchemas(
|
||||
input.resourceType,
|
||||
input.resourcePath,
|
||||
$workspaceStore,
|
||||
(message: string) => sendUserToast(message, true)
|
||||
)
|
||||
} else if (input.type == 'ducklake') {
|
||||
$dbSchemas[dbSchemasPath] = await getDucklakeSchema({
|
||||
workspace: $workspaceStore!,
|
||||
ducklake: input.ducklake
|
||||
})
|
||||
}
|
||||
|
||||
$dbSchemas[dbSchemasPath]
|
||||
if (input.type == 'database') {
|
||||
$dbSchemas[dbSchemasPath] = await getDbSchemas(
|
||||
input.resourceType,
|
||||
input.resourcePath,
|
||||
$workspaceStore,
|
||||
(message: string) => sendUserToast(message, true)
|
||||
)
|
||||
} else if (input.type == 'ducklake') {
|
||||
$dbSchemas[dbSchemasPath] = await getDucklakeSchema({
|
||||
workspace: $workspaceStore!,
|
||||
ducklake: input.ducklake
|
||||
})
|
||||
}
|
||||
})(),
|
||||
(async () => {
|
||||
cachedColDefs = (await loadAllTablesMetaData($workspaceStore, input)) ?? {}
|
||||
})()
|
||||
])
|
||||
refreshing = false
|
||||
}
|
||||
|
||||
@@ -126,23 +117,13 @@
|
||||
hasReplResult = !!replResultData
|
||||
})
|
||||
|
||||
let cachedColDefs: Record<string, TableMetadata> = {}
|
||||
let cachedLastRefreshCount = 0
|
||||
|
||||
async function getColDefs(tableKey: string): Promise<TableMetadata> {
|
||||
if (cachedLastRefreshCount !== refreshCount) cachedColDefs = {}
|
||||
cachedLastRefreshCount = refreshCount
|
||||
|
||||
if (cachedColDefs[tableKey]) return cachedColDefs[tableKey]
|
||||
if (!input) return []
|
||||
|
||||
if (input?.type == 'ducklake') throw 'Impossible that loadAllTablesMetaData fails for Ducklake'
|
||||
// Query is not implemented for all dbs, need a fallback
|
||||
const result = await loadTableMetaData(input, $workspaceStore, tableKey)
|
||||
|
||||
if (result) cachedColDefs[tableKey] = result
|
||||
return result ?? []
|
||||
}
|
||||
let colDefs = resource(
|
||||
() => [input, refreshCount],
|
||||
async () => {
|
||||
if (!input) return
|
||||
return await loadAllTablesMetaData($workspaceStore, input)
|
||||
}
|
||||
)
|
||||
|
||||
// Export for parent components
|
||||
export function clearReplResult() {
|
||||
@@ -188,7 +169,7 @@
|
||||
<DbManager
|
||||
dbSupportsSchemas={input?.type == 'database' && dbSupportsSchemas(input.resourceType)}
|
||||
{dbSchema}
|
||||
{getColDefs}
|
||||
colDefs={colDefs.current}
|
||||
dbTableOpsFactory={({ colDefs, tableKey }) =>
|
||||
dbTableOpsWithPreviewScripts({
|
||||
colDefs,
|
||||
|
||||
+3
-10
@@ -3,7 +3,6 @@ import { wrapDucklakeQuery } from '$lib/components/ducklake'
|
||||
import { runScriptAndPollResult } from '$lib/components/jobs/utils'
|
||||
import type { ScriptLang } from '$lib/gen'
|
||||
import type { TableEditorForeignKey } from '../tableEditor'
|
||||
import type { TableMetadata } from '../utils'
|
||||
|
||||
/**
|
||||
* Raw foreign key result from database queries
|
||||
@@ -403,12 +402,10 @@ export async function fetchTableRelationalKeys(
|
||||
schema: string | undefined,
|
||||
workspace: string,
|
||||
dbArg: Record<string, any>,
|
||||
language: ScriptLang,
|
||||
getColDefs: () => Promise<TableMetadata>
|
||||
language: ScriptLang
|
||||
): Promise<{
|
||||
foreignKeys: TableEditorForeignKey[]
|
||||
pk_constraint_name?: string
|
||||
colDefs: TableMetadata
|
||||
}> {
|
||||
let fkPromise = async () => {
|
||||
try {
|
||||
@@ -466,11 +463,7 @@ export async function fetchTableRelationalKeys(
|
||||
}
|
||||
}
|
||||
|
||||
const [foreignKeys, pk_constraint_name, colDefs] = await Promise.all([
|
||||
fkPromise(),
|
||||
pkPromise(),
|
||||
getColDefs()
|
||||
])
|
||||
const [foreignKeys, pk_constraint_name] = await Promise.all([fkPromise(), pkPromise()])
|
||||
|
||||
return { foreignKeys, pk_constraint_name, colDefs }
|
||||
return { foreignKeys, pk_constraint_name }
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ export type IDbSchemaOps = {
|
||||
onFetchTableEditorDefinition: (params: {
|
||||
table: string
|
||||
schema?: string
|
||||
getColDefs: () => Promise<TableMetadata>
|
||||
colDefs: TableMetadata
|
||||
}) => Promise<TableEditorValues>
|
||||
}
|
||||
|
||||
@@ -192,16 +192,15 @@ export function dbSchemaOpsWithPreviewScripts({
|
||||
requestBody: { args: { ...dbArg }, language, content: dropSchemaQuery }
|
||||
})
|
||||
},
|
||||
onFetchTableEditorDefinition: async ({ table, schema, getColDefs }) => {
|
||||
let { foreignKeys, pk_constraint_name, colDefs } = await fetchTableRelationalKeys(
|
||||
onFetchTableEditorDefinition: async ({ table, schema, colDefs }) => {
|
||||
let { foreignKeys, pk_constraint_name } = await fetchTableRelationalKeys(
|
||||
input,
|
||||
dbType,
|
||||
table,
|
||||
schema,
|
||||
workspace,
|
||||
dbArg,
|
||||
language,
|
||||
getColDefs
|
||||
language
|
||||
)
|
||||
|
||||
return buildTableEditorValues({
|
||||
|
||||
Reference in New Issue
Block a user