Revert "fix(objects): guard system source edits"

This reverts commit 17bc2e66d4.
This commit is contained in:
t8y2 committed 2026-05-18 17:53:02 +08:00
1 parent 2172b624b1
commit af16ac219c
13 files changed
+27 -291

No files matched your search

@@ -34,11 +34,7 @@ import type { ConnectionConfig, ObjectInfo, ObjectSourceKind } from "@/types/dat
import { isSchemaAware } from "@/lib/databaseCapabilities";
import { buildTableSelectSql, qualifiedTableName } from "@/lib/tableSelectSql";
import { useToast } from "@/composables/useToast";
import {
buildExecutableObjectSourceStatements,
objectSourceReadOnlyReason,
objectSourceSaveExecutionMode,
} from "@/lib/objectSourceEditor";
import { buildExecutableObjectSourceStatements, objectSourceSaveExecutionMode } from "@/lib/objectSourceEditor";
import { buildRenameObjectSql, supportsObjectRename } from "@/lib/objectRenameSql";
import { useConnectionStore } from "@/stores/connectionStore";
import { useQueryStore } from "@/stores/queryStore";
@@ -112,7 +108,6 @@ const sourceFormatDialect = computed<SqlFormatDialect>(() => {
return "generic";
}
});
const sourceRowReadOnlyReason = computed(() => (sourceRow.value ? readOnlyReasonForRow(sourceRow.value) : null));
const objectFilters = computed<ObjectFilter[]>(() =>
(
[
@@ -174,17 +169,7 @@ function canOpenSource(row: ObjectBrowserRow) {
}
function canRename(row: ObjectBrowserRow) {
return !readOnlyReasonForRow(row) && supportsObjectRename(props.connection.db_type, row.type);
}
function readOnlyReasonForRow(row: ObjectBrowserRow) {
if (row.type !== "VIEW" && row.type !== "PROCEDURE" && row.type !== "FUNCTION") return null;
return objectSourceReadOnlyReason({
databaseType: props.connection.db_type,
schema: row.schema || selectedSchema.value || props.database,
name: row.name,
objectType: row.type,
});
return supportsObjectRename(props.connection.db_type, row.type);
}
function sourceTitle(row: ObjectBrowserRow | null) {
@@ -220,7 +205,7 @@ async function openSource(row: ObjectBrowserRow) {
);
sourceContent.value = result.source;
sourceDraft.value = result.source;
sourceEditing.value = !readOnlyReasonForRow(row);
sourceEditing.value = true;
} catch (e: any) {
sourceError.value = e?.message || String(e);
} finally {
@@ -250,19 +235,11 @@ function qualifiedName(row: ObjectBrowserRow): string {
}
function requestDrop(row: ObjectBrowserRow) {
if (readOnlyReasonForRow(row)) {
toast(t("objects.sourceReadOnlySystemObject"), 5000);
return;
}
dropTarget.value = row;
showDropConfirm.value = true;
}
function requestRename(row: ObjectBrowserRow) {
if (readOnlyReasonForRow(row)) {
toast(t("objects.sourceReadOnlySystemObject"), 5000);
return;
}
renameTarget.value = row;
renameInput.value = row.name;
renameError.value = "";
@@ -290,10 +267,6 @@ async function confirmRename() {
const row = renameTarget.value;
const newName = renameInput.value.trim();
if (!row || !newName || newName === row.name) return;
if (readOnlyReasonForRow(row)) {
renameError.value = t("objects.sourceReadOnlySystemObject");
return;
}
renameError.value = "";
try {
const schema = row.schema || selectedSchema.value || props.database;
@@ -322,11 +295,6 @@ async function confirmRename() {
async function confirmDrop() {
if (!dropTarget.value) return;
const row = dropTarget.value;
if (readOnlyReasonForRow(row)) {
toast(t("objects.sourceReadOnlySystemObject"), 5000);
dropTarget.value = null;
return;
}
const typeSql =
row.type === "VIEW"
? "VIEW"
@@ -395,10 +363,6 @@ function copySource() {
function editSource() {
if (!sourceRow.value || !sourceContent.value) return;
if (sourceRowReadOnlyReason.value) {
toast(t("objects.sourceReadOnlySystemObject"), 5000);
return;
}
sourceDraft.value = sourceContent.value;
sourceSaveError.value = "";
sourceEditing.value = true;
@@ -412,10 +376,6 @@ function cancelEditSource() {
async function saveSource() {
if (!sourceRow.value || !sourceDraft.value.trim()) return;
if (sourceRowReadOnlyReason.value) {
toast(t("objects.sourceReadOnlySystemObject"), 5000);
return;
}
const row = sourceRow.value;
const schema = row.schema || selectedSchema.value || props.database;
sourceSaving.value = true;
@@ -691,13 +651,11 @@ watch(
<ContextMenuItem v-if="canRename(item)" @click="requestRename(item)">
<Pencil class="w-4 h-4 mr-2" /> {{ t("contextMenu.renameObject") }}
</ContextMenuItem>
<template v-if="!readOnlyReasonForRow(item)">
<ContextMenuSeparator />
<ContextMenuItem class="text-destructive" @click="requestDrop(item)">
<Trash2 class="w-4 h-4 mr-2" />
{{ item.type === "PROCEDURE" ? t("contextMenu.dropProcedure") : t("contextMenu.dropFunction") }}
</ContextMenuItem>
</template>
<ContextMenuSeparator />
<ContextMenuItem class="text-destructive" @click="requestDrop(item)">
<Trash2 class="w-4 h-4 mr-2" />
{{ item.type === "PROCEDURE" ? t("contextMenu.dropProcedure") : t("contextMenu.dropFunction") }}
</ContextMenuItem>
</template>
</ContextMenuContent>
</ContextMenu>
@@ -743,8 +701,7 @@ watch(
variant="ghost"
size="icon"
class="h-5 w-5"
:disabled="!sourceContent || !!sourceRowReadOnlyReason"
:title="sourceRowReadOnlyReason ? t('objects.sourceReadOnlySystemObject') : undefined"
:disabled="!sourceContent"
@click="editSource"
>
<PencilLine class="h-3 w-3" />
@@ -767,7 +724,6 @@ watch(
:database="props.database"
:dialect="sourceDialect"
:format-dialect="sourceFormatDialect"
:read-only="!!sourceRowReadOnlyReason"
force-word-wrap
@save="saveSource"
/>