show generic index error and added support to autoreplace the collection id if part of an index name

This commit is contained in:
Gani Georgiev
2024-11-02 22:34:05 +02:00
parent fadb4e3d67
commit 1025fb2406
29 changed files with 128 additions and 106 deletions
@@ -1,7 +1,8 @@
<script>
import { scale } from "svelte/transition";
import CommonHelper from "@/utils/CommonHelper";
import { errors, removeError } from "@/stores/errors";
import tooltip from "@/actions/tooltip";
import { errors, removeError } from "@/stores/errors";
import IndexUpsertPanel from "@/components/collections/IndexUpsertPanel.svelte";
export let collection;
@@ -26,6 +27,13 @@
<div class="section-title">
Unique constraints and indexes ({collection?.indexes?.length || 0})
{#if $errors?.indexes?.message}
<i
class="ri-error-warning-fill txt-danger"
transition:scale={{ duration: 150 }}
use:tooltip={$errors?.indexes.message}
/>
{/if}
</div>
<div class="indexes-list">
{#each collection?.indexes || [] as rawIndex, i}
@@ -68,6 +76,11 @@
collection.indexes = collection.indexes;
}}
on:submit={(e) => {
// clear generic error
if ($errors.indexes?.message) {
removeError("indexes");
}
pushOrReplace(e.detail.old, e.detail.new);
}}
/>
@@ -192,6 +192,14 @@
}
}
}
// update index names that contains the collection id
for (let i = 0; i < collection.indexes?.length; i++) {
collection.indexes[i] = collection.indexes[i].replace(
/create\s+(?:unique\s+)?\s*index\s*(?:if\s+not\s+exists\s+)?(\S*)\s+on/gim,
(v) => v.replace(originalId, replacedId),
);
}
}
schemas = JSON.stringify(newCollections, null, 4);