From a59a1895f7b6fdaa91d0dcf509e1d2677e3d2c76 Mon Sep 17 00:00:00 2001 From: Divyansha Dubey Date: Thu, 20 Nov 2025 13:58:09 +0530 Subject: [PATCH 1/5] fix spatial index column issue --- .../table-[table]/indexes/createIndex.svelte | 43 ++++++++++++++++--- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/indexes/createIndex.svelte b/src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/indexes/createIndex.svelte index 88af9c2571..20eab24c13 100644 --- a/src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/indexes/createIndex.svelte +++ b/src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/indexes/createIndex.svelte @@ -68,11 +68,26 @@ ] ); - // spatial type selected -> reset column list to single empty column - // and the column already is not spatial type + // Handle index type changes and reset incompatible columns $effect(() => { - if (selectedType === IndexType.Spatial && !columnList.at(0).value) { - columnList = [{ value: '', order: null, length: null }]; + if (selectedType === IndexType.Spatial) { + // When switching to spatial, reset to single empty column with null order + // or clear any non-spatial columns that were previously selected + const currentColumn = columnList.at(0)?.value; + const currentColumnObj = $table.columns.find(col => col.key === currentColumn); + + if (!currentColumn || !currentColumnObj || !isSpatialType(currentColumnObj)) { + columnList = [{ value: '', order: null, length: null }]; + } else { + // Keep the spatial column but ensure order is null + columnList = [{ value: currentColumn, order: null, length: null }]; + } + } else { + // When switching away from spatial, ensure non-spatial columns have proper order + const currentColumn = columnList.at(0)?.value; + if (currentColumn && columnList.at(0)?.order === null) { + columnList = [{ value: currentColumn, order: 'ASC', length: null }]; + } } }); @@ -122,7 +137,25 @@ }); export async function create() { - if (!key || !selectedType || (selectedType !== IndexType.Spatial && addColumnDisabled)) { + // Validate basic requirements + if (!key || !selectedType) { + addNotification({ + type: 'error', + message: 'Index key and type are required' + }); + throw new Error('Index key and type are required'); + } + + // Validate column selection for spatial indexes + if (selectedType === IndexType.Spatial) { + if (!columnList.at(0)?.value) { + addNotification({ + type: 'error', + message: 'Please select a spatial column for the spatial index' + }); + throw new Error('Please select a spatial column for the spatial index'); + } + } else if (addColumnDisabled) { addNotification({ type: 'error', message: 'Selected column key or type invalid' From eff73566af760264cd1d05a066e2b2c9d68b0ba4 Mon Sep 17 00:00:00 2001 From: Divyansha Dubey Date: Thu, 20 Nov 2025 14:26:13 +0530 Subject: [PATCH 2/5] fixed lint issues --- .../table-[table]/indexes/createIndex.svelte | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/indexes/createIndex.svelte b/src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/indexes/createIndex.svelte index 20eab24c13..ac528ddab8 100644 --- a/src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/indexes/createIndex.svelte +++ b/src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/indexes/createIndex.svelte @@ -71,11 +71,10 @@ // Handle index type changes and reset incompatible columns $effect(() => { if (selectedType === IndexType.Spatial) { - // When switching to spatial, reset to single empty column with null order - // or clear any non-spatial columns that were previously selected + // When switching to spatial, reset column list appropriately const currentColumn = columnList.at(0)?.value; - const currentColumnObj = $table.columns.find(col => col.key === currentColumn); - + const currentColumnObj = $table.columns.find((col) => col.key === currentColumn); + if (!currentColumn || !currentColumnObj || !isSpatialType(currentColumnObj)) { columnList = [{ value: '', order: null, length: null }]; } else { @@ -83,7 +82,7 @@ columnList = [{ value: currentColumn, order: null, length: null }]; } } else { - // When switching away from spatial, ensure non-spatial columns have proper order + // When switching away from spatial, ensure proper order const currentColumn = columnList.at(0)?.value; if (currentColumn && columnList.at(0)?.order === null) { columnList = [{ value: currentColumn, order: 'ASC', length: null }]; @@ -121,7 +120,8 @@ const isOnIndexesPage = $derived(page.route.id?.endsWith('/indexes')); const navigatorPathToIndexes = $derived( - `${base}/project-${page.params.region}-${page.params.project}/databases/database-${databaseId}/table-${$table?.$id}/indexes` + `${base}/project-${page.params.region}-${page.params.project}/databases/` + + `database-${databaseId}/table-${$table?.$id}/indexes` ); let initializedForOpen = $state(false); From e0d297113446067e5926009dc50074cdb9d785fe Mon Sep 17 00:00:00 2001 From: Divyansha Dubey Date: Thu, 20 Nov 2025 14:33:22 +0530 Subject: [PATCH 3/5] lint issues --- .../table-[table]/indexes/createIndex.svelte | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/indexes/createIndex.svelte b/src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/indexes/createIndex.svelte index ac528ddab8..132db9bbfb 100644 --- a/src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/indexes/createIndex.svelte +++ b/src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/indexes/createIndex.svelte @@ -36,7 +36,8 @@ if (selectedType === IndexType.Spatial) { return isSpatialType(column); // keep only spatial } - return !isRelationship(column) && !isSpatialType(column); // keep non-relationship and non-spatial + // keep non-relationship and non-spatial + return !isRelationship(column) && !isSpatialType(column); }) .map((column) => ({ value: column.key, From 2970dce4699ead77389c68028fbb75879e9947ad Mon Sep 17 00:00:00 2001 From: Divyansha Dubey Date: Thu, 20 Nov 2025 14:36:51 +0530 Subject: [PATCH 4/5] fixed lint issues --- .../table-[table]/indexes/createIndex.svelte | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/indexes/createIndex.svelte b/src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/indexes/createIndex.svelte index 132db9bbfb..9533a7e5ff 100644 --- a/src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/indexes/createIndex.svelte +++ b/src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/indexes/createIndex.svelte @@ -121,8 +121,7 @@ const isOnIndexesPage = $derived(page.route.id?.endsWith('/indexes')); const navigatorPathToIndexes = $derived( - `${base}/project-${page.params.region}-${page.params.project}/databases/` + - `database-${databaseId}/table-${$table?.$id}/indexes` + `${base}/project-${page.params.region}-${page.params.project}/databases/database-${databaseId}/table-${$table?.$id}/indexes` ); let initializedForOpen = $state(false); From 1b27ae0d25db6faed90eb1c834cf00d5b26f1a66 Mon Sep 17 00:00:00 2001 From: Divyansha Dubey Date: Thu, 20 Nov 2025 16:29:56 +0530 Subject: [PATCH 5/5] fixed infinite loop --- .../table-[table]/indexes/createIndex.svelte | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/indexes/createIndex.svelte b/src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/indexes/createIndex.svelte index 9533a7e5ff..953d3398a2 100644 --- a/src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/indexes/createIndex.svelte +++ b/src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/indexes/createIndex.svelte @@ -72,21 +72,31 @@ // Handle index type changes and reset incompatible columns $effect(() => { if (selectedType === IndexType.Spatial) { - // When switching to spatial, reset column list appropriately - const currentColumn = columnList.at(0)?.value; - const currentColumnObj = $table.columns.find((col) => col.key === currentColumn); - - if (!currentColumn || !currentColumnObj || !isSpatialType(currentColumnObj)) { - columnList = [{ value: '', order: null, length: null }]; - } else { - // Keep the spatial column but ensure order is null - columnList = [{ value: currentColumn, order: null, length: null }]; + // When switching to spatial, normalize to a single spatial column with no order + const currentEntry = columnList.at(0) ?? { value: '', order: null, length: null }; + const currentColumnObj = currentEntry.value + ? $table.columns.find((col) => col.key === currentEntry.value) + : undefined; + + const nextEntry = + !currentEntry.value || !currentColumnObj || !isSpatialType(currentColumnObj) + ? { value: '', order: null, length: null } + : { value: currentEntry.value, order: null, length: null }; + + const needsUpdate = + columnList.length !== 1 || + columnList[0].value !== nextEntry.value || + columnList[0].order !== nextEntry.order || + columnList[0].length !== nextEntry.length; + + if (needsUpdate) { + columnList = [nextEntry]; } } else { // When switching away from spatial, ensure proper order - const currentColumn = columnList.at(0)?.value; - if (currentColumn && columnList.at(0)?.order === null) { - columnList = [{ value: currentColumn, order: 'ASC', length: null }]; + const currentEntry = columnList.at(0); + if (currentEntry?.value && currentEntry.order === null) { + columnList = [{ ...currentEntry, order: 'ASC' }]; } } });