Skip to content

KTOR-9594 Update the Integrate a database tutorial#820

Merged
vnikolova merged 4 commits into
mainfrom
vnikolova/KTOR-9594
May 26, 2026
Merged

KTOR-9594 Update the Integrate a database tutorial#820
vnikolova merged 4 commits into
mainfrom
vnikolova/KTOR-9594

Conversation

@vnikolova
Copy link
Copy Markdown
Collaborator

  • Update file names and generated code.
  • Update Exposed version.
  • Use DI for TaskRepository.
  • Update screenshots and GIFs.
  • Update the snippets project.

KTOR-9594 Update the Integrate a database tutorial

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 20, 2026

Review Change Stack

Walkthrough

The 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.

Changes

Database Integration Tutorial Refactor and Upgrade

Layer / File(s) Summary
Gradle infrastructure and dependency versions
codeSnippets/gradle.properties, v.list, snippets/tutorial-server-db-integration/build.gradle.kts, snippets/tutorial-server-db-integration/gradle.properties, snippets/tutorial-server-db-integration/gradle/libs.versions.toml, snippets/tutorial-server-db-integration/gradle/wrapper/gradle-wrapper.properties, snippets/tutorial-server-db-integration/settings.gradle.kts
Updated version pins and version-catalog entries (Exposed → 1.3.0, Logback → 1.5.21), added pluginManagement and Foojay resolver, and migrated build script to use ktorLibs.* catalog aliases.
Gradle wrapper scripts and invocation change
snippets/tutorial-server-db-integration/gradlew, snippets/tutorial-server-db-integration/gradlew.bat
Wrapper scripts now build a CLASSPATH pointing at gradle-wrapper.jar, convert paths for Cygwin/MSYS, and invoke the wrapper via org.gradle.wrapper.GradleWrapperMain with -classpath instead of -jar.
Application architecture refactoring to modular configuration
snippets/tutorial-server-db-integration/src/main/kotlin/main.kt, .../Exposed.kt, .../StatusPages.kt, .../Serialization.kt, .../Routing.kt, .../resources/application.yaml, .../resources/logback.xml
Removed monolithic Application.module() wiring; added main.kt entrypoint and configureDependencies(), refactored configureSerialization, added configureExposed and configureStatusPages, updated application.yaml to list configurators, and set logback root level to INFO.
Test refactoring with centralized application configuration
snippets/tutorial-server-db-integration/src/test/kotlin/ServerTest.kt
Renamed test class to ServerTest, added configureTestApp() helper to provide FakeTaskRepository via DI and invoke serialization/status pages/routing for tests.
Tutorial documentation aligned with new architecture and versions
snippets/tutorial-server-db-integration/README.md, topics/server-integrate-database.topic
Docs updated to reference renamed files and modular configurators, adjust plugin names/count, and update Gradle dependency guidance to use the new catalog aliases.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

dependencies

Suggested reviewers

  • osipxd
  • e5l
  • bjhham
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title directly matches the main objective of updating the Integrate a database tutorial, with a specific issue reference for context.
Description check ✅ Passed The description is related to the changeset, listing key updates including file names, Exposed version, DI usage, and documentation changes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch vnikolova/KTOR-9594

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 win

Use CRLF line endings for the Windows launcher.

This .bat file 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=crlf in .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 win

Use configureExposed() in the README code snippet to match the new tutorial structure.

The step points to Exposed.kt, but the snippet still declares configureDatabases(). 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

📥 Commits

Reviewing files that changed from the base of the PR and between 33b3ac5 and 22cdb7f.

⛔ Files ignored due to path filters (6)
  • images/ktor_project_generator_add_plugins.gif is excluded by !**/*.gif
  • images/ktor_project_generator_add_plugins_dark.gif is excluded by !**/*.gif
  • images/tutorial_server_db_integration_plugin_list.png is excluded by !**/*.png
  • images/tutorial_server_db_integration_plugin_list_dark.png is excluded by !**/*.png
  • images/tutorial_server_db_integration_src_folder.png is excluded by !**/*.png
  • images/tutorial_server_db_integration_src_folder_dark.png is excluded by !**/*.png
📒 Files selected for processing (20)
  • codeSnippets/gradle.properties
  • codeSnippets/snippets/tutorial-server-db-integration/README.md
  • codeSnippets/snippets/tutorial-server-db-integration/build.gradle.kts
  • codeSnippets/snippets/tutorial-server-db-integration/gradle.properties
  • codeSnippets/snippets/tutorial-server-db-integration/gradle/libs.versions.toml
  • codeSnippets/snippets/tutorial-server-db-integration/gradle/wrapper/gradle-wrapper.properties
  • codeSnippets/snippets/tutorial-server-db-integration/gradlew
  • codeSnippets/snippets/tutorial-server-db-integration/gradlew.bat
  • codeSnippets/snippets/tutorial-server-db-integration/settings.gradle.kts
  • codeSnippets/snippets/tutorial-server-db-integration/src/main/kotlin/Application.kt
  • codeSnippets/snippets/tutorial-server-db-integration/src/main/kotlin/Exposed.kt
  • codeSnippets/snippets/tutorial-server-db-integration/src/main/kotlin/Routing.kt
  • codeSnippets/snippets/tutorial-server-db-integration/src/main/kotlin/Serialization.kt
  • codeSnippets/snippets/tutorial-server-db-integration/src/main/kotlin/StatusPages.kt
  • codeSnippets/snippets/tutorial-server-db-integration/src/main/kotlin/main.kt
  • codeSnippets/snippets/tutorial-server-db-integration/src/main/resources/application.yaml
  • codeSnippets/snippets/tutorial-server-db-integration/src/main/resources/logback.xml
  • codeSnippets/snippets/tutorial-server-db-integration/src/test/kotlin/ServerTest.kt
  • topics/server-integrate-database.topic
  • v.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

Comment thread topics/server-integrate-database.topic Outdated
@vnikolova vnikolova requested a review from a team May 20, 2026 10:12
@vnikolova vnikolova requested a review from bjhham May 22, 2026 09:43
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
codeSnippets/snippets/tutorial-server-db-integration/settings.gradle.kts (1)

1-10: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Place pluginManagement {} before plugins {} in settings.gradle.kts.

pluginManagement is currently not the first block. In Gradle settings scripts, this can break settings evaluation. Please move pluginManagement {} to the top, then keep plugins {} 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

📥 Commits

Reviewing files that changed from the base of the PR and between 67db152 and 09b7128.

📒 Files selected for processing (2)
  • codeSnippets/snippets/tutorial-server-db-integration/gradle/wrapper/gradle-wrapper.properties
  • codeSnippets/snippets/tutorial-server-db-integration/settings.gradle.kts

@vnikolova vnikolova merged commit 166ceec into main May 26, 2026
1 check passed
@vnikolova vnikolova deleted the vnikolova/KTOR-9594 branch May 26, 2026 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants