Tính năng chuyển đổi dữ liệu H2 <-> MariaDB/MySQL - #80
Conversation
📝 WalkthroughWalkthroughAdds a new ChangesDatabase Conversion Feature
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
PR bổ sung tính năng chuyển đổi dữ liệu giữa H2 và MariaDB/MySQL trong plugin DotMan, cho phép admin chạy chuyển đổi trực tiếp trong game và theo dõi tiến độ bằng bossbar.
Changes:
- Thêm enum
DbConvertEngineđể chuẩn hoá engine, quoting identifier và validate điều kiện chuyển đổi. - Thêm
DbConversionServicethực hiện pipeline migrate schema, đối chiếu bảng/cột, copy dữ liệu theo batch, và reseed identity cho H2. - Thêm subcommand
/dotman admin dbconvert(có confirm qua chat + tab-complete) để kích hoạt chuyển đổi.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| dotman-plugin/src/main/java/net/minevn/dotman/database/convert/DbConvertEngine.kt | Khai báo engine (H2/MySQL/MariaDB), quoting và validate rule chuyển đổi. |
| dotman-plugin/src/main/java/net/minevn/dotman/database/convert/DbConversionService.kt | Implement toàn bộ logic migrate + copy dữ liệu + hiển thị tiến độ. |
| dotman-plugin/src/main/java/net/minevn/dotman/commands/AdminCmd.kt | Thêm command dbconvert, tab completion và luồng xác nhận qua chat. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| tabComplete { | ||
| val current = DbConvertEngine.from(DotMan.instance.config.config.getString("database.engine")) | ||
| when (args.size) { | ||
| 1 -> availableSources(current).filter { it.startsWith(args.last().lowercase()) } | ||
| 2 -> availableTargets(args.firstOrNull(), current).filter { it.startsWith(args.last().lowercase()) } | ||
| else -> emptyList() | ||
| } | ||
| } |
| player.send(""" | ||
| §eBạn sắp chuyển đổi database từ §b§n${source.typeName}§f -> §a§n${target.typeName} | ||
| §r | ||
| §c§lLƯU Ý: | ||
| §e- Hãy nhớ backup dữ liệu trước khi tiếp tục. | ||
| §e- Dữ liệu ở database đích §b(${target.typeName})§e sẽ bị ghi đè (nếu có). | ||
| §e- Chỉ thực hiện khi server không có người chơi. | ||
| §e- Quá trình chuyển đổi có thể mất vài phút, hãy kiên nhẫn chờ đợi và đừng tắt server trong quá trình này. | ||
| §e- Sau khi chuyển đổi xong, hãy nhớ cập nhật lại cấu hình database trong file config.yml và restart server để áp dụng. | ||
| §r | ||
| §eNhập §a§lXACNHAN §eđể bắt đầu, hoặc nhập §c§lHUY §eđể hủy bỏ. | ||
| """.trimIndent()) |
| target.createStatement().use { statement -> | ||
| statement.executeUpdate("DELETE FROM $targetTableName") | ||
| } |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
dotman-plugin/src/main/java/net/minevn/dotman/database/convert/DbConversionService.kt (1)
482-494: Acknowledged TODO: Boss bar removed before completion state is visible.The
complete()method immediately callsremoveAll(), which removes the boss bar before the player can see the 100% completion state. To improve UX, the boss bar should remain visible briefly before removal.Would you like me to generate a workaround using Bukkit's scheduler to delay the
removeAll()call untilrunLateris available in minevn-lib? A simple approach usingBukkit.getScheduler().runTaskLater()with a 40-60 tick delay would provide the same effect.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@dotman-plugin/src/main/java/net/minevn/dotman/database/convert/DbConversionService.kt` around lines 482 - 494, The complete() method removes the boss bar immediately after setting it to 100% progress and green color, preventing the player from seeing the completion state. Wrap the bossBar?.removeAll() call with a delayed execution using Bukkit.getScheduler().runTaskLater() to delay the removal by 40-60 ticks (2-3 seconds), allowing the completion state to remain visible to the player before the boss bar is removed.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@dotman-plugin/src/main/java/net/minevn/dotman/commands/AdminCmd.kt`:
- Around line 414-415: The tab completion filter in the adminCmd has a case
mismatch where availableSources() and availableTargets() return uppercase values
but are filtered against args.last().lowercase(). To fix this, apply
.lowercase() to the items returned from availableSources(current) and
availableTargets(args.firstOrNull(), current) before filtering them with
startsWith(args.last().lowercase()), so that "h2".startsWith("h") will correctly
match the available source values.
---
Nitpick comments:
In
`@dotman-plugin/src/main/java/net/minevn/dotman/database/convert/DbConversionService.kt`:
- Around line 482-494: The complete() method removes the boss bar immediately
after setting it to 100% progress and green color, preventing the player from
seeing the completion state. Wrap the bossBar?.removeAll() call with a delayed
execution using Bukkit.getScheduler().runTaskLater() to delay the removal by
40-60 ticks (2-3 seconds), allowing the completion state to remain visible to
the player before the boss bar is removed.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 3a6e2f08-44f7-4cb4-811f-7541dd8d63cb
📒 Files selected for processing (3)
dotman-plugin/src/main/java/net/minevn/dotman/commands/AdminCmd.ktdotman-plugin/src/main/java/net/minevn/dotman/database/convert/DbConversionService.ktdotman-plugin/src/main/java/net/minevn/dotman/database/convert/DbConvertEngine.kt
| 1 -> availableSources(current).filter { it.startsWith(args.last().lowercase()) } | ||
| 2 -> availableTargets(args.firstOrNull(), current).filter { it.startsWith(args.last().lowercase()) } |
There was a problem hiding this comment.
Tab completion filter has case mismatch.
availableSources() and availableTargets() return uppercase values (e.g., "H2", "MYSQL"), but the filter compares against args.last().lowercase(). This causes "H2".startsWith("h") to return false, so typing h won't suggest H2.
🔧 Proposed fix
tabComplete {
val current = DbConvertEngine.from(DotMan.instance.config.config.getString("database.engine"))
when (args.size) {
- 1 -> availableSources(current).filter { it.startsWith(args.last().lowercase()) }
- 2 -> availableTargets(args.firstOrNull(), current).filter { it.startsWith(args.last().lowercase()) }
+ 1 -> availableSources(current).filter { it.lowercase().startsWith(args.last().lowercase()) }
+ 2 -> availableTargets(args.firstOrNull(), current).filter { it.lowercase().startsWith(args.last().lowercase()) }
else -> emptyList()
}
}🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@dotman-plugin/src/main/java/net/minevn/dotman/commands/AdminCmd.kt` around
lines 414 - 415, The tab completion filter in the adminCmd has a case mismatch
where availableSources() and availableTargets() return uppercase values but are
filtered against args.last().lowercase(). To fix this, apply .lowercase() to the
items returned from availableSources(current) and
availableTargets(args.firstOrNull(), current) before filtering them with
startsWith(args.last().lowercase()), so that "h2".startsWith("h") will correctly
match the available source values.
Summary by CodeRabbit