feat(table): support openGauss object renaming

This commit is contained in:
dadong authored and GitHub committed 2026-08-20 09:28:29 +08:00
1 parent 2c75a6535e
commit c7797b4be1
3 files changed
+47 -2

No files matched your search

@@ -1,6 +1,7 @@
import { beforeEach, describe, expect, it, vi } from "vitest"; import { beforeEach, describe, expect, it, vi } from "vitest";
import * as api from "@/lib/backend/api"; import * as api from "@/lib/backend/api";
import { executeObjectSourceSave, formatObjectSourceSaveError, resolveObjectSourceEditDraft } from "@/lib/table/objectSourceEditor"; import { executeObjectSourceSave, formatObjectSourceSaveError, resolveObjectSourceEditDraft, supportsSourceBackedRoutineRename } from "@/lib/table/objectSourceEditor";
import { supportsObjectRename } from "@/lib/table/objectRenameSql";
import { formatSqlForDisplay } from "@/lib/sql/sqlFormatter"; import { formatSqlForDisplay } from "@/lib/sql/sqlFormatter";
vi.mock("@/lib/backend/api", () => ({ vi.mock("@/lib/backend/api", () => ({
@@ -13,6 +14,17 @@ beforeEach(() => {
vi.clearAllMocks(); vi.clearAllMocks();
}); });
describe("openGauss rename capabilities", () => {
it("keeps direct object renames without enabling source-backed routine rebuilds", () => {
expect(supportsObjectRename("opengauss", "TABLE")).toBe(true);
expect(supportsObjectRename("opengauss", "VIEW")).toBe(true);
expect(supportsObjectRename("opengauss", "MATERIALIZED_VIEW")).toBe(true);
expect(supportsSourceBackedRoutineRename("opengauss", "FUNCTION")).toBe(false);
expect(supportsSourceBackedRoutineRename("opengauss", "PROCEDURE")).toBe(false);
expect(supportsSourceBackedRoutineRename("postgres", "FUNCTION")).toBe(true);
});
});
describe("executeObjectSourceSave", () => { describe("executeObjectSourceSave", () => {
it("runs multi-statement Informix source saves in a transaction", async () => { it("runs multi-statement Informix source saves in a transaction", async () => {
await executeObjectSourceSave("conn-1", "stores", "informix", ["CREATE TEMP VIEW v AS SELECT 1", " ", "DROP VIEW v", "CREATE VIEW v AS SELECT 2"], "app"); await executeObjectSourceSave("conn-1", "stores", "informix", ["CREATE TEMP VIEW v AS SELECT 1", " ", "DROP VIEW v", "CREATE VIEW v AS SELECT 2"], "app");
@@ -11,7 +11,8 @@ export interface BuildRenameObjectSqlOptions {
newName: string; newName: string;
} }
const postgresLikeRenameTypes = new Set<DatabaseType>(["postgres", "redshift", "gaussdb", "kwdb", "kingbase", "highgo", "uxdb", "vastbase"]); // openGauss 兼容 PostgreSQL 的 ALTER TABLE/VIEW ... RENAME TO 语法,需与 gaussdb 等 PG 系数据库同等开放重命名能力
const postgresLikeRenameTypes = new Set<DatabaseType>(["postgres", "redshift", "gaussdb", "kwdb", "opengauss", "kingbase", "highgo", "uxdb", "vastbase"]);
const oracleLikeRenameTypes = new Set<DatabaseType>(["oracle", "dameng"]); const oracleLikeRenameTypes = new Set<DatabaseType>(["oracle", "dameng"]);
+32
View File
@@ -816,12 +816,14 @@ pub fn build_rename_object_sql(options: RenameObjectSqlOptions) -> Result<String
} }
fn is_postgres_like_rename(database_type: DatabaseType) -> bool { fn is_postgres_like_rename(database_type: DatabaseType) -> bool {
// openGauss 兼容 PG 的 ALTER TABLE/VIEW ... RENAME TO 语法,与 gaussdb 等同开放重命名能力。
matches!( matches!(
database_type, database_type,
DatabaseType::Postgres DatabaseType::Postgres
| DatabaseType::Redshift | DatabaseType::Redshift
| DatabaseType::Gaussdb | DatabaseType::Gaussdb
| DatabaseType::Kwdb | DatabaseType::Kwdb
| DatabaseType::OpenGauss
| DatabaseType::Kingbase | DatabaseType::Kingbase
| DatabaseType::Highgo | DatabaseType::Highgo
| DatabaseType::Uxdb | DatabaseType::Uxdb
@@ -2040,6 +2042,36 @@ mod tests {
); );
} }
#[test]
fn builds_opengauss_table_and_view_rename_sql() {
// openGauss 兼容 PG 重命名语法,与 gaussdb 等 PG 系数据库保持一致(右键“重命名”菜单入口)。
assert!(supports_object_rename(Some(DatabaseType::OpenGauss), DatabaseObjectType::Table));
assert!(supports_object_rename(Some(DatabaseType::OpenGauss), DatabaseObjectType::View));
assert!(supports_object_rename(Some(DatabaseType::OpenGauss), DatabaseObjectType::MaterializedView));
assert_eq!(
build_rename_object_sql(RenameObjectSqlOptions {
database_type: Some(DatabaseType::OpenGauss),
object_type: DatabaseObjectType::Table,
schema: Some("public".to_string()),
old_name: "orders".to_string(),
new_name: "archived orders".to_string(),
})
.unwrap(),
"ALTER TABLE \"public\".\"orders\" RENAME TO \"archived orders\";"
);
assert_eq!(
build_rename_object_sql(RenameObjectSqlOptions {
database_type: Some(DatabaseType::OpenGauss),
object_type: DatabaseObjectType::View,
schema: Some("public".to_string()),
old_name: "active_users".to_string(),
new_name: "enabled_users".to_string(),
})
.unwrap(),
"ALTER VIEW \"public\".\"active_users\" RENAME TO \"enabled_users\";"
);
}
#[test] #[test]
fn builds_sqlserver_routine_rename_sql() { fn builds_sqlserver_routine_rename_sql() {
assert_eq!( assert_eq!(