mirror of
https://github.com/t8y2/dbx.git
synced 2026-10-21 05:20:02 +00:00
feat(starrocks): enable F2 table rename
This commit is contained in:
@@ -12,6 +12,16 @@ describe("Inceptor object rename", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("StarRocks object rename", () => {
|
||||
it("enables table rename only", () => {
|
||||
expect(supportsObjectRename("starrocks", "TABLE")).toBe(true);
|
||||
for (const objectType of ["VIEW", "MATERIALIZED_VIEW", "PROCEDURE", "FUNCTION", "EVENT"] as const) {
|
||||
expect(supportsObjectRename("starrocks", objectType)).toBe(false);
|
||||
}
|
||||
expect(supportsDatabaseRename("starrocks")).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("database rename", () => {
|
||||
it("chooses a maintenance database outside the rename target", () => {
|
||||
expect(databaseRenameMaintenanceDatabase("admin", "application")).toBe("admin");
|
||||
|
||||
@@ -23,7 +23,7 @@ export function supportsObjectRename(databaseType: DatabaseType | undefined, obj
|
||||
return false;
|
||||
}
|
||||
if (databaseType === "sqlite" || databaseType === "rqlite" || databaseType === "turso" || databaseType === "cloudflare-d1" || databaseType === "duckdb") return objectType === "TABLE";
|
||||
if (databaseType === "transwarp") return objectType === "TABLE";
|
||||
if (databaseType === "transwarp" || databaseType === "starrocks") return objectType === "TABLE";
|
||||
if (databaseType === "mysql" || databaseType === "goldendb") return objectType === "TABLE" || objectType === "VIEW";
|
||||
if (postgresLikeRenameTypes.has(databaseType)) return objectType === "TABLE" || objectType === "VIEW" || objectType === "MATERIALIZED_VIEW";
|
||||
if (oracleLikeRenameTypes.has(databaseType)) return objectType === "TABLE" || objectType === "VIEW" || objectType === "MATERIALIZED_VIEW";
|
||||
|
||||
@@ -932,7 +932,7 @@ pub fn supports_object_rename(database_type: Option<DatabaseType>, object_type:
|
||||
if database_type == DatabaseType::SqlServer {
|
||||
return true;
|
||||
}
|
||||
if database_type == DatabaseType::Transwarp {
|
||||
if matches!(database_type, DatabaseType::Transwarp | DatabaseType::StarRocks) {
|
||||
return object_type == DatabaseObjectType::Table;
|
||||
}
|
||||
if matches!(object_type, DatabaseObjectType::Procedure | DatabaseObjectType::Function) {
|
||||
@@ -978,6 +978,14 @@ pub fn build_rename_object_sql(options: RenameObjectSqlOptions) -> Result<String
|
||||
));
|
||||
}
|
||||
|
||||
if database_type == Some(DatabaseType::StarRocks) {
|
||||
return Ok(format!(
|
||||
"ALTER TABLE {} RENAME {};",
|
||||
qualified_name(database_type, options.schema.as_deref(), &options.old_name),
|
||||
quote_rename_identifier(database_type, &options.new_name)
|
||||
));
|
||||
}
|
||||
|
||||
if database_type == Some(DatabaseType::Transwarp) {
|
||||
return Ok(format!(
|
||||
"ALTER TABLE {} RENAME TO {};",
|
||||
@@ -3033,6 +3041,45 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn builds_starrocks_table_rename_sql() {
|
||||
let database_type = Some(DatabaseType::StarRocks);
|
||||
assert!(supports_object_rename(database_type, DatabaseObjectType::Table));
|
||||
for (old_name, new_name, expected) in [
|
||||
("users", "app_users", "ALTER TABLE `users` RENAME `app_users`;"),
|
||||
("user`name", "new`name", "ALTER TABLE `user``name` RENAME `new``name`;"),
|
||||
] {
|
||||
assert_eq!(
|
||||
build_rename_object_sql(RenameObjectSqlOptions {
|
||||
database_type,
|
||||
object_type: DatabaseObjectType::Table,
|
||||
schema: None,
|
||||
old_name: old_name.to_string(),
|
||||
new_name: new_name.to_string(),
|
||||
})
|
||||
.unwrap(),
|
||||
expected
|
||||
);
|
||||
}
|
||||
for object_type in [
|
||||
DatabaseObjectType::View,
|
||||
DatabaseObjectType::MaterializedView,
|
||||
DatabaseObjectType::Procedure,
|
||||
DatabaseObjectType::Function,
|
||||
DatabaseObjectType::Event,
|
||||
] {
|
||||
assert!(!supports_object_rename(database_type, object_type));
|
||||
assert!(build_rename_object_sql(RenameObjectSqlOptions {
|
||||
database_type,
|
||||
object_type,
|
||||
schema: None,
|
||||
old_name: "old_name".to_string(),
|
||||
new_name: "new_name".to_string(),
|
||||
})
|
||||
.is_err());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn builds_mysql_table_and_view_rename_sql() {
|
||||
assert_eq!(
|
||||
|
||||
Reference in New Issue
Block a user