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(sqlserver): include IDENTITY in table DDL

zipg9319efb9e5a7
diff --git a/crates/dbx-core/src/schema.rs b/crates/dbx-core/src/schema.rs
index 856643fee9..a67287847d 100644
--- a/crates/dbx-core/src/schema.rs
+++ b/crates/dbx-core/src/schema.rs
@@ -5409,6 +5409,18 @@ mod ddl_tests {
));
}
+ #[test]
+ fn sqlserver_table_ddl_includes_identity_clause() {
+ let mut id = column("FIDS", "int");
+ id.is_nullable = false;
+ id.is_primary_key = true;
+ id.extra = Some("identity(1,1)".to_string());
+
+ let ddl = render_sqlserver_table_ddl("dbo", "ZHLSBS", &[id], &[], &[]);
+
+ assert!(ddl.contains("[FIDS] int IDENTITY(1,1) NOT NULL"), "ddl: {ddl}");
+ }
+
#[test]
fn opengauss_table_ddl_uses_native_tabledef_function() {
assert_eq!(
@@ -5598,6 +5610,23 @@ pub fn render_postgres_table_ddl(
ddl
}
+fn sqlserver_identity_clause(extra: Option<&str>) -> Option<String> {
+ let extra = extra?.trim();
+ let lower = extra.to_ascii_lowercase();
+ if !lower.starts_with("identity") {
+ return None;
+ }
+
+ let rest = extra["identity".len()..].trim_start();
+ if rest.is_empty() {
+ return Some("IDENTITY".to_string());
+ }
+
+ let args = rest.strip_prefix('(')?;
+ let end = args.find(')')?;
+ Some(format!("IDENTITY({})", args[..end].trim()))
+}
+
fn group_foreign_keys_by_name(fkeys: &[db::ForeignKeyInfo]) -> Vec<Vec<&db::ForeignKeyInfo>> {
let mut groups: Vec<Vec<&db::ForeignKeyInfo>> = Vec::new();
for fk in fkeys {
@@ -5635,6 +5664,9 @@ pub fn render_sqlserver_table_ddl(
.iter()
.map(|c| {
let mut line = format!(" {} {}", sqlserver_ident(&c.name), c.data_type);
+ if let Some(identity) = sqlserver_identity_clause(c.extra.as_deref()) {
+ line.push_str(&format!(" {identity}"));
+ }
if !c.is_nullable {
line.push_str(" NOT NULL");
}