Skip to content

Commit ec3bf1d

Browse files
committed
feat(database): add check for empty table names #80
Add a check to ensure that the list of table names is not empty before generating the SQL script. If the list is empty, set the progress indicator fraction to 1.0 and log a warning message. Also, add a new function `getAllTables()` to retrieve all table names from `actions.dasTables`.
1 parent d15ce43 commit ec3bf1d

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

exts/database/src/main/kotlin/cc/unitmesh/database/actions/GenSqlScriptBySelection.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ class GenSqlScriptBySelection : AbstractChatIntention() {
8787
override fun run(indicator: ProgressIndicator) {
8888
indicator.fraction = 0.2
8989

90-
9190
indicator.text = AutoDevBundle.message("migration.database.sql.generate.clarify")
9291
val tables = flow.clarify()
9392

@@ -96,6 +95,13 @@ class GenSqlScriptBySelection : AbstractChatIntention() {
9695
val tableNames = tables.substringAfter("[").substringBefore("]")
9796
.split(", ").map { it.trim() }
9897

98+
if (tableNames.isEmpty()) {
99+
indicator.fraction = 1.0
100+
val allTables = flow.getAllTables()
101+
logger.warn("no table related: $allTables")
102+
return
103+
}
104+
99105
indicator.fraction = 0.6
100106
indicator.text = AutoDevBundle.message("migration.database.sql.generate.generate")
101107
val sqlScript = flow.generate(tableNames)
@@ -187,6 +193,10 @@ class GenSqlFlow(
187193
logger.info("Prompt: $prompter")
188194
return prompter
189195
}
196+
197+
fun getAllTables(): List<String> {
198+
return actions.dasTables.map { it.name }
199+
}
190200
}
191201

192202

0 commit comments

Comments
 (0)