KTOR-9594 Update the Integrate a database tutorial#820
Conversation
WalkthroughThe PR refactors the database tutorial into modular suspend configurators wired via DI, centralizes tests, updates docs, and modernizes Gradle infra/version catalog while bumping Exposed to 1.3.0. ChangesDatabase Integration Tutorial Refactor and Upgrade
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
codeSnippets/snippets/tutorial-server-db-integration/gradlew.bat (1)
1-95:⚠️ Potential issue | 🟠 Major | ⚡ Quick winUse CRLF line endings for the Windows launcher.
This
.batfile appears to be committed with LF-only endings. On Windows, that can cause intermittent label/GOTO parsing failures. Please re-save it as CRLF (and ideally enforce*.bat text eol=crlfin.gitattributes).🤖 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 `@codeSnippets/snippets/tutorial-server-db-integration/gradlew.bat` around lines 1 - 95, The gradlew.bat file was committed with LF-only endings which can break Windows label/GOTO parsing (labels such as :execute, :fail, :mainEnd, :omega); re-save the file with CRLF line endings and commit that fix, and add a .gitattributes entry (e.g., "*.bat text eol=crlf") to enforce CRLF for .bat files going forward.codeSnippets/snippets/tutorial-server-db-integration/README.md (1)
18-27:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winUse
configureExposed()in the README code snippet to match the new tutorial structure.The step points to
Exposed.kt, but the snippet still declaresconfigureDatabases(). This creates a naming mismatch for readers following the guide.Suggested doc fix
-fun Application.configureDatabases() { +suspend fun Application.configureExposed() { Database.connect( "jdbc:postgresql://localhost:5432/ktor_tutorial_db", user = "postgresql", password = "password" ) }🤖 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 `@codeSnippets/snippets/tutorial-server-db-integration/README.md` around lines 18 - 27, The README snippet uses the old function name configureDatabases() which no longer matches the tutorial structure; update the snippet in Exposed.kt to call and show configureExposed() instead, keeping the Database.connect(...) example intact so readers see the correct function name (replace occurrences of configureDatabases() with configureExposed() and ensure the surrounding text references Exposed.kt and configureExposed() consistently).
🤖 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 `@codeSnippets/snippets/tutorial-server-db-integration/settings.gradle.kts`:
- Around line 3-8: The settings file defines rootProject.name before
pluginManagement which violates Gradle ordering; move the pluginManagement { ...
} block to the very top of settings.gradle.kts, immediately follow it with the
plugins { ... } block (currently at lines 19-21), and then place
rootProject.name and the rest of the settings after those two blocks so
pluginManagement and plugins appear in the required order.
In
`@codeSnippets/snippets/tutorial-server-db-integration/src/main/kotlin/StatusPages.kt`:
- Around line 10-12: The handler registered with exception<Throwable> currently
returns the raw exception via call.respondText("500: $cause") which leaks
internals; change it to respond with a generic 500 message (e.g., "Internal
server error") using call.respondText(..., HttpStatusCode.InternalServerError)
and move the detailed error to server logs instead (log the Throwable using the
application logger or a logger instance). Update the exception<Throwable> {
call, cause -> ... } block to call the logger (e.g.,
call.application.environment.log.error(...) or your logger.error(...)) with the
cause and then send the generic response via call.respondText.
In `@topics/server-integrate-database.topic`:
- Line 690: The documentation references the wrong version-catalog filename;
replace occurrences of "gradle/libs.versions.kts" with
"gradle/libs.versions.toml" so the catalog uses the proper TOML extension
(including the instruction where it tells the reader to add "exposed-jdbc" and
any other entries); update any related examples or links that point to
libs.versions.kts to libs.versions.toml to keep names consistent.
---
Outside diff comments:
In `@codeSnippets/snippets/tutorial-server-db-integration/gradlew.bat`:
- Around line 1-95: The gradlew.bat file was committed with LF-only endings
which can break Windows label/GOTO parsing (labels such as :execute, :fail,
:mainEnd, :omega); re-save the file with CRLF line endings and commit that fix,
and add a .gitattributes entry (e.g., "*.bat text eol=crlf") to enforce CRLF for
.bat files going forward.
In `@codeSnippets/snippets/tutorial-server-db-integration/README.md`:
- Around line 18-27: The README snippet uses the old function name
configureDatabases() which no longer matches the tutorial structure; update the
snippet in Exposed.kt to call and show configureExposed() instead, keeping the
Database.connect(...) example intact so readers see the correct function name
(replace occurrences of configureDatabases() with configureExposed() and ensure
the surrounding text references Exposed.kt and configureExposed() consistently).
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 7523fbfa-a284-43b4-8976-31a275ef7bcf
⛔ Files ignored due to path filters (6)
images/ktor_project_generator_add_plugins.gifis excluded by!**/*.gifimages/ktor_project_generator_add_plugins_dark.gifis excluded by!**/*.gifimages/tutorial_server_db_integration_plugin_list.pngis excluded by!**/*.pngimages/tutorial_server_db_integration_plugin_list_dark.pngis excluded by!**/*.pngimages/tutorial_server_db_integration_src_folder.pngis excluded by!**/*.pngimages/tutorial_server_db_integration_src_folder_dark.pngis excluded by!**/*.png
📒 Files selected for processing (20)
codeSnippets/gradle.propertiescodeSnippets/snippets/tutorial-server-db-integration/README.mdcodeSnippets/snippets/tutorial-server-db-integration/build.gradle.ktscodeSnippets/snippets/tutorial-server-db-integration/gradle.propertiescodeSnippets/snippets/tutorial-server-db-integration/gradle/libs.versions.tomlcodeSnippets/snippets/tutorial-server-db-integration/gradle/wrapper/gradle-wrapper.propertiescodeSnippets/snippets/tutorial-server-db-integration/gradlewcodeSnippets/snippets/tutorial-server-db-integration/gradlew.batcodeSnippets/snippets/tutorial-server-db-integration/settings.gradle.ktscodeSnippets/snippets/tutorial-server-db-integration/src/main/kotlin/Application.ktcodeSnippets/snippets/tutorial-server-db-integration/src/main/kotlin/Exposed.ktcodeSnippets/snippets/tutorial-server-db-integration/src/main/kotlin/Routing.ktcodeSnippets/snippets/tutorial-server-db-integration/src/main/kotlin/Serialization.ktcodeSnippets/snippets/tutorial-server-db-integration/src/main/kotlin/StatusPages.ktcodeSnippets/snippets/tutorial-server-db-integration/src/main/kotlin/main.ktcodeSnippets/snippets/tutorial-server-db-integration/src/main/resources/application.yamlcodeSnippets/snippets/tutorial-server-db-integration/src/main/resources/logback.xmlcodeSnippets/snippets/tutorial-server-db-integration/src/test/kotlin/ServerTest.kttopics/server-integrate-database.topicv.list
💤 Files with no reviewable changes (2)
- codeSnippets/snippets/tutorial-server-db-integration/src/main/kotlin/Routing.kt
- codeSnippets/snippets/tutorial-server-db-integration/src/main/kotlin/Application.kt
There was a problem hiding this comment.
♻️ Duplicate comments (1)
codeSnippets/snippets/tutorial-server-db-integration/settings.gradle.kts (1)
1-10:⚠️ Potential issue | 🔴 Critical | ⚡ Quick winPlace
pluginManagement {}beforeplugins {}insettings.gradle.kts.
pluginManagementis currently not the first block. In Gradle settings scripts, this can break settings evaluation. Please movepluginManagement {}to the top, then keepplugins {}immediately after it.For Gradle 9.4, what is the required ordering of `pluginManagement {}` and `plugins {}` blocks in `settings.gradle.kts`? Is `plugins {}` allowed before `pluginManagement {}`?🤖 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 `@codeSnippets/snippets/tutorial-server-db-integration/settings.gradle.kts` around lines 1 - 10, The settings file has the plugins { } block before pluginManagement { }, which breaks Gradle 9.4 evaluation; move the pluginManagement { } block to the top and place plugins { } immediately after it so pluginManagement appears before plugins (ensure you edit the existing pluginManagement and plugins blocks in settings.gradle.kts).
🤖 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.
Duplicate comments:
In `@codeSnippets/snippets/tutorial-server-db-integration/settings.gradle.kts`:
- Around line 1-10: The settings file has the plugins { } block before
pluginManagement { }, which breaks Gradle 9.4 evaluation; move the
pluginManagement { } block to the top and place plugins { } immediately after it
so pluginManagement appears before plugins (ensure you edit the existing
pluginManagement and plugins blocks in settings.gradle.kts).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: ae4d3324-6037-4d9a-a53e-20cb5b06c1ab
📒 Files selected for processing (2)
codeSnippets/snippets/tutorial-server-db-integration/gradle/wrapper/gradle-wrapper.propertiescodeSnippets/snippets/tutorial-server-db-integration/settings.gradle.kts
TaskRepository.KTOR-9594 Update the Integrate a database tutorial