Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

fix(dameng): include column comments in table ddl

lxk9558a31da122c56
diff --git a/agents/common/src/main/java/com/dbx/agent/BaseDatabaseAgent.java b/agents/common/src/main/java/com/dbx/agent/BaseDatabaseAgent.java
index 77ff4b4687..8b6f8a8072 100644
--- a/agents/common/src/main/java/com/dbx/agent/BaseDatabaseAgent.java
+++ b/agents/common/src/main/java/com/dbx/agent/BaseDatabaseAgent.java
@@ -48,7 +48,14 @@ public abstract class BaseDatabaseAgent implements DatabaseAgent {
// Table comment is optional; DDL generation should still succeed without it.
}
- return DdlBuilder.buildTableDdl(schema, table, getColumns(schema, table), indexes, foreignKeys, Collections.emptyList(), false, false, tableComment);
+ return DdlBuilder.buildTableDdl(
+ schema, table, getColumns(schema, table), indexes, foreignKeys,
+ Collections.emptyList(), false, includeColumnCommentsInTableDdl(), tableComment
+ );
+ }
+
+ protected boolean includeColumnCommentsInTableDdl() {
+ return false;
}
@Override
diff --git a/agents/drivers/dameng/src/main/java/com/dbx/agent/dameng/DamengAgent.java b/agents/drivers/dameng/src/main/java/com/dbx/agent/dameng/DamengAgent.java
index fcf12dd065..31d21bb863 100644
--- a/agents/drivers/dameng/src/main/java/com/dbx/agent/dameng/DamengAgent.java
+++ b/agents/drivers/dameng/src/main/java/com/dbx/agent/dameng/DamengAgent.java
@@ -975,9 +975,11 @@ public final class DamengAgent extends AbstractJdbcAgent {
return current;
}
}
- } catch (SQLException error) {
- // A server without SYS_CONTEXT support still resolves an unqualified name to the
- // connected user, which is what the caller falls back to.
+ } catch (Exception error) {
+ // Current schema resolution is best-effort: any failure (including environments without
+ // SYS_CONTEXT support, query execution errors, or pathological drivers returning a null
+ // Statement) falls back to an empty string, allowing the caller to fall back to the
+ // connected username.
}
return "";
}
@@ -1853,6 +1855,24 @@ public final class DamengAgent extends AbstractJdbcAgent {
};
}
+ @Override
+ protected boolean includeColumnCommentsInTableDdl() {
+ return true;
+ }
+
+ @Override
+ public String getTableComment(String rawSchema, String table) {
+ final String schema = normalizeSchema(rawSchema);
+ try {
+ String comment = tableComment(schema, table);
+ if (notBlank(comment)) {
+ return comment;
+ }
+ } catch (Exception ignored) {
+ }
+ return super.getTableComment(schema, table);
+ }
+
@Override
public String getTableDdl(String rawSchema, String table) {
final String schema = normalizeSchema(rawSchema);
@@ -3042,16 +3062,30 @@ public final class DamengAgent extends AbstractJdbcAgent {
return value == null ? "" : value;
}
+ private boolean schemaMatchesConnectedUserOrCurrent(String schema) {
+ if (schema == null || schema.isBlank()) {
+ return true;
+ }
+ if (schemaMatchesConnectedUser(schema)) {
+ return true;
+ }
+ // Short-circuit before the SYS_CONTEXT probe: when we don't know the connected username
+ // there is nothing to compare the probe result against, so skip the extra DB round-trip.
+ if (connectedUsername == null || connectedUsername.isBlank()) {
+ return true;
+ }
+ String currentSchema = currentSchemaOrBlank();
+ if (!currentSchema.isBlank()) {
+ return schema.equalsIgnoreCase(currentSchema);
+ }
+ return false;
+ }
+
private void fillMissingColumnComments(String schema, String table, List<ColumnInfo> columns) {
if (columns.stream().noneMatch(column -> !notBlank(column.getComment()))) {
return;
}
Map<String, String> comments = new HashMap<>();
- queryColumnComments(
- comments,
- "SELECT /*+ PARALLEL(1) */ COLUMN_NAME, COMMENTS FROM USER_COL_COMMENTS WHERE TABLE_NAME = ?",
- table
- );
queryColumnComments(
comments,
"SELECT /*+ PARALLEL(1) */ COLNAME, COMMENT$ FROM SYS.SYSCOLUMNCOMMENTS WHERE SCHNAME = ? AND TVNAME = ?",
@@ -3064,6 +3098,13 @@ public final class DamengAgent extends AbstractJdbcAgent {
schema,
table
);
+ if (schemaMatchesConnectedUserOrCurrent(schema)) {
+ queryColumnComments(
+ comments,
+ "SELECT /*+ PARALLEL(1) */ COLUMN_NAME, COMMENTS FROM USER_COL_COMMENTS WHERE TABLE_NAME = ?",
+ table
+ );
+ }
for (ColumnInfo column : columns) {
if (notBlank(column.getComment())) {
continue;
@@ -3130,10 +3171,63 @@ public final class DamengAgent extends AbstractJdbcAgent {
}
}
}
+ } catch (Exception ignored) {
+ }
+ if (result.isEmpty()) {
+ queryTableColumnComments(
+ result,
+ "SELECT /*+ PARALLEL(1) */ COLNAME, COMMENT$ FROM SYS.SYSCOLUMNCOMMENTS WHERE SCHNAME = ? AND TVNAME = ?",
+ schema,
+ table
+ );
+ }
+ if (result.isEmpty()) {
+ queryTableColumnComments(
+ result,
+ "SELECT /*+ PARALLEL(1) */ COLUMN_NAME, COMMENTS FROM ALL_COL_COMMENTS WHERE UPPER(OWNER) = UPPER(?) AND UPPER(TABLE_NAME) = UPPER(?)",
+ schema,
+ table
+ );
+ }
+ if (result.isEmpty() && schemaMatchesConnectedUserOrCurrent(schema)) {
+ queryTableColumnComments(
+ result,
+ "SELECT /*+ PARALLEL(1) */ COLUMN_NAME, COMMENTS FROM USER_COL_COMMENTS WHERE TABLE_NAME = ?",
+ table
+ );
+ }
+ if (result.isEmpty()) {
+ try {
+ for (ColumnInfo column : getColumns(schema, table)) {
+ if (notBlank(column.getName()) && notBlank(column.getComment())) {
+ result.put(column.getName(), column.getComment());
+ }
+ }
+ } catch (Exception ignored) {
+ }
}
return result;
}
+ private void queryTableColumnComments(Map<String, String> comments, String sql, String... params) {
+ try (PreparedStatement stmt = requireConnected().prepareStatement(sql)) {
+ for (int i = 0; i < params.length; i++) {
+ stmt.setString(i + 1, params[i]);
+ }
+ try (ResultSet rs = stmt.executeQuery()) {
+ while (rs.next()) {
+ String column = rs.getString(1);
+ String comment = rs.getString(2);
+ if (notBlank(column) && notBlank(comment)) {
+ comments.putIfAbsent(column, comment);
+ }
+ }
+ }
+ } catch (Exception ignored) {
+ // Some Dameng versions or users do not expose every comment view.
+ }
+ }
+
private String appendIndependentIndexDdl(String ddl, String schema, String table) throws Exception {
StringBuilder result = new StringBuilder(ddl == null ? "" : ddl.trim());
for (IndexInfo index : independentIndexes(schema, table)) {
diff --git a/agents/drivers/dameng/src/test/java/com/dbx/agent/dameng/DamengAgentMetadataTest.java b/agents/drivers/dameng/src/test/java/com/dbx/agent/dameng/DamengAgentMetadataTest.java
index 7214ed0a7a..6b95e7f11f 100644
--- a/agents/drivers/dameng/src/test/java/com/dbx/agent/dameng/DamengAgentMetadataTest.java
+++ b/agents/drivers/dameng/src/test/java/com/dbx/agent/dameng/DamengAgentMetadataTest.java
@@ -2106,10 +2106,48 @@ class DamengAgentMetadataTest {
Assertions.assertTrue(ddl.contains("CREATE TABLE \"APP\".\"USERS\""), ddl);
Assertions.assertTrue(ddl.contains("\"ID\" NUMBER(10) NOT NULL"), ddl);
+ Assertions.assertTrue(ddl.contains("COMMENT ON COLUMN \"APP\".\"USERS\".\"ID\" IS 'id comment';"), ddl);
Assertions.assertEquals(1, sqls.stream().filter(sql -> sql.contains("DBMS_METADATA.GET_DDL")).count());
Assertions.assertTrue(sqls.stream().anyMatch(sql -> sql.contains("ALL_TAB_COLUMNS")), String.join("\n", sqls));
}
+ @Test
+ void appendsColumnCommentsFromFallbackViewsWhenAllColCommentsEmpty() {
+ DamengAgent agent = new DamengAgent();
+ List<String> sqls = new ArrayList<>();
+ TestSupport.setPrivateConnection(agent, metadataConnection(
+ null,
+ "fallback id comment",
+ false,
+ List.of(),
+ sqls
+ ));
+
+ String ddl = agent.getTableDdl("APP", "USERS");
+
+ Assertions.assertTrue(ddl.contains("COMMENT ON COLUMN \"APP\".\"USERS\".\"ID\" IS 'fallback id comment';"), ddl);
+ Assertions.assertTrue(sqls.stream().anyMatch(sql -> sql.contains("USER_COL_COMMENTS")), String.join("\n", sqls));
+ }
+
+ @Test
+ void doesNotQueryUserColCommentsWhenSchemaDiffersFromConnectedUser() {
+ DamengAgent agent = new DamengAgent();
+ setConnectedUsername(agent, "SYSDBA");
+ List<String> sqls = new ArrayList<>();
+ TestSupport.setPrivateConnection(agent, metadataConnection(
+ null,
+ "fallback id comment",
+ false,
+ List.of(),
+ sqls
+ ));
+
+ String ddl = agent.getTableDdl("APP", "USERS");
+
+ Assertions.assertFalse(sqls.stream().anyMatch(sql -> sql.contains("USER_COL_COMMENTS")), String.join("\n", sqls));
+ Assertions.assertFalse(ddl.contains("fallback id comment"), ddl);
+ }
+
@Test
void propagatesNonPermissionDbmsMetadataErrorsWithoutFallback() {
DamengAgent agent = new DamengAgent();
diff --git a/crates/dbx-core/src/schema/mod.rs b/crates/dbx-core/src/schema/mod.rs
index 36a19fdb33..669f3dff25 100644
--- a/crates/dbx-core/src/schema/mod.rs
+++ b/crates/dbx-core/src/schema/mod.rs
@@ -1231,114 +1231,120 @@ fn mysql_auto_increment_from_query_result(result: db::QueryResult) -> Result<Opt
Ok(Some(text))
}
-async fn get_table_comment_core_for_session(
+async fn get_table_comment_core_with_pool_key(
state: &AppState,
connection_id: &str,
database: &str,
schema: &str,
table: &str,
- client_session_id: Option<&str>,
+ pool_key: &str,
) -> Result<Option<String>, String> {
- retry_metadata_connection_for_session(state, connection_id, Some(database), client_session_id, || async {
- let pool_key =
- state.get_or_create_metadata_pool_for_session(connection_id, Some(database), client_session_id).await?;
- let db_config = connection_config(state, connection_id).await;
+ let db_config = connection_config(state, connection_id).await;
- {
- let pool_handle = state.pool_handle(&pool_key).await;
- try_sqlserver!(pool_handle, get_table_comment, schema, table);
- if let Some(PoolKind::ExternalDriver { config, session, .. }) = pool_handle.as_ref() {
- if is_oracle_external_driver_config(config.as_ref()) {
- return external_driver_oracle_table_comment(
- session.clone(),
- config.as_ref(),
- database,
- schema,
- table,
- )
+ {
+ let pool_handle = state.pool_handle(pool_key).await;
+ try_sqlserver!(pool_handle, get_table_comment, schema, table);
+ if let Some(PoolKind::ExternalDriver { config, session, .. }) = pool_handle.as_ref() {
+ if is_oracle_external_driver_config(config.as_ref()) {
+ return external_driver_oracle_table_comment(session.clone(), config.as_ref(), database, schema, table)
.await;
- }
- }
- if let Some(client) = extract_pool!(pool_handle.as_ref(), Agent) {
- if db_config.as_ref().is_some_and(|config| {
- matches!(config.db_type, DatabaseType::Oracle | DatabaseType::OceanbaseOracle)
- }) {
- let sql = oracle_table_comment_sql(schema, table);
- let timeout = agent_metadata_timeout(db_config.as_ref());
- let mut client = client.lock().await;
- let result = client
- .execute_query_with_timeout::<db::QueryResult>(
- agent_execute_query_params(
- &sql,
- Some(database),
- Some(schema),
- QueryExecutionOptions { max_rows: Some(1), ..Default::default() },
- ),
- timeout,
- )
- .await?;
- return single_table_comment_from_query_result(result);
- }
- if db_config.as_ref().is_some_and(|config| config.db_type == DatabaseType::SqlServer) {
- // JDBC `REMARKS` is always NULL on SQL Server, so the legacy Agent's
- // table list cannot supply the `MS_Description` written by the editor.
- let sql = db::sqlserver::sqlserver_table_comment_sql(schema, table);
- let timeout = agent_metadata_timeout(db_config.as_ref());
- let mut client = client.lock().await;
- let result = client
- .execute_query_with_timeout::<db::QueryResult>(
- agent_execute_query_params(
- &sql,
- Some(database),
- Some(schema),
- QueryExecutionOptions { max_rows: Some(1), ..Default::default() },
- ),
- timeout,
- )
- .await?;
- return single_table_comment_from_query_result(result);
- }
- if db_config.as_ref().is_some_and(|config| config.db_type == DatabaseType::Kingbase) {
- let timeout = agent_metadata_timeout(db_config.as_ref());
- let mut client = client.lock().await;
- return client.get_table_comment::<Option<String>>(database, schema, table, timeout).await;
- }
- if db_config.as_ref().is_some_and(|config| config.db_type == DatabaseType::Tdengine) {
- let metadata_database = if schema.trim().is_empty() { database } else { schema };
- let sql = tdengine_table_comment_sql(metadata_database, table);
- let timeout = agent_metadata_timeout(db_config.as_ref());
- let mut client = client.lock().await;
- let result = client
- .execute_query_with_timeout::<db::QueryResult>(
- agent_execute_query_params(
- &sql,
- Some(database),
- (!schema.trim().is_empty()).then_some(schema),
- QueryExecutionOptions { max_rows: Some(2), ..Default::default() },
- ),
- timeout,
- )
- .await?;
- return single_table_comment_from_query_result(result);
- }
}
}
-
- let pool = clone_metadata_pool(state, &pool_key).await.ok_or("Pool not found")?;
-
- match &pool {
- PoolKind::Mysql(p, mode)
- if *mode != MysqlMode::OceanBaseOracle
- && !db_config.as_ref().is_some_and(db::mysql_compatible::uses_show_metadata)
- && !db_config.as_ref().is_some_and(db::manticoresearch::is_config) =>
+ if let Some(client) = extract_pool!(pool_handle.as_ref(), Agent) {
+ if db_config
+ .as_ref()
+ .is_some_and(|config| matches!(config.db_type, DatabaseType::Oracle | DatabaseType::OceanbaseOracle))
{
- db::mysql::get_table_comment(p, database, table).await
+ let sql = oracle_table_comment_sql(schema, table);
+ let timeout = agent_metadata_timeout(db_config.as_ref());
+ let mut client = client.lock().await;
+ let result = client
+ .execute_query_with_timeout::<db::QueryResult>(
+ agent_execute_query_params(
+ &sql,
+ Some(database),
+ Some(schema),
+ QueryExecutionOptions { max_rows: Some(1), ..Default::default() },
+ ),
+ timeout,
+ )
+ .await?;
+ return single_table_comment_from_query_result(result);
}
- PoolKind::Postgres(p) if !db_config.as_ref().is_some_and(is_questdb_config) => {
- db::postgres::get_table_comment(p, schema, table).await
+ if db_config.as_ref().is_some_and(|config| config.db_type == DatabaseType::SqlServer) {
+ // JDBC `REMARKS` is always NULL on SQL Server, so the legacy Agent's
+ // table list cannot supply the `MS_Description` written by the editor.
+ let sql = db::sqlserver::sqlserver_table_comment_sql(schema, table);
+ let timeout = agent_metadata_timeout(db_config.as_ref());
+ let mut client = client.lock().await;
+ let result = client
+ .execute_query_with_timeout::<db::QueryResult>(
+ agent_execute_query_params(
+ &sql,
+ Some(database),
+ Some(schema),
+ QueryExecutionOptions { max_rows: Some(1), ..Default::default() },
+ ),
+ timeout,
+ )
+ .await?;
+ return single_table_comment_from_query_result(result);
+ }
+ if db_config.as_ref().is_some_and(|config| config.db_type == DatabaseType::Kingbase) {
+ let timeout = agent_metadata_timeout(db_config.as_ref());
+ let mut client = client.lock().await;
+ return client.get_table_comment::<Option<String>>(database, schema, table, timeout).await;
}
- _ => Err("Table comment lookup is not supported for this connection".to_string()),
+ if db_config.as_ref().is_some_and(|config| config.db_type == DatabaseType::Tdengine) {
+ let metadata_database = if schema.trim().is_empty() { database } else { schema };
+ let sql = tdengine_table_comment_sql(metadata_database, table);
+ let timeout = agent_metadata_timeout(db_config.as_ref());
+ let mut client = client.lock().await;
+ let result = client
+ .execute_query_with_timeout::<db::QueryResult>(
+ agent_execute_query_params(
+ &sql,
+ Some(database),
+ (!schema.trim().is_empty()).then_some(schema),
+ QueryExecutionOptions { max_rows: Some(2), ..Default::default() },
+ ),
+ timeout,
+ )
+ .await?;
+ return single_table_comment_from_query_result(result);
+ }
+ }
+ }
+
+ let pool = clone_metadata_pool(state, pool_key).await.ok_or("Pool not found")?;
+
+ match &pool {
+ PoolKind::Mysql(p, mode)
+ if *mode != MysqlMode::OceanBaseOracle
+ && !db_config.as_ref().is_some_and(db::mysql_compatible::uses_show_metadata)
+ && !db_config.as_ref().is_some_and(db::manticoresearch::is_config) =>
+ {
+ db::mysql::get_table_comment(p, database, table).await
+ }
+ PoolKind::Postgres(p) if !db_config.as_ref().is_some_and(is_questdb_config) => {
+ db::postgres::get_table_comment(p, schema, table).await
}
+ _ => Err("Table comment lookup is not supported for this connection".to_string()),
+ }
+}
+
+async fn get_table_comment_core_for_session(
+ state: &AppState,
+ connection_id: &str,
+ database: &str,
+ schema: &str,
+ table: &str,
+ client_session_id: Option<&str>,
+) -> Result<Option<String>, String> {
+ retry_metadata_connection_for_session(state, connection_id, Some(database), client_session_id, || async {
+ let pool_key =
+ state.get_or_create_metadata_pool_for_session(connection_id, Some(database), client_session_id).await?;
+ get_table_comment_core_with_pool_key(state, connection_id, database, schema, table, &pool_key).await
})
.await
}
@@ -9760,7 +9766,21 @@ async fn get_table_ddl_core_with_options(
// Oracle-family comments live in dictionary tables, not inside CREATE VIEW.
// Append COMMENT ON so table-properties DDL / hover match the structure editor.
if append_oracle_comments {
- return Ok(enrich_ddl_with_oracle_style_comments(state, connection_id, database, schema, table, &ddl).await);
+ let pool_key = state
+ .get_or_create_metadata_pool_for_session(connection_id, Some(database), client_session_id)
+ .await
+ .ok();
+ return Ok(enrich_ddl_with_oracle_style_comments(
+ state,
+ connection_id,
+ database,
+ schema,
+ table,
+ &ddl,
+ client_session_id,
+ pool_key.as_deref(),
+ )
+ .await);
}
return Ok(ddl);
}
@@ -9795,10 +9815,29 @@ async fn get_table_ddl_core_with_options(
}
}
- retry_metadata_connection_for_session(state, connection_id, Some(database), client_session_id, || {
+ let ddl = retry_metadata_connection_for_session(state, connection_id, Some(database), client_session_id, || {
get_table_ddl_once(state, connection_id, database, schema, table, options, client_session_id)
})
- .await
+ .await?;
+
+ let db_config = connection_config(state, connection_id).await;
+ if should_append_oracle_style_comment_ddl(db_config.as_ref()) {
+ let pool_key =
+ state.get_or_create_metadata_pool_for_session(connection_id, Some(database), client_session_id).await.ok();
+ Ok(enrich_ddl_with_oracle_style_comments(
+ state,
+ connection_id,
+ database,
+ schema,
+ table,
+ &ddl,
+ client_session_id,
+ pool_key.as_deref(),
+ )
+ .await)
+ } else {
+ Ok(ddl)
+ }
}
/// Whether the DDL of this object kind is its own definition, rather than the
@@ -11756,33 +11795,84 @@ async fn enrich_ddl_with_oracle_style_comments(
schema: &str,
table: &str,
ddl: &str,
+ client_session_id: Option<&str>,
+ existing_pool_key: Option<&str>,
) -> String {
- let columns = match get_columns_core(state, connection_id, database, schema, table).await {
- Ok(columns) => columns,
- Err(error) => {
- log::debug!(
- "[schema][oracle:display-ddl:columns-for-comments-failed] connection_id={} schema={} table={} error={}",
- connection_id,
- schema,
- table,
- error
- );
- Vec::new()
+ if ddl.trim().is_empty() {
+ return String::new();
+ }
+ let existing_ddl_upper = ddl.to_ascii_uppercase();
+ let needs_column_comments = !existing_ddl_upper.contains("COMMENT ON COLUMN");
+ let needs_table_comment = !existing_ddl_upper.contains("COMMENT ON TABLE");
+ if !needs_column_comments && !needs_table_comment {
+ return crate::object_source_sql::ensure_oracle_ddl_terminated(ddl);
+ }
+
+ let columns = if !needs_column_comments {
+ Vec::new()
+ } else if let Some(pool_key) = existing_pool_key {
+ match get_columns_core_for_existing_pool(state, connection_id, database, schema, table, pool_key).await {
+ Ok(columns) => columns,
+ Err(error) => {
+ log::debug!(
+ "[schema][oracle:display-ddl:columns-for-comments-failed] connection_id={} schema={} table={} error={}",
+ connection_id,
+ schema,
+ table,
+ error
+ );
+ Vec::new()
+ }
+ }
+ } else {
+ match get_columns_core_for_session(state, connection_id, database, schema, table, client_session_id).await {
+ Ok(columns) => columns,
+ Err(error) => {
+ log::debug!(
+ "[schema][oracle:display-ddl:columns-for-comments-failed] connection_id={} schema={} table={} error={}",
+ connection_id,
+ schema,
+ table,
+ error
+ );
+ Vec::new()
+ }
}
};
- let table_comment = match get_table_comment_core(state, connection_id, database, schema, table).await {
- Ok(comment) => comment,
- Err(error) => {
- log::debug!(
- "[schema][oracle:display-ddl:table-comment-failed] connection_id={} schema={} table={} error={}",
- connection_id,
- schema,
- table,
- error
- );
- None
+
+ let table_comment = if !needs_table_comment {
+ None
+ } else if let Some(pool_key) = existing_pool_key {
+ match get_table_comment_core_with_pool_key(state, connection_id, database, schema, table, pool_key).await {
+ Ok(comment) => comment,
+ Err(error) => {
+ log::debug!(
+ "[schema][oracle:display-ddl:table-comment-failed] connection_id={} schema={} table={} error={}",
+ connection_id,
+ schema,
+ table,
+ error
+ );
+ None
+ }
+ }
+ } else {
+ match get_table_comment_core_for_session(state, connection_id, database, schema, table, client_session_id).await
+ {
+ Ok(comment) => comment,
+ Err(error) => {
+ log::debug!(
+ "[schema][oracle:display-ddl:table-comment-failed] connection_id={} schema={} table={} error={}",
+ connection_id,
+ schema,
+ table,
+ error
+ );
+ None
+ }
}
};
+
append_oracle_comments_to_ddl(ddl, schema, table, table_comment.as_deref(), &columns)
}
@@ -12818,6 +12908,32 @@ mod object_source_tests {
assert!(!ddl.contains("New table comment"));
assert!(!ddl.contains("New column comment"));
}
+
+ #[test]
+ fn appends_oracle_comments_to_table_ddl_when_missing() {
+ let column = db::ColumnInfo {
+ name: "USER_NAME".to_string(),
+ data_type: "VARCHAR2(50)".to_string(),
+ is_nullable: true,
+ column_default: None,
+ is_primary_key: false,
+ extra: None,
+ comment: Some("User name comment".to_string()),
+ ..Default::default()
+ };
+
+ let ddl = append_oracle_comments_to_ddl(
+ "CREATE TABLE \"SYSDBA\".\"USERS\" (\n \"USER_NAME\" VARCHAR(50)\n);",
+ "SYSDBA",
+ "USERS",
+ Some("Users table"),
+ &[column],
+ );
+
+ assert!(ddl.contains("CREATE TABLE \"SYSDBA\".\"USERS\""));
+ assert!(ddl.contains("COMMENT ON TABLE \"SYSDBA\".\"USERS\" IS 'Users table';"));
+ assert!(ddl.contains("COMMENT ON COLUMN \"SYSDBA\".\"USERS\".\"USER_NAME\" IS 'User name comment';"));
+ }
}
#[cfg(test)]